Beispiel #1
0
 static void CleanTrained(PredictorEntity e)
 {
     PredictorPredictLogic.TrainedPredictorCache.Remove(e.ToLite());
     e.TrainingException = null;
     foreach (var fp in e.Files)
     {
         fp.DeleteFileOnCommit();
     }
     e.ClassificationTraining   = null;
     e.ClassificationValidation = null;
     e.RegressionTraining       = null;
     e.RegressionValidation     = null;
     e.Files.Clear();
     e.Codifications().UnsafeDelete();
     e.EpochProgresses().UnsafeDelete();
 }
Beispiel #2
0
    public static List <PredictorCodification> RetrievePredictorCodifications(this PredictorEntity predictor)
    {
        var list = predictor.Codifications().ToList();


        object?ParseValue(string str, QueryToken token)
        {
            return(FilterValueConverter.Parse(str, token.Type, isList: false));
        }

        object?ParseKey(string?str, PredictorSubQueryColumnEmbedded key)
        {
            return(FilterValueConverter.Parse(str, key.Token.Token.Type, isList: false));
        }

        object?[] GetKeys(PredictorCodificationEntity cod, List <PredictorSubQueryColumnEmbedded> keys)
        {
            switch (keys.Count)
            {
            case 0: return(new object[0]);

            case 1:
                return(new[] {
                    ParseKey(cod.SplitKey0, keys[0]),
                });

            case 2:
                return(new[] {
                    ParseKey(cod.SplitKey0, keys[0]),
                    ParseKey(cod.SplitKey1, keys[1]),
                });

            case 3:
                return(new[] {
                    ParseKey(cod.SplitKey0, keys[0]),
                    ParseKey(cod.SplitKey1, keys[1]),
                    ParseKey(cod.SplitKey2, keys[2]),
                });

            default:
                throw new InvalidOperationException("Unexpected Group count");
            }
        }

        Dictionary <int, PredictorColumnMain> mainColumns = new Dictionary <int, PredictorColumnMain>();

        PredictorColumnMain GetPredictorColumnMain(PredictorCodificationEntity cod)
        {
            return(mainColumns.GetOrCreate(cod.OriginalColumnIndex, () => new PredictorColumnMain(
                                               predictorColumnIndex: cod.OriginalColumnIndex,
                                               predictorColumn: predictor.MainQuery.Columns[cod.OriginalColumnIndex]
                                               )));
        }

        Dictionary <int, Dictionary <int, PredictorColumnSubQuery> > subColumns = new Dictionary <int, Dictionary <int, PredictorColumnSubQuery> >();

        PredictorColumnSubQuery GetPredictorColumnSubQuery(PredictorCodificationEntity cod)
        {
            return(subColumns.GetOrCreate(cod.SubQueryIndex !.Value).GetOrCreate(cod.OriginalColumnIndex, () => {
                var sq = predictor.SubQueries[cod.SubQueryIndex.Value];
                var col = sq.Columns[cod.OriginalColumnIndex];
                if (col.Usage == PredictorSubQueryColumnUsage.SplitBy || col.Usage == PredictorSubQueryColumnUsage.ParentKey)
                {
                    throw new InvalidOperationException("Unexpected codification usage");
                }

                var keys = GetKeys(cod, sq.Columns.Where(a => a.Usage == PredictorSubQueryColumnUsage.SplitBy).ToList());

                return new PredictorColumnSubQuery(col, cod.OriginalColumnIndex, sq, keys);
            }));
        }

        return((from cod in list
                let col = cod.SubQueryIndex == null ?
                          (PredictorColumnBase)GetPredictorColumnMain(cod) :
                          (PredictorColumnBase)GetPredictorColumnSubQuery(cod)
                          select new PredictorCodification(col)
        {
            Index = cod.Index,
            IsValue = cod.IsValue != null ? ParseValue(cod.IsValue, col.Token) : null,
            Average = cod.Average,
            StdDev = cod.StdDev,
            Min = cod.Min,
            Max = cod.Max,
        })
               .ToList());
    }