@Test
public void testViterbiTraining() {

  // initialize the expected model parameters (from R)
  // expected transition matrix
  double[][] transitionE = {{0.3125, 0.0625, 0.3125, 0.3125},
      {0.25, 0.25, 0.25, 0.25}, {0.5, 0.071429, 0.357143, 0.071429},
      {0.5, 0.1, 0.1, 0.3}};
  // initialize the emission matrix
  double[][] emissionE = {{0.882353, 0.058824, 0.058824},
      {0.333333, 0.333333, 0.3333333}, {0.076923, 0.846154, 0.076923},
      {0.111111, 0.111111, 0.777778}};
  // train the given network to the following output sequence
  int[] observed = {1, 0, 2, 2, 0, 0, 1, 1, 1, 0, 2, 0, 1, 0, 0};
  HmmModel trained = HmmTrainer.trainViterbi(getModel(), observed, 0.5, 0.1, 10, false);
  // now check whether the model matches our expectations
  Matrix emissionMatrix = trained.getEmissionMatrix();
  Matrix transitionMatrix = trained.getTransitionMatrix();
  for (int i = 0; i < trained.getNrOfHiddenStates(); ++i) {
    for (int j = 0; j < trained.getNrOfHiddenStates(); ++j) {
      assertEquals(transitionMatrix.getQuick(i, j), transitionE[i][j], EPSILON);
    }
    for (int j = 0; j < trained.getNrOfOutputStates(); ++j) {
      assertEquals(emissionMatrix.getQuick(i, j), emissionE[i][j], EPSILON);
    }
  }
}