Esempio n. 1
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);
        }