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) {
if (i == 2) {
assertEquals(1.0, sparse_ip.getQuick(i), EPSILON);
} else {
assertEquals(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);
}
}
}
}