public void RBMDataSample1Test() { var dataPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"RestrictedBolzmannMachine2\Data\rbm_sample1.csv"); LearningApi api = new LearningApi(this.getDescriptorForRbm_sample1()); // Initialize data provider api.UseCsvDataProvider(dataPath, ',', false, 1); api.UseDefaultDataMapper(); api.UseRbm(0.2, 1000, 6, 3); RbmResult score = api.Run() as RbmResult; double[][] testData = new double[4][]; testData[0] = new double[] { 1, 1, 0, 0, 0, 0 }; testData[1] = new double[] { 0, 0, 0, 0, 1, 1 }; testData[2] = new double[] { 0, 1, 0, 0, 0, 0 }; testData[3] = new double[] { 0, 0, 0, 0, 1, 1 }; var result = api.Algorithm.Predict(testData, api.Context); // NOT FINISHED. //Assert.True(result[0] == 1); //Assert.True(result[1] == 0); //Assert.True(result[2] == 0); //Assert.True(result[3] == 0); //Assert.True(result[4] == 1); //Assert.True(result[5] == 0); }
public void CRbm_ClassifierTest() { var dataPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"RestrictedBolzmannMachine2\Data\rbm_twoclass_sample.csv"); LearningApi api = new LearningApi(this.getDescriptorForRbmTwoClassesClassifier()); // Initialize data provider api.UseCsvDataProvider(dataPath, ';', false, 1); api.UseDefaultDataMapper(); double[] featureVector = new double[] { 0.1, 0.2, 0.3 }; api.UseCRbm(featureVector, 0.01, 1000, 10, 2); RbmResult score = api.Run() as RbmResult; double[][] testData = new double[5][]; // // This test data contains two patterns. One is grouped at left and one at almost right. testData[0] = new double[] { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; testData[1] = new double[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 }; testData[2] = new double[] { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 }; testData[3] = new double[] { 0, 0, 0, 0, 0, 1, 0, 1, 0, 0 }; // This will be classified as third class. testData[4] = new double[] { 1, 1, 1, 0, 0, 1, 1, 1, 0, 0 }; var result = api.Algorithm.Predict(testData, api.Context) as RbmResult; // // 2 * BIT1 + BIT2 of [0] and [1] should be same. // We don't know how RBM will classiffy data. We only expect that // same or similar pattern of data will be assigned to the same class. // Note, we have here two classes (two hiddne nodes). // First and second data sample are of same class. Third and fourth are also of same class. // Here we check first classs. Assert.True(2 * result.HiddenNodesPredictions[0][0] + result.HiddenNodesPredictions[0][1] == 2 * result.HiddenNodesPredictions[1][0] + result.HiddenNodesPredictions[1][1]); // Here is test for second class. Assert.True(2 * result.HiddenNodesPredictions[2][0] + result.HiddenNodesPredictions[2][1] == 2 * result.HiddenNodesPredictions[3][0] + result.HiddenNodesPredictions[3][1]); printVector("Weights", result.Weights); }
public void Rbm_ClassifierTest2() { var dataPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"RestrictedBolzmannMachine2\Data\rbm_sample2.csv"); LearningApi api = new LearningApi(this.getDescriptorForRbmTwoClassesClassifier(21)); // Initialize data provider api.UseCsvDataProvider(dataPath, ',', false, 1); api.UseDefaultDataMapper(); api.UseDeepRbm(0.2, 10000, new int[] { 21, 9, 6, 2 }); RbmResult score = api.Run() as RbmResult; var expectedResults = new Dictionary <int, List <double[]> >(); // All test data, which belong to the sam class. List <double[]> testListClass1 = new List <double[]>(); List <double[]> testListClass2 = new List <double[]>(); // // This test data contains two patterns. One is grouped at left and one at almost right. // testListClass1 contains class 1 // testListClass2 contains class 2 testListClass1.Add(new double[] { 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); testListClass1.Add(new double[] { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); testListClass1.Add(new double[] { 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }); testListClass2.Add(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 }); testListClass2.Add(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0 }); testListClass2.Add(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }); expectedResults.Add(1, testListClass1); expectedResults.Add(2, testListClass2); validateClassificationResult(api, expectedResults); }
public void Rbm_ClassifierTest() { var dataPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), @"RestrictedBolzmannMachine2\Data\rbm_twoclass_sample.csv"); LearningApi api = new LearningApi(this.getDescriptorForRbmTwoClassesClassifier(10)); // Initialize data provider api.UseCsvDataProvider(dataPath, ';', false, 1); api.UseDefaultDataMapper(); api.UseDeepRbm(0.2, 1000, new int[] { 10, 2 }); RbmResult score = api.Run() as RbmResult; double[][] trainData = new double[6][]; // All test data, which belong to the sam class. List <double[]> testListClass1 = new List <double[]>(); List <double[]> testListClass2 = new List <double[]>(); // // This test data contains two patterns. One is grouped at left and one at almost right. trainData[0] = new double[] { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; testListClass1.Add(trainData[0]); trainData[1] = new double[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 }; testListClass1.Add(trainData[1]); trainData[2] = new double[] { 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 }; testListClass1.Add(trainData[2]); trainData[3] = new double[] { 0, 0, 0, 0, 0, 1, 1, 1, 0, 0 }; testListClass2.Add(trainData[3]); trainData[4] = new double[] { 0, 0, 0, 0, 0, 1, 0, 1, 0, 0 }; testListClass2.Add(trainData[4]); trainData[5] = new double[] { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 }; testListClass2.Add(trainData[5]); // This will be classified as third class. //testData[4] = new double[] { 1, 1, 1, 0, 0, 1, 1, 1, 0, 0 }; RbmDeepResult result = api.Algorithm.Predict(trainData, api.Context) as RbmDeepResult; var expectedResults = new Dictionary <int, List <double[]> >(); expectedResults.Add(1, testListClass1); expectedResults.Add(2, testListClass2); validateClassificationResult(api, expectedResults); // // 2 * BIT1 + BIT2 of [0] and [1] should be same. // We don't know how RBM will classiffy data. We only expect that // same or similar pattern of data will be assigned to the same class. // Note, we have here two classes (two hiddne nodes). // First and second data sample are of the same class. // Third and fourth are also of same class. See data. //// Here we check first classs. //Assert.True(result.Results[0].ToArray()[0].HiddenNodesPredictions[0] == result.Results[1].ToArray()[0].HiddenNodesPredictions[0] && // result.Results[0].ToArray()[0].HiddenNodesPredictions[1] == result.Results[1].ToArray()[0].HiddenNodesPredictions[1]); //// Here is test for second class. //Assert.True(result.Results[2].ToArray()[0].HiddenNodesPredictions[0] == result.Results[3].ToArray()[0].HiddenNodesPredictions[0] && // result.Results[2].ToArray()[0].HiddenNodesPredictions[1] == result.Results[3].ToArray()[0].HiddenNodesPredictions[1]); }