Package edu.cmu.sphinx.linguist.acoustic

Examples of edu.cmu.sphinx.linguist.acoustic.HMMState


     * @param indexScore the current index into the TrainerScore
     * @param score      the score information
     * @param nextScore  the score information for the next frame
     */
    private void accumulateStateTransition(int indexScore, TrainerScore[] score, TrainerScore[] nextScore) {
        HMMState state = score[indexScore].getState();
        if (state == null) {
            // Non-emitting state
            return;
        }
        int indexState = state.getState();
        SenoneHMM hmm = (SenoneHMM) state.getHMM();
        float[][] matrix = hmm.getTransitionMatrix();

        // Find the index for current matrix in the transition matrix pool
        // int indexMatrix = matrixPool.indexOf(matrix);
        int indexMatrix = indexMap.get(matrix);
View Full Code Here


                // Certainly non-emitting, if it's not in an HMM.
                probCurrentFrame[index] = 0.0f;
            } else {
                // See if it's the last state in the HMM, i.e., if
                // it's non-emitting.
                HMMState state = (HMMState) node.getObject();
                if (!state.isEmitting()) {
                    probCurrentFrame[index] = 0.0f;
                }
                assert false;
            }
        }

        // If getFeature() is true, curFeature contains a valid
        // Feature. If not, a problem or EOF was encountered.
        lastFeatureIndex = 0;
        while (getFeature()) {
            forwardPass(score);
            scoreList.add(score);
            lastFeatureIndex++;
        }
        logger.info("Feature frames read: " + lastFeatureIndex);
        // Prepare for beta computation
        for (int i = 0; i < probCurrentFrame.length; i++) {
            probCurrentFrame[i] = LogMath.LOG_ZERO;
        }
        Node finalNode = graph.getFinalNode();
        int indexFinalNode = graph.indexOf(finalNode);
        // Overwrite in the right position
        probCurrentFrame[indexFinalNode] = 0.0f;
        for (finalNode.startIncomingEdgeIterator();
             finalNode.hasMoreIncomingEdges();) {
            Edge edge = finalNode.nextIncomingEdge();
            Node node = edge.getSource();
            int index = graph.indexOf(node);
            if (!node.isType("STATE")) {
                // Certainly non-emitting, if it's not in an HMM.
                probCurrentFrame[index] = 0.0f;
                assert false;
            } else {
                // See if it's the last state in the HMM, i.e., if
                // it's non-emitting.
                HMMState state = (HMMState) node.getObject();
                if (!state.isEmitting()) {
                    probCurrentFrame[index] = 0.0f;
                }
            }
        }
View Full Code Here

            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;
                }
View Full Code Here

            // Treat dummy node (and initial and final nodes) the same
            // as non-emitting
            if (!node.isType("STATE")) {
                continue;
            }
            HMMState state = (HMMState) node.getObject();
            SenoneHMM hmm = (SenoneHMM) state.getHMM();
            if (!state.isEmitting()) {
                continue;
            }
            // Initialize the current frame probability with log
            // probability of log(0f)
            probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
            for (node.startOutgoingEdgeIterator();
                 node.hasMoreOutgoingEdges();) {
                float logTransitionProbability;
                // Finds out what the next node and next state are
                Node nextNode = node.nextOutgoingEdge().getDestination();
                int indexNextNode = graph.indexOf(nextNode);
                HMMState nextState = (HMMState) nextNode.getObject();
                if (nextState != null) {
                    // Make sure that the transition happened to a
                    // non-emitting state, or to the same model
                    assert ((!nextState.isEmitting()) ||
                            (nextState.getHMM() == hmm));
                    if (nextState.getHMM() != hmm) {
                        logTransitionProbability = 0.0f;
                    } else {
                        logTransitionProbability =
                                hmm.getTransitionProbability(state.getState(),
                                        nextState.getState());
                    }
                } else {
                    // Next state is a dummy state or beginning of
                    // utterance.
                    logTransitionProbability = 0.0f;
                }
                // Adds the beta, the output prob, and the transition
                // from the next state into the current beta
                probCurrentFrame[indexNode] =
                        logMath.addAsLinear(probCurrentFrame[indexNode],
                                probNextFrame[indexNextNode] +
                                        logTransitionProbability +
                                        outputProbs[indexNextNode]);
            }
            // System.out.println("State= " + indexNode + " beta= " + probCurrentFrame[indexNode]);
            score[indexNode].setBeta(probCurrentFrame[indexNode]);
        }

        // Now, the non-emitting states

        // We have to go backwards because for non-emitting states we
        // use the current frame probability, and we need to refer to
        // states that are downstream in the graph
        for (int indexNode = graph.size() - 1; indexNode >= 0; indexNode--) {
            Node node = graph.getNode(indexNode);
            HMMState state = null;
            if (node.isType("STATE")) {
                state = (HMMState) node.getObject();
                if (state.isEmitting()) {
                    continue;
                }
            } else if (graph.isFinalNode(node)) {
                score[indexNode].setBeta(LogMath.LOG_ZERO);
                probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
                continue;
            }
            // Initialize the current frame probability with log(0f)
            probCurrentFrame[indexNode] = LogMath.LOG_ZERO;
            for (node.startOutgoingEdgeIterator();
                 node.hasMoreOutgoingEdges();) {
                float logTransitionProbability;
                // Finds out what the next node and next state are
                Node nextNode = node.nextOutgoingEdge().getDestination();
                int indexNextNode = graph.indexOf(nextNode);
                if (nextNode.isType("STATE")) {
                    HMMState nextState = (HMMState) nextNode.getObject();
                    // Make sure that the transition happened to a
                    // state that either is the same, or is emitting
                    assert ((nextState.isEmitting()) || (nextState == state));
                    // In any case, the transition (at this point) is
                    // assumed to be 1.0f, or 0.0f in log scale.
                    logTransitionProbability = 0.0f;
                    /*
                 if (!nextState.isEmitting()) {
View Full Code Here

TOP

Related Classes of edu.cmu.sphinx.linguist.acoustic.HMMState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.