Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public void TestSingleValue0Steps()
        {
            var classifier = new SDRClassifier(new[] { 0 }, 1.0);
            // Enough times to perform Inference and learn associations
            Classification <double> retVal = null;

            for (int i = 0; i < 10; i++)
            {
                retVal = _compute(classifier, i, new[] { 1, 5 }, 0, 10);
            }
            Assert.AreEqual(retVal.GetActualValue(0), 10);
            Assert.IsTrue(retVal.GetStat(0, 0) > 0.9, "value of 1 must be greater then 0.9 and is " + retVal.GetStat(0, 0));
        }
Exemple #5
0
        public void TestCompute1()
        {
            _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);
            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(34.7, result.GetActualValue(0), 0.01);
        }
Exemple #6
0
        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));
        }
Exemple #7
0
        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));
        }
Exemple #8
0
        public void TestSingleValue0Steps()
        {
            _classifier = new CLAClassifier(new[] { 0 }, 0.001, 0.3, 0);

            // Enough times to perform Inference and learn associations
            Classification <double> retVal = null;

            for (int recordNum = 0; recordNum < 10; recordNum++)
            {
                retVal = Compute <double>(_classifier, recordNum, new[] { 1, 5 }, 0, 10);
            }

            Assert.AreEqual(10.0, retVal.GetActualValue(0), .00001);
            Assert.AreEqual(1.0, retVal.GetStat(0, 0), .00001);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
 public void CheckValue <T>(Classification <T> retVal, int index, object value, double probability)
 {
     Assert.AreEqual(retVal.GetActualValue(index), value);
     Assert.AreEqual(probability, retVal.GetStat(1, index), 0.01);
 }