public void TrainModelAndTestModelTest(string trainFile, string testFile)
        {
            var trainModel = new TrainModel(2, 0.1);
            var trainDataset = new ClassifiedDataset(trainFile, 64, 2);
            trainModel.Train(trainDataset.GetClassifiedVectors());

            var testModel = new TestModel(2, 0.1);
            var testDataset = new UnclassifiedDataset(testFile, 64);
            var testData = testDataset.GetDataVectors().Select(v => v.FeatureVector).ToArray();
            var results = testModel.Test(trainModel.GetInferredPosterier(), testData);

            Assert.That(results.Length, Is.EqualTo(testData.Length));
        }
Exemplo n.º 2
0
 public Machine(int numOfClasses, int numOfFeatures, int[] featureSelection, double noise)
     : base(numOfClasses, numOfFeatures, featureSelection, noise)
 {
     this.trainModel = new TrainModel(numOfClasses, noise);
     this.testModel = new TestModel(numOfClasses, noise);
 }
        public void TrainModelIncrementalTrainTest(string trainFile1, string trainFile2)
        {
            var model = new TrainModel(2, 0.1);

            var dataset1 = new ClassifiedDataset(trainFile1, 64, 2);
            model.TrainIncremental(dataset1.GetClassifiedVectors());
            var posteriors1 = model.GetInferredPosterier();

            var dataset2 = new ClassifiedDataset(trainFile2, 64, 2);
            model.TrainIncremental(dataset2.GetClassifiedVectors());
            var posteriors2 = model.GetInferredPosterier();

            Assert.AreEqual(posteriors1.Length, posteriors2.Length);

            Assert.That(posteriors1.Intersect(posteriors2).Count() < posteriors1.Length);
        }
        public void TrainModelWithFeatureSelectionTest(string trainFile, int[] featureSelection)
        {
            var model = new TrainModel(2, 0.1);
            var dataset = new ClassifiedDataset(trainFile, 64, featureSelection, 2);

            model.Train(dataset.GetClassifiedVectors());

            var posteriors = model.GetInferredPosterier();

            Assert.That(posteriors.Length, Is.EqualTo(2));

            foreach (var p in posteriors)
            {
                Assert.That(p.Dimension, Is.EqualTo(featureSelection.Length));
            }
        }