Accord.Tests.Statistics.Models.Fields.DiscreteHiddenMarkovModelFunctionTest.CreateModel2 C# (CSharp) Method

CreateModel2() public static method

public static CreateModel2 ( ) : HiddenMarkovModel
return Accord.Statistics.Models.Markov.HiddenMarkovModel
        public static HiddenMarkovModel CreateModel2()
        {
            int states = 3;
            int symbols = 3;

            int[][] sequences = new int[][] 
            {
                new int[] { 0, 1, 1, 1, 2 },
                new int[] { 0, 1, 1, 1, 2, 2, 2 },
                new int[] { 0, 0, 1, 1, 2, 2 },
                new int[] { 0, 1, 1, 1, 2, 2, 2 },
                new int[] { 0, 1, 1, 1, 2, 1 },
                new int[] { 0, 1, 1, 2, 2 },
                new int[] { 0, 0, 1, 1, 1, 2, 1 },
                new int[] { 0, 0, 0, 1, 1, 1, 2, 1 },
                new int[] { 0, 1, 1, 2, 2, 2 },
            };

            HiddenMarkovModel hmm = new HiddenMarkovModel(new Forward(states), symbols);

            var teacher = new BaumWelchLearning(hmm) { Iterations = 100, Tolerance = 0 };

            double ll = teacher.Run(sequences);

            return hmm;
        }

Usage Example

Beispiel #1
0
        public void ComputeTest()
        {
            HiddenMarkovModel hmm = DiscreteHiddenMarkovModelFunctionTest.CreateModel2();

            int states = hmm.States;


            var    function = new MarkovDiscreteFunction(hmm);
            var    target = new ConditionalRandomField <int>(states, function);
            double p1, p2;

            int[] observations, expected, actual;

            observations = new int[] { 0, 0, 1, 1, 1, 2 };
            expected     = hmm.Decode(observations, out p1);
            actual       = target.Compute(observations, out p2);

            Assert.IsTrue(expected.IsEqual(actual));
            Assert.AreEqual(p1, p2, 1e-6);


            observations = new int[] { 0, 1, 2, 2, 2 };
            expected     = hmm.Decode(observations, out p1);
            actual       = target.Compute(observations, out p2);

            Assert.IsTrue(expected.IsEqual(actual));
            Assert.AreEqual(p1, p2, 1e-6);
        }
All Usage Examples Of Accord.Tests.Statistics.Models.Fields.DiscreteHiddenMarkovModelFunctionTest::CreateModel2