HmmAlgorithms { public static int[] viterbiAlgorithm(HmmModel model, int[] observations, boolean scaled) { double[][] delta = new double[observations.length][model .getNrOfHiddenStates()]; int[][] phi = new int[observations.length - 1][model.getNrOfHiddenStates()]; int[] sequence = new int[observations.length]; viterbiAlgorithm(sequence, delta, phi, model, observations, scaled); return sequence; } private  HmmAlgorithms(); static Matrix forwardAlgorithm(HmmModel model, int[] observations, boolean scaled); static Matrix backwardAlgorithm(HmmModel model, int[] observations, boolean scaled); static int[] viterbiAlgorithm(HmmModel model, int[] observations, boolean scaled);  }
@Test public void testViterbiAlgorithm() { int[] expected = {2, 0, 3, 3, 0, 0, 2}; int[] computed = HmmAlgorithms.viterbiAlgorithm(getModel(), getSequence(), false); assertNotNull(computed); assertEquals(computed.length, getSequence().length); for (int i = 0; i < getSequence().length; ++i) { assertEquals(expected[i], computed[i]); } }
@Test public void testLogScaledViterbiAlgorithm() { int[] expected = {2, 0, 3, 3, 0, 0, 2}; int[] computed = HmmAlgorithms.viterbiAlgorithm(getModel(), getSequence(), true); assertNotNull(computed); assertEquals(computed.length, getSequence().length); for (int i = 0; i < getSequence().length; ++i) { assertEquals(expected[i], computed[i]); } }