public static CreateModel2 ( double &sequences, int &labels ) : HiddenMarkovClassifier |
||
sequences | double | |
labels | int | |
Результат | HiddenMarkovClassifier |
public void LogForwardTest() { double[][][] observations; int[] labels; var hmm = IndependentMarkovFunctionTest.CreateModel2(out observations, out labels); MarkovMultivariateFunction function = new MarkovMultivariateFunction(hmm, includePriors: false); foreach (double[][] x in observations) { foreach (int y in labels) { double[,] actual = new double[5, 2]; Accord.Statistics.Models.Fields. ForwardBackwardAlgorithm.LogForward(function.Factors[y], x, y, actual); double[,] expected = new double[5, 2]; Accord.Statistics.Models.Markov. ForwardBackwardAlgorithm.LogForward(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); } } } } }
public void GradientTest_MarkovIndependent() { double[][][] observations; int[] labels; HiddenMarkovClassifier <Independent> hmm = IndependentMarkovFunctionTest.CreateModel2(out observations, out labels); var function = new MarkovMultivariateFunction(hmm); var model = new HiddenConditionalRandomField <double[]>(function); var target = new ForwardBackwardGradient <double[]>(model); target.Regularization = 0; FiniteDifferences diff = new FiniteDifferences(function.Weights.Length); diff.Function = parameters => func(model, parameters, observations, labels); double[] expected = diff.Compute(function.Weights); double[] actual = target.Gradient(function.Weights, observations, labels); for (int i = 0; i < actual.Length; i++) { if (double.IsNaN(expected[i])) { continue; } Assert.AreEqual(expected[i], actual[i], 1e-5); Assert.IsFalse(double.IsNaN(actual[i])); } }
public void ForwardTest() { double[][][] observations; int[] labels; var hmm = IndependentMarkovFunctionTest.CreateModel2(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.AreEqual(scaling1[i], scaling2[i], 1e-10); } } } }