示例#1
0
        public void TestProbability1()
        {
            MealyIohmm <int, int> mi = CreateMealy1();

            Assert.AreEqual(M1Pr0, mi.Probability(new Tuple <int, int> (0x01, 0x00)), TestConstants.Tolerance);
            Assert.AreEqual(M1Pr1, mi.Probability(new Tuple <int, int> (0x01, 0x01)), TestConstants.Tolerance);
            Assert.AreEqual(M1Pr00, mi.Probability(new Tuple <int, int> (0x01, 0x00), new Tuple <int, int> (0x01, 0x00)), TestConstants.Tolerance);
            Assert.AreEqual(M1Pr00, mi.Probability(new Tuple <int, int> (0x01, 0x00), new Tuple <int, int> (0x01, 0x00)), TestConstants.Tolerance);
            Assert.AreEqual(M1Pr01, mi.Probability(new Tuple <int, int> (0x01, 0x00), new Tuple <int, int> (0x01, 0x01)), TestConstants.Tolerance);
            Assert.AreEqual(M1Pr10, mi.Probability(new Tuple <int, int> (0x01, 0x01), new Tuple <int, int> (0x01, 0x00)), TestConstants.Tolerance);
            Assert.AreEqual(M1Pr11, mi.Probability(new Tuple <int, int> (0x01, 0x01), new Tuple <int, int> (0x01, 0x01)), TestConstants.Tolerance);
        }
