public void TestSerializeCLAClassifier() { CLAClassifier classifier = new CLAClassifier(new int[] { 1 }, 0.1, 0.1, 0); int recordNum = 0; Map <String, Object> classification = new Map <string, object>(); classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); Classification <double> result = classifier.Compute <double>(recordNum, classification, new int[] { 1, 5, 9 }, true, true); recordNum += 1; classification.Add("bucketIdx", 5); classification.Add("actValue", 41.7); result = classifier.Compute <double>(recordNum, classification, new int[] { 0, 6, 9, 11 }, true, true); recordNum += 1; classification.Add("bucketIdx", 5); classification.Add("actValue", 44.9); result = classifier.Compute <double>(recordNum, classification, new int[] { 6, 9 }, true, true); recordNum += 1; classification.Add("bucketIdx", 4); classification.Add("actValue", 42.9); result = classifier.Compute <double>(recordNum, classification, new int[] { 1, 5, 9 }, true, true); recordNum += 1; // Serialize the Metrics too just to be sure everything can be serialized SerialConfig config = new SerialConfig("testSerializeCLAClassifier", SerialConfig.SERIAL_TEST_DIR); IPersistenceAPI api = Persistence.Get(config); api.Write(classifier); // Deserialize the Metrics CLAClassifier serializedClassifier = api.Read <CLAClassifier>(); Assert.IsNotNull(serializedClassifier); //Using the deserialized classifier, continue test classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); result = serializedClassifier.Compute <double>(recordNum, classification, new int[] { 1, 5, 9 }, true, true); recordNum += 1; Assert.IsTrue(Arrays.AreEqual(new int[] { 1 }, result.StepSet())); Assert.AreEqual(35.520000457763672, result.GetActualValue(4), 0.00001); Assert.AreEqual(42.020000457763672, result.GetActualValue(5), 0.00001); Assert.AreEqual(6, result.GetStatCount(1)); Assert.AreEqual(0.0, result.GetStat(1, 0), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 1), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 2), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 3), 0.00001); Assert.AreEqual(0.12300123, result.GetStat(1, 4), 0.00001); Assert.AreEqual(0.87699877, result.GetStat(1, 5), 0.00001); }
public void TestSerialization() { _classifier = new CLAClassifier(new[] { 1 }, 0.1, 0.1, 0); int recordNum = 0; Map <string, object> classification = new Map <string, object>(); classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); Classification <double> result = _classifier.Compute <double>(recordNum, classification, new[] { 1, 5, 9 }, true, true); recordNum += 1; classification.Add("bucketIdx", 5); classification.Add("actValue", 41.7); result = _classifier.Compute <double>(recordNum, classification, new[] { 0, 6, 9, 11 }, true, true); recordNum += 1; classification.Add("bucketIdx", 5); classification.Add("actValue", 44.9); result = _classifier.Compute <double>(recordNum, classification, new[] { 6, 9 }, true, true); recordNum += 1; classification.Add("bucketIdx", 4); classification.Add("actValue", 42.9); result = _classifier.Compute <double>(recordNum, classification, new[] { 1, 5, 9 }, true, true); recordNum += 1; // Configure serializer SerialConfig config = new SerialConfig("testSerializerClassifier", SerialConfig.SERIAL_TEST_DIR); IPersistenceAPI api = Persistence.Get(config); // 1. Serialize byte[] data = api.Write(_classifier, "testSerializeClassifier"); // 2. Deserialize CLAClassifier serialized = api.Read <CLAClassifier>(data); // Using the deserialized classifier, continue test classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); result = serialized.Compute <double>(recordNum, classification, new[] { 1, 5, 9 }, true, true); recordNum += 1; Assert.IsTrue(Arrays.AreEqual(new[] { 1 }, result.StepSet())); Assert.AreEqual(35.520000457763672, result.GetActualValue(4), 0.00001); Assert.AreEqual(42.020000457763672, result.GetActualValue(5), 0.00001); Assert.AreEqual(6, result.GetStatCount(1)); Assert.AreEqual(0.0, result.GetStat(1, 0), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 1), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 2), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 3), 0.00001); Assert.AreEqual(0.12300123, result.GetStat(1, 4), 0.00001); Assert.AreEqual(0.87699877, result.GetStat(1, 5), 0.00001); }
public void TestComputeCategory() { _classifier = new CLAClassifier(new[] { 1 }, 0.1, 0.1, 0); Dictionary <string, object> classification = new Dictionary <string, object>(); classification.Add("bucketIdx", 4); classification.Add("actValue", "D"); _classifier.Compute <string>(0, classification, new[] { 1, 5, 9 }, true, true); Classification <string> result = _classifier.Compute <string>(0, classification, new[] { 1, 5, 9 }, true, true); Assert.IsTrue(Arrays.AreEqual(new[] { 1 }, result.StepSet())); Assert.AreEqual("D", result.GetActualValue(4)); }
public void TestCompute2() { _classifier = new CLAClassifier(new[] { 1 }, 0.1, 0.1, 0); Dictionary <string, object> classification = new Dictionary <string, object>(); classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); _classifier.Compute <double>(0, classification, new[] { 1, 5, 9 }, true, true); Classification <double> result = _classifier.Compute <double>(1, classification, new[] { 1, 5, 9 }, true, true); Assert.IsTrue(Arrays.AreEqual(new[] { 1 }, result.StepSet())); Assert.AreEqual(5, result.GetActualValueCount()); Assert.AreEqual(34.7, result.GetActualValue(4), 0.01); }
public void testComputeComplex() { var classifier = new CLAClassifier <double>(new List <int> { 1 }, 0.1, 0.1); int recordNum = 0; Dictionary <string, object> classification = new Dictionary <string, object>(); classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); ClassificationExperiment <double> result = classifier.Compute(recordNum, classification, new int[] { 1, 5, 9 }, true, true); recordNum += 1; classification["bucketIdx"] = 5; classification["actValue"] = 41.7; result = classifier.Compute(recordNum, classification, new int[] { 0, 6, 9, 11 }, true, true); recordNum += 1; classification["bucketIdx"] = 5; classification["actValue"] = 44.9; result = classifier.Compute(recordNum, classification, new int[] { 6, 9 }, true, true); recordNum += 1; classification["bucketIdx"] = 4; classification["actValue"] = 42.9; result = classifier.Compute(recordNum, classification, new int[] { 1, 5, 9 }, true, true); recordNum += 1; classification["bucketIdx"] = 4; classification["actValue"] = 34.7; result = classifier.Compute(recordNum, classification, new int[] { 1, 5, 9 }, true, true); Assert.AreEqual(35.520000457763672, result.getActualValue(4), 0.00001); Assert.AreEqual(42.020000457763672, result.getActualValue(5), 0.00001); Assert.AreEqual(6, result.getStatCount(1)); Assert.AreEqual(0.0, result.getStat(1, 0), 0.00001); Assert.AreEqual(0.0, result.getStat(1, 1), 0.00001); Assert.AreEqual(0.0, result.getStat(1, 2), 0.00001); Assert.AreEqual(0.0, result.getStat(1, 3), 0.00001); Assert.AreEqual(0.12300123, result.getStat(1, 4), 0.00001); Assert.AreEqual(0.87699877, result.getStat(1, 5), 0.00001); }
public void TestComputeWithTwoIteration() { var classifier = new CLAClassifier <double>(new List <int> { 1 }, 0.1, 0.1); Dictionary <string, object> classification = new Dictionary <string, object>(); classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); classifier.Compute(0, classification, new int[] { 1, 5, 9 }, true, true); //It is second iteration and so it will learn and that's why value count will be more than one ClassificationExperiment <double> result = classifier.Compute(1, classification, new int[] { 1, 5, 9 }, true, true); Assert.AreEqual(5, result.getActualValueCount()); Assert.AreEqual(34.7, result.getActualValue(4), 0.01); }
/// <summary> /// general method for calling computing method of claclassifier class /// </summary> /// <typeparam name="T"></typeparam> /// <param name="classifier">instance of claclassifier class</param> /// <param name="recordNum">iteration number</param> /// <param name="pattern">list of the active indices</param> /// <param name="bucket">bucket index</param> /// <param name="value">value of predicted field</param> /// <returns>classification object</returns> public ClassificationExperiment <T> compute <T>(CLAClassifier <T> classifier, int recordNum, int[] pattern, int bucket, Object value) where T : struct { Dictionary <string, object> classification = new Dictionary <string, object>(); classification.Add("bucketIdx", bucket); classification.Add("actValue", value); return(classifier.Compute(recordNum, classification, pattern, true, true)); }
public void TestMissingRecordInitialization() { _classifier = new CLAClassifier(new[] { 2 }, 0.1, 0.1, 0); int recordNum = 0; Dictionary <string, object> classification = new Dictionary <string, object>(); classification.Add("bucketIdx", 0); classification.Add("actValue", 34.7); _classifier.Compute <double>(recordNum, classification, new[] { 1, 5, 9 }, true, true); recordNum = 2; Classification <double> result = _classifier.Compute <double>(recordNum, classification, new[] { 1, 5, 9 }, true, true); Assert.IsTrue(Arrays.AreEqual(new[] { 2 }, result.StepSet())); Assert.AreEqual(1, result.GetActualValueCount()); Assert.AreEqual(34.7, result.GetActualValue(0), 0.01); }
public Classification <T> Compute <T>(CLAClassifier classifier, int recordNum, int[] pattern, int bucket, object value) { Dictionary <string, object> classification = new Dictionary <string, object>(); classification.Add("bucketIdx", bucket); classification.Add("actValue", value); return(classifier.Compute <T>(recordNum, classification, pattern, true, true)); }
public void TestComputeComplex() { _classifier = new CLAClassifier(new[] { 1 }, 0.1, 0.1, 0); int recordNum = 0; Map <string, object> classification = new Map <string, object>(); classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); Classification <double> result = _classifier.Compute <double>(recordNum, classification, new[] { 1, 5, 9 }, true, true); recordNum += 1; classification.Add("bucketIdx", 5); classification.Add("actValue", 41.7); result = _classifier.Compute <double>(recordNum, classification, new[] { 0, 6, 9, 11 }, true, true); recordNum += 1; classification.Add("bucketIdx", 5); classification.Add("actValue", 44.9); result = _classifier.Compute <double>(recordNum, classification, new[] { 6, 9 }, true, true); recordNum += 1; classification.Add("bucketIdx", 4); classification.Add("actValue", 42.9); result = _classifier.Compute <double>(recordNum, classification, new[] { 1, 5, 9 }, true, true); recordNum += 1; classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); result = _classifier.Compute <double>(recordNum, classification, new[] { 1, 5, 9 }, true, true); recordNum += 1; Assert.IsTrue(Arrays.AreEqual(new[] { 1 }, result.StepSet())); Assert.AreEqual(35.520000457763672, result.GetActualValue(4), 0.00001); Assert.AreEqual(42.020000457763672, result.GetActualValue(5), 0.00001); Assert.AreEqual(6, result.GetStatCount(1)); Assert.AreEqual(0.0, result.GetStat(1, 0), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 1), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 2), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 3), 0.00001); Assert.AreEqual(0.12300123, result.GetStat(1, 4), 0.00001); Assert.AreEqual(0.87699877, result.GetStat(1, 5), 0.00001); }
public void TestComputeWithMissingValue() { _classifier = new CLAClassifier(new[] { 1 }, 0.1, 0.1, 0); Map <string, object> classification = new Map <string, object>(); classification.Add("bucketIdx", null); classification.Add("actValue", null); Classification <double?> result = _classifier.Compute <double?>(0, classification, new[] { 1, 5, 9 }, true, true); Assert.IsTrue(Arrays.AreEqual(new[] { 1 }, result.StepSet())); Assert.AreEqual(1, result.GetActualValueCount()); Assert.AreEqual(null, result.GetActualValue(0)); }
public void TestComputeWithMissingValue() { var classifier = new CLAClassifier <double>(new List <int> { 1 }, 0.1, 0.1); Dictionary <string, object> classification = new Dictionary <string, object>(); classification.Add("bucketIdx", null); classification.Add("actValue", null); ClassificationExperiment <double> result = classifier.Compute(0, classification, new int[] { 1, 5, 9 }, true, true); Assert.AreEqual(1, result.getActualValueCount()); Assert.AreEqual(-1, result.getActualValue(0)); }
public void TestCompute() { var classifier = new CLAClassifier <double>(new List <int> { 1 }, 0.1, 0.1); Dictionary <string, object> classification = new Dictionary <string, object>(); classification.Add("bucketIdx", 4); classification.Add("actValue", 34.7); ClassificationExperiment <double> result = classifier.Compute(0, classification, new int[] { 1, 5, 9 }, true, true); //it is first time and so it wont learn and that's why value count will be one Assert.AreEqual(1, result.getActualValueCount()); Assert.AreEqual(34.7, result.getActualValue(0), 0.01); }
public void TestMissingRecords() { _classifier = new CLAClassifier(new[] { 1 }, 0.1, 0.1, 0); int recordNum = 0; Map <string, object> classification = new Map <string, object>(); classification.Add("bucketIdx", 0); classification.Add("actValue", 0); _classifier.Compute <double>(recordNum, classification, new[] { 1, 3, 5 }, true, true); recordNum += 1; classification.Add("bucketIdx", 1); classification.Add("actValue", 1); _classifier.Compute <double>(recordNum, classification, new[] { 2, 4, 6 }, true, true); recordNum += 1; classification.Add("bucketIdx", 2); classification.Add("actValue", 2); _classifier.Compute <double>(recordNum, classification, new[] { 1, 3, 5 }, true, true); recordNum += 1; classification.Add("bucketIdx", 1); classification.Add("actValue", 1); _classifier.Compute <double>(recordNum, classification, new[] { 2, 4, 6 }, true, true); recordNum += 1; // ---------------------------------------------------------------------------------- // At this point, we should have learned [1, 3, 5] => bucket 1 // [2, 4, 6] => bucket 2 classification.Add("bucketIdx", 2); classification.Add("actValue", 2); Classification <double> result = _classifier.Compute <double>(recordNum, classification, new[] { 1, 3, 5 }, true, true); recordNum += 1; Assert.AreEqual(0.0, result.GetStat(1, 0), 0.00001); Assert.AreEqual(1.0, result.GetStat(1, 1), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 2), 0.00001); classification.Add("bucketIdx", 1); classification.Add("actValue", 1); result = _classifier.Compute <double>(recordNum, classification, new[] { 2, 4, 6 }, true, true); recordNum += 1; Assert.AreEqual(0.0, result.GetStat(1, 0), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 1), 0.00001); Assert.AreEqual(1.0, result.GetStat(1, 2), 0.00001); // ---------------------------------------------------------------------------------- // Feed in records that skip and make sure they don't mess up what we learned // // If we skip a record, the CLA should NOT learn that [2,4,6] from // the previous learning associates with bucket 0 recordNum += 1; // <----- Does the skip classification.Add("bucketIdx", 0); classification.Add("actValue", 0); result = _classifier.Compute <double>(recordNum, classification, new[] { 1, 3, 5 }, true, true); recordNum += 1; Assert.AreEqual(0.0, result.GetStat(1, 0), 0.00001); Assert.AreEqual(1.0, result.GetStat(1, 1), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 2), 0.00001); // If we skip a record, the CLA should NOT learn that [1,3,5] from // the previous learning associates with bucket 0 recordNum += 1; // <----- Does the skip classification.Add("bucketIdx", 0); classification.Add("actValue", 0); result = _classifier.Compute <double>(recordNum, classification, new[] { 2, 4, 6 }, true, true); recordNum += 1; Assert.AreEqual(0.0, result.GetStat(1, 0), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 1), 0.00001); Assert.AreEqual(1.0, result.GetStat(1, 2), 0.00001); // If we skip a record, the CLA should NOT learn that [2,4,6] from // the previous learning associates with bucket 0 recordNum += 1; // <----- Does the skip classification.Add("bucketIdx", 0); classification.Add("actValue", 0); result = _classifier.Compute <double>(recordNum, classification, new[] { 1, 3, 5 }, true, true); recordNum += 1; Assert.AreEqual(0.0, result.GetStat(1, 0), 0.00001); Assert.AreEqual(1.0, result.GetStat(1, 1), 0.00001); Assert.AreEqual(0.0, result.GetStat(1, 2), 0.00001); }