Ejemplo n.º 1
0
        public TransformerPipeline Add(ICaseTransformer transformer)
        {
            if (transformer == null)
            {
                throw new ArgumentNullException(nameof(transformer));
            }
            transformers.Add(transformer);

            return(this);
        }
Ejemplo n.º 2
0
        private static FoldValidationResult <TSolution> ProcessFold <TSolution>(string[][] folds, int testFoldIndex, ICaseFrame cases, ICaseTransformer pipeline, Reasoner reasoner)
        {
            var watch  = Stopwatch.StartNew();
            var result = new FoldValidationResult <TSolution>(testFoldIndex, folds[testFoldIndex].Length);

            var testFold  = cases.FilterCases(folds[testFoldIndex]);
            var trainFold = cases.FilterCases(folds.Where((f, i) => i != testFoldIndex).SelectMany(f => f));

            pipeline.Prepare(trainFold);
            testFold  = pipeline.Transform(testFold);
            trainFold = pipeline.Transform(trainFold);

            reasoner.SetData(trainFold);

            using (var cursor = testFold.GetCaseCursor())
            {
                while (cursor.MoveNext())
                {
                    var trueSolution      = cursor.GetSolution <TSolution>();
                    var predictedSolution = reasoner.GetSolution <TSolution>(cursor);
                    result.AddPrediction(trueSolution, predictedSolution);
                }
            }
            watch.Stop();
            result.ValidationTime = watch.ElapsedMilliseconds;

            return(result);
        }
Ejemplo n.º 3
0
 public TransformerPipeline(ICaseTransformer transformer) : this()
 {
     Add(transformer);
 }
Ejemplo n.º 4
0
        public static CrossValidationResult <TSolution> Validate <TSolution>(string[][] folds, ICaseFrame cases, Reasoner reasoner, ICaseTransformer pipeline = null)
        {
            if (folds == null)
            {
                throw new ArgumentNullException(nameof(folds));
            }
            if (cases == null)
            {
                throw new ArgumentNullException(nameof(cases));
            }
            if (reasoner == null)
            {
                throw new ArgumentNullException(nameof(reasoner));
            }

            var results = new FoldValidationResult <TSolution> [folds.Length];

            for (var i = 0; i < folds.Length; i++)
            {
                results[i] = ProcessFold <TSolution>(folds, i, cases, pipeline, reasoner);
            }

            return(new CrossValidationResult <TSolution>(results));
        }