CreateModel3() public static method

public static CreateModel3 ( double &sequences2, int &labels2 ) : HiddenMarkovClassifier
sequences2 double
labels2 int
return HiddenMarkovClassifier
Example #1
0
        public void LogBackwardTest2()
        {
            double[][][] observations;
            int[]        labels;

            var hmm = IndependentMarkovFunctionTest.CreateModel3(out observations, out labels);

            MarkovMultivariateFunction function = new MarkovMultivariateFunction(hmm);


            foreach (double[][] x in observations)
            {
                foreach (int y in labels)
                {
                    double[,] actual = new double[x.Length, 5];
                    Accord.Statistics.Models.Fields.
                    ForwardBackwardAlgorithm.LogBackward(function.Factors[y], x, y, actual);

                    double[,] expected = new double[x.Length, 5];
                    Accord.Statistics.Models.Markov.
                    ForwardBackwardAlgorithm.LogBackward(hmm.Models[y], x, expected);

                    for (int i = 0; i < actual.GetLength(0); i++)
                    {
                        for (int j = 0; j < actual.GetLength(1); j++)
                        {
                            Assert.AreEqual(expected[i, j], actual[i, j], 1e-10);
                            Assert.IsFalse(Double.IsNaN(actual[i, j]));
                        }
                    }
                }
            }
        }
Example #2
0
        public void ForwardTest2()
        {
            double[][][] observations;
            int[]        labels;

            var hmm = IndependentMarkovFunctionTest.CreateModel3(out observations, out labels);

            var function = new MarkovMultivariateFunction(hmm, includePriors: false);


            foreach (double[][] x in observations)
            {
                foreach (int y in labels)
                {
                    double[] scaling1;
                    double   logLikelihood1;

                    double[,] actual = Accord.Statistics.Models.Fields.
                                       ForwardBackwardAlgorithm.Forward(function.Factors[y], x, y, out scaling1, out logLikelihood1);

                    double[] scaling2;
                    double   logLikelihood2;
                    double[,] expected = Accord.Statistics.Models.Markov.
                                         ForwardBackwardAlgorithm.Forward(hmm.Models[y], x, out scaling2, out logLikelihood2);

                    for (int i = 0; i < actual.GetLength(0); i++)
                    {
                        for (int j = 0; j < actual.GetLength(1); j++)
                        {
                            Assert.AreEqual(expected[i, j], actual[i, j], 1e-10);
                            Assert.IsFalse(Double.IsNaN(actual[i, j]));
                        }
                    }

                    Assert.AreEqual(logLikelihood1, logLikelihood2, 1e-10);

                    for (int i = 0; i < scaling1.Length; i++)
                    {
                        Assert.IsTrue(scaling1[i].IsRelativelyEqual(scaling2[i], 1e-10));
                        Assert.IsFalse(Double.IsNaN(scaling1[i]));
                        Assert.IsFalse(Double.IsNaN(scaling2[i]));
                    }
                }
            }
        }