public void LogBackwardTest2()
        {
            HiddenMarkovClassifier <Independent> hmm = IndependentMarkovClassifierPotentialFunctionTest
                                                       .CreateModel3();

            MarkovMultivariateFunction function = new MarkovMultivariateFunction(hmm);

            double[][][] observations = IndependentMarkovClassifierPotentialFunctionTest.sequences2;
            int[]        labels       = IndependentMarkovClassifierPotentialFunctionTest.labels2;

            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]));
                        }
                    }
                }
            }
        }
        public void ForwardTest2()
        {
            HiddenMarkovClassifier <Independent> hmm = IndependentMarkovClassifierPotentialFunctionTest
                                                       .CreateModel3();

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

            double[][][] observations = IndependentMarkovClassifierPotentialFunctionTest.sequences2;
            int[]        labels       = IndependentMarkovClassifierPotentialFunctionTest.labels2;

            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.AreEqual(scaling1[i], scaling2[i], 1e-8);
                        Assert.IsFalse(Double.IsNaN(scaling1[i]));
                        Assert.IsFalse(Double.IsNaN(scaling2[i]));
                    }
                }
            }
        }