for (int row = 0; row < transitionProbabilityMatrix.getRowCount(); row++) {
// note that we are using row vectors here, because dense matrices give us
// the underlying array wrapped by the vector object so we can directly
// mutate the values beneath
DoubleVector rowVector = transitionProbabilityMatrix.getRowVector(row);
rowVector = rowVector.divide(rowVector.sum());
if (log) {
rowVector = rowVector.log();
}
transitionProbabilityMatrix.setRowVector(row, rowVector);
rowVector = emissionProbabilitiyMatrix.getRowVector(row);