@Test
public void testTruncateModel() {

  DenseVector ip = new DenseVector(new double[]{0.0001, 0.0001, 0.9998});
  DenseMatrix tr = new DenseMatrix(new double[][]{
      {0.9998, 0.0001, 0.0001}, {0.0001, 0.9998, 0.0001},
      {0.0001, 0.0001, 0.9998}});
  DenseMatrix em = new DenseMatrix(new double[][]{
      {0.9998, 0.0001, 0.0001}, {0.0001, 0.9998, 0.0001},
      {0.0001, 0.0001, 0.9998}});
  HmmModel model = new HmmModel(tr, em, ip);
  // now truncate the model
  HmmModel sparseModel = HmmUtils.truncateModel(model, 0.01);
  // first make sure this is a valid model
  HmmUtils.validate(sparseModel);
  // now check whether the values are as expected
  Vector sparse_ip = sparseModel.getInitialProbabilities();
  Matrix sparse_tr = sparseModel.getTransitionMatrix();
  Matrix sparse_em = sparseModel.getEmissionMatrix();
  for (int i = 0; i < sparseModel.getNrOfHiddenStates(); ++i) {
    assertEquals(i == 2 ? 1.0 : 0.0, sparse_ip.getQuick(i), EPSILON);
    for (int j = 0; j < sparseModel.getNrOfHiddenStates(); ++j) {
      if (i == j) {
        assertEquals(1.0, sparse_tr.getQuick(i, j), EPSILON);
        assertEquals(1.0, sparse_em.getQuick(i, j), EPSILON);
      } else {
        assertEquals(0.0, sparse_tr.getQuick(i, j), EPSILON);
        assertEquals(0.0, sparse_em.getQuick(i, j), EPSILON);
      }
    }
  }
}