// Treat dummy node (and initial and final nodes) the same
// as non-emitting
if (!node.isType("STATE")) {
continue;
}
SenoneHMMState state = (SenoneHMMState) node.getObject();
SenoneHMM hmm = (SenoneHMM) state.getHMM();
if (!state.isEmitting()) {
continue;
}
// Initialize the current frame probability with 0.0f, log scale
probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
for (node.startIncomingEdgeIterator();
node.hasMoreIncomingEdges();) {
// Finds out what the previous node and previous state are
Node previousNode = node.nextIncomingEdge().getSource();
int indexPreviousNode = graph.indexOf(previousNode);
HMMState previousState = (HMMState) previousNode.getObject();
float logTransitionProbability;
// previous state could be have an associated hmm state...
if (previousState != null) {
// Make sure that the transition happened from a state
// that either is in the same model, or was a
// non-emitting state
assert ((!previousState.isEmitting()) ||
(previousState.getHMM() == hmm));
if (!previousState.isEmitting()) {
logTransitionProbability = 0.0f;
} else {
logTransitionProbability =
hmm.getTransitionProbability(
previousState.getState(),
state.getState());
}
} else {
// Previous state is a dummy state or beginning of
// utterance.
logTransitionProbability = 0.0f;
}
// Adds the alpha and transition from the previous
// state into the current alpha
probCurrentFrame[indexNode] =
logMath.addAsLinear(probCurrentFrame[indexNode],
probPreviousFrame[indexPreviousNode] +
logTransitionProbability);
// System.out.println("State= " + indexNode + " curr "
// + probCurrentFrame[indexNode] + " prev " +
// probPreviousFrame[indexNode] + " trans " +
// logTransitionProbability);
}
// Finally, multiply by this state's output probability for the
// current Feature (add in log scale)
probCurrentFrame[indexNode] += outputProbs[indexNode];
// System.out.println("State= " + indexNode + " alpha= " +
// probCurrentFrame[indexNode]);
score[indexNode].setAlpha(probCurrentFrame[indexNode]);
}
// Finally, the non-emitting states
for (int indexNode = 0; indexNode < graph.size(); indexNode++) {
Node node = graph.getNode(indexNode);
HMMState state = null;
SenoneHMM hmm = null;
if (node.isType("STATE")) {
state = (HMMState) node.getObject();
hmm = (SenoneHMM) state.getHMM();
if (state.isEmitting()) {
continue;
}
} else if (graph.isInitialNode(node)) {
score[indexNode].setAlpha(LogMath.LOG_ZERO);
probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
continue;
}
// Initialize the current frame probability 0.0f, log scale
probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
for (node.startIncomingEdgeIterator();
node.hasMoreIncomingEdges();) {
float logTransitionProbability;
// Finds out what the previous node and previous state are
Node previousNode = node.nextIncomingEdge().getSource();
int indexPreviousNode = graph.indexOf(previousNode);
if (previousNode.isType("STATE")) {
HMMState previousState =
(HMMState) previousNode.getObject();
// Make sure that the transition happened from a
// state that either is in the same model, or was
// a non-emitting state
assert ((!previousState.isEmitting()) ||
(previousState.getHMM() == hmm));
if (!previousState.isEmitting()) {
logTransitionProbability = 0.0f;
} else {
// previousState == state
logTransitionProbability =
hmm.getTransitionProbability(
previousState.getState(),
state.getState());
}
} else {
logTransitionProbability = 0.0f;
}
// Adds the alpha and transition from the previous