@Test public void testLogp() { System.out.println("logp"); HMM hmm = new HMM(pi, new Matrix(a), new Matrix(b)); int[] o = {0, 0, 1, 1, 0, 1, 1, 0}; double expResult = -5.609373; double result = hmm.logp(o); assertEquals(expResult, result, 1E-6); }
public double logp(int[] o, int[] s) { if (o.length != s.length) { throw new IllegalArgumentException("The observation sequence and state sequence are not the same length."); } int n = s.length; double p = MathEx.log(pi[s[0]]) + MathEx.log(b.get(s[0], o[0])); for (int i = 1; i < n; i++) { p += MathEx.log(a.get(s[i - 1], s[i])) + MathEx.log(b.get(s[i], o[i])); } return p; }
HMM implements Serializable { public double logp(int[] o, int[] s) { if (o.length != s.length) { throw new IllegalArgumentException("The observation sequence and state sequence are not the same length."); } int n = s.length; double p = MathEx.log(pi[s[0]]) + MathEx.log(b.get(s[0], o[0])); for (int i = 1; i < n; i++) { p += MathEx.log(a.get(s[i - 1], s[i])) + MathEx.log(b.get(s[i], o[i])); } return p; } }
HMM implements Serializable { public double logp(int[] o, int[] s) { if (o.length != s.length) { throw new IllegalArgumentException("The observation sequence and state sequence are not the same length."); } int n = s.length; double p = MathEx.log(pi[s[0]]) + MathEx.log(b.get(s[0], o[0])); for (int i = 1; i < n; i++) { p += MathEx.log(a.get(s[i - 1], s[i])) + MathEx.log(b.get(s[i], o[i])); } return p; } HMM(double[] pi, Matrix a, Matrix b); }
HMM implements Serializable { public double logp(int[] o, int[] s) { if (o.length != s.length) { throw new IllegalArgumentException("The observation sequence and state sequence are not the same length."); } int n = s.length; double p = MathEx.log(pi[s[0]]) + MathEx.log(b.get(s[0], o[0])); for (int i = 1; i < n; i++) { p += MathEx.log(a.get(s[i - 1], s[i])) + MathEx.log(b.get(s[i], o[i])); } return p; } HMM(double[] pi, Matrix a, Matrix b); double[] getInitialStateProbabilities(); Matrix getStateTransitionProbabilities(); Matrix getSymbolEmissionProbabilities(); double p(int[] o, int[] s); double logp(int[] o, int[] s); double p(int[] o); double logp(int[] o); int[] predict(int[] o); static HMM fit(int[][] observations, int[][] labels); static HMM fit(T[][] observations, int[][] labels, ToIntFunction<T> ordinal); void update(T[][] observations, int iterations, ToIntFunction<T> ordinal); void update(int[][] observations, int iterations); @Override String toString(); }
HMM implements Serializable { public double logp(int[] o, int[] s) { if (o.length != s.length) { throw new IllegalArgumentException("The observation sequence and state sequence are not the same length."); } int n = s.length; double p = MathEx.log(pi[s[0]]) + MathEx.log(b.get(s[0], o[0])); for (int i = 1; i < n; i++) { p += MathEx.log(a.get(s[i - 1], s[i])) + MathEx.log(b.get(s[i], o[i])); } return p; } HMM(double[] pi, Matrix a, Matrix b); double[] getInitialStateProbabilities(); Matrix getStateTransitionProbabilities(); Matrix getSymbolEmissionProbabilities(); double p(int[] o, int[] s); double logp(int[] o, int[] s); double p(int[] o); double logp(int[] o); int[] predict(int[] o); static HMM fit(int[][] observations, int[][] labels); static HMM fit(T[][] observations, int[][] labels, ToIntFunction<T> ordinal); void update(T[][] observations, int iterations, ToIntFunction<T> ordinal); void update(int[][] observations, int iterations); @Override String toString();  }