Accord.Tests.Statistics.GenericMaximumLikelihoodLearningTest.RunTest C# (CSharp) Method

RunTest() private method

private RunTest ( ) : void
return void
        public void RunTest()
        {
            // Example from
            // http://www.cs.columbia.edu/4761/notes07/chapter4.3-HMM.pdf



            double[][] observations = 
            {
                new double[] { 0,0,0,1,0,0 }, 
                new double[] { 1,0,0,1,0,0 },
                new double[] { 0,0,1,0,0,0 },
                new double[] { 0,0,0,0,1,0 },
                new double[] { 1,0,0,0,1,0 },
                new double[] { 0,0,0,1,1,0 },
                new double[] { 1,0,0,0,0,0 },
                new double[] { 1,0,1,0,0,0 },
            };

            int[][] paths =
            {
                new int[] { 0,0,1,0,1,0 },
                new int[] { 1,0,1,0,1,0 },
                new int[] { 1,0,0,1,1,0 },
                new int[] { 1,0,1,1,1,0 },
                new int[] { 1,0,0,1,0,1 },
                new int[] { 0,0,1,0,0,1 },
                new int[] { 0,0,1,1,0,1 },
                new int[] { 0,1,1,1,0,0 },
            };


            GeneralDiscreteDistribution initial = new GeneralDiscreteDistribution(symbols: 2);

            var model = new HiddenMarkovModel<GeneralDiscreteDistribution>(states: 2, emissions: initial);

            var target = new MaximumLikelihoodLearning<GeneralDiscreteDistribution>(model);
            target.UseLaplaceRule = false;

            double logLikelihood = target.Run(observations, paths);

            var pi = Matrix.Exp(model.Probabilities);
            var A = Matrix.Exp(model.Transitions);
            var B = model.Emissions;

            Assert.AreEqual(0.5, pi[0]);
            Assert.AreEqual(0.5, pi[1]);

            Assert.AreEqual(7 / 20.0, A[0, 0], 1e-5);
            Assert.AreEqual(13 / 20.0, A[0, 1], 1e-5);
            Assert.AreEqual(14 / 20.0, A[1, 0], 1e-5);
            Assert.AreEqual(6 / 20.0, A[1, 1], 1e-5);

            Assert.AreEqual(17 / 25.0, B[0].ProbabilityMassFunction(0));
            Assert.AreEqual(8 / 25.0, B[0].ProbabilityMassFunction(1));
            Assert.AreEqual(19 / 23.0, B[1].ProbabilityMassFunction(0));
            Assert.AreEqual(4 / 23.0, B[1].ProbabilityMassFunction(1));

            Assert.AreEqual(-1.1472359046136624, logLikelihood);
        }
    }
GenericMaximumLikelihoodLearningTest