示例#2
0
        public void TestConstructor()
        {
            MealyIohmm <int, int> mi = CreateMealy1();

            Assert.AreEqual(M1P0, mi.GetPi(0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1P1, mi.GetPi(0x01), TestConstants.Tolerance);
            Assert.AreEqual(M1A00, mi.GetA(0x01, 0x00, 0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1A01, mi.GetA(0x01, 0x00, 0x01), TestConstants.Tolerance);
            Assert.AreEqual(M1A10, mi.GetA(0x01, 0x01, 0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1A11, mi.GetA(0x01, 0x01, 0x01), TestConstants.Tolerance);
            Assert.AreEqual(M1B00, mi.GetB(0x01, 0x00, 0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1B01, mi.GetB(0x01, 0x00, 0x01), TestConstants.Tolerance);
            Assert.AreEqual(M1B10, mi.GetB(0x01, 0x01, 0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1B11, mi.GetB(0x01, 0x01, 0x01), TestConstants.Tolerance);
        }
示例#3
0
        public void TestCalculateBetasReverse1()
        {
            MealyIohmm <int, int> mi = CreateMealy1();

            double[][] beta;
            beta = mi.CalculateBetasReverse(new Tuple <int, int> (0x01, 0x00)).Reverse().ToArray();
            Assert.AreEqual(M1O0B00, beta [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O0B01, beta [0x00] [0x01], TestConstants.Tolerance);
            beta = mi.CalculateBetasReverse(new Tuple <int, int> (0x01, 0x01)).Reverse().ToArray();
            Assert.AreEqual(M1O1B00, beta [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O1B01, beta [0x00] [0x01], TestConstants.Tolerance);
            beta = mi.CalculateBetasReverse(new Tuple <int, int> (0x01, 0x00), new Tuple <int, int> (0x01, 0x00)).Reverse().ToArray();
            Assert.AreEqual(M1O00B00, beta [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O00B01, beta [0x00] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1O00B10, beta [0x01] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O00B11, beta [0x01] [0x01], TestConstants.Tolerance);
            beta = mi.CalculateBetasReverse(new Tuple <int, int> (0x01, 0x01), new Tuple <int, int> (0x01, 0x00)).Reverse().ToArray();
            Assert.AreEqual(M1O01B00, beta [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O01B01, beta [0x00] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1O01B10, beta [0x01] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O01B11, beta [0x01] [0x01], TestConstants.Tolerance);
        }
示例#4
0
        public void TestCalculateAlphas1()
        {
            MealyIohmm <int, int> mi = CreateMealy1();

            double[][] alpha;
            alpha = mi.CalculateAlphas(new Tuple <int, int> (0x01, 0x00)).ToArray();
            Assert.AreEqual(M1O0A00, alpha [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O0A01, alpha [0x00] [0x01], TestConstants.Tolerance);
            alpha = mi.CalculateAlphas(new Tuple <int, int> (0x01, 0x01)).ToArray();
            Assert.AreEqual(M1O1A00, alpha [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O1A01, alpha [0x00] [0x01], TestConstants.Tolerance);
            alpha = mi.CalculateAlphas(new Tuple <int, int> (0x01, 0x00), new Tuple <int, int> (0x01, 0x00)).ToArray();
            Assert.AreEqual(M1O00A00, alpha [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O00A01, alpha [0x00] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1O00A10, alpha [0x01] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O00A11, alpha [0x01] [0x01], TestConstants.Tolerance);
            alpha = mi.CalculateAlphas(new Tuple <int, int> (0x01, 0x00), new Tuple <int, int> (0x01, 0x01)).ToArray();
            Assert.AreEqual(M1O01A00, alpha [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O01A01, alpha [0x00] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1O01A10, alpha [0x01] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1O01A11, alpha [0x01] [0x01], TestConstants.Tolerance);
        }
示例#5
0
        public void TestTrain1()
        {
            MealyIohmm <int, int> mi = CreateMealy1();

            Tuple <int, int>[] observations = new Tuple <int, int>[] {
                new Tuple <int, int> (0x01, 0x00),
                new Tuple <int, int> (0x01, 0x01),
                new Tuple <int, int> (0x01, 0x00),
                new Tuple <int, int> (0x01, 0x01),
            };
            double[][] alpha = mi.CalculateAlphas(observations).ToArray();
            Assert.AreEqual(M1TA00, alpha [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1TA01, alpha [0x00] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1TA10, alpha [0x01] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1TA11, alpha [0x01] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1TA20, alpha [0x02] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1TA21, alpha [0x02] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1TA30, alpha [0x03] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1TA31, alpha [0x03] [0x01], TestConstants.Tolerance);
            double[][] beta = mi.CalculateBetas(observations).ToArray();
            Assert.AreEqual(M1TB00, beta [0x00] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1TB01, beta [0x00] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1TB10, beta [0x01] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1TB11, beta [0x01] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1TB20, beta [0x02] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1TB21, beta [0x02] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(M1TB30, beta [0x03] [0x00], TestConstants.Tolerance);
            Assert.AreEqual(M1TB31, beta [0x03] [0x01], TestConstants.Tolerance);
            Assert.AreEqual(1.0d, M1T_NP0 + M1T_NP1, TestConstants.Tolerance);
            Assert.AreEqual(1.0d, M1T_NA00 + M1T_NA01, TestConstants.Tolerance);
            Assert.AreEqual(1.0d, M1T_NA10 + M1T_NA11, TestConstants.Tolerance);
            Assert.AreEqual(1.0d, M1T_NB00 + M1T_NB01, TestConstants.Tolerance);
            Assert.AreEqual(1.0d, M1T_NB10 + M1T_NB11, TestConstants.Tolerance);
            Tuple <Tuple <int, int>, double>[] newtran;
            newtran = mi.CalculateNewTransition(observations, 0x00).ToArray();
            Assert.AreEqual(M1TE000, newtran [0x00].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE001, newtran [0x01].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE100, newtran [0x02].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE101, newtran [0x03].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE200, newtran [0x04].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE201, newtran [0x05].Item2, TestConstants.Tolerance);
            newtran = mi.CalculateNewTransition(observations, 0x01).ToArray();
            Assert.AreEqual(M1TE010, newtran [0x00].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE011, newtran [0x01].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE110, newtran [0x02].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE111, newtran [0x03].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE210, newtran [0x04].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TE211, newtran [0x05].Item2, TestConstants.Tolerance);
            Tuple <Tuple <int, int>, double>[] newemis;
            newemis = mi.CalculateNewEmission(observations, 0x00).ToArray();
            Assert.AreEqual(M1TC00, newemis [0x00].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TC10, newemis [0x01].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TC20, newemis [0x02].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TC30, newemis [0x03].Item2, TestConstants.Tolerance);
            newemis = mi.CalculateNewEmission(observations, 0x01).ToArray();
            Assert.AreEqual(M1TC01, newemis [0x00].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TC11, newemis [0x01].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TC21, newemis [0x02].Item2, TestConstants.Tolerance);
            Assert.AreEqual(M1TC31, newemis [0x03].Item2, TestConstants.Tolerance);
            mi.Train(observations);
            Assert.AreEqual(M1T_NP1, mi.GetPi(0x01), TestConstants.Tolerance);
            Assert.AreEqual(M1T_NP0, mi.GetPi(0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1T_NA00, mi.GetA(0x01, 0x00, 0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1T_NA01, mi.GetA(0x01, 0x00, 0x01), TestConstants.Tolerance);
            Assert.AreEqual(M1T_NA10, mi.GetA(0x01, 0x01, 0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1T_NA11, mi.GetA(0x01, 0x01, 0x01), TestConstants.Tolerance);
            Assert.AreEqual(M1T_NB00, mi.GetB(0x01, 0x00, 0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1T_NB01, mi.GetB(0x01, 0x00, 0x01), TestConstants.Tolerance);
            Assert.AreEqual(M1T_NB10, mi.GetB(0x01, 0x01, 0x00), TestConstants.Tolerance);
            Assert.AreEqual(M1T_NB11, mi.GetB(0x01, 0x01, 0x01), TestConstants.Tolerance);
            for (int i = 0x00; i < 0x10; i++)
            {
                mi.Train(observations);
            }
            Console.WriteLine(mi);
        }