Package edu.cmu.sphinx.util

Examples of edu.cmu.sphinx.util.LogMath


    }

    @Override
    public float calculateScore(Data data) {
        float logTotal = LogMath.LOG_ZERO;
        LogMath logMath = LogMath.getLogMath();
        for (Float mixtureScore : calculateComponentScore(data))
            logTotal = logMath.addAsLinear(logTotal, mixtureScore);

        return logTotal;
    }
View Full Code Here


        parser.expectToken("<LogProbs>");
        logProbabilities = parser.getFloatArray();
        parser.expectToken("</LogProbs>");
        parser.expectToken("</TransitionModel>");

        LogMath logMath = LogMath.getLogMath();
        for (int i = 0; i < logProbabilities.length; ++i)
            logProbabilities[i] = logMath.lnToLog(logProbabilities[i]);
    }
View Full Code Here

     * @param cluster the cluster to sum over
     * @return the probability sum
     */
    protected double clusterProbability(List<Node> cluster) {
        float p = LogMath.LOG_ZERO;
        LogMath logMath = LogMath.getLogMath();

        for (Node node : cluster)
            p = logMath.addAsLinear(p, (float)node.getPosterior());

        return p;
    }
View Full Code Here

    /**
     * Adds skip elements for each word slot in which the word posteriors do not add up to linear 1.
     */
    public void fillInBlanks() {
        LogMath logMath = LogMath.getLogMath();
        int index = 0;
        for (ConfusionSet set : confusionSets) {
            float sum = LogMath.LOG_ZERO;
            for (Double val : set.keySet()) {
                sum = logMath.addAsLinear(sum, val.floatValue());
            }
            if (sum < LogMath.LOG_ONE - 10) {
                float remainder = logMath.subtractAsLinear
                    (LogMath.LOG_ONE, sum);
                addWordHypothesis(index, "<skip>", remainder);
            } else {
                ConfusionSet newSet = new ConfusionSet();
                for (Map.Entry<Double, Set<WordResult>> entry : set.entrySet()) {
View Full Code Here

            throws FileNotFoundException, IOException {

        String location = "";
        InputStream inputStream = StreamFactory.getInputStream(location, path);

        LogMath logMath = LogMath.getLogMath();
        logger.info("Loading transition matrices from: ");
        logger.info(path);

        Pool<float[][]> pool = new Pool<float[][]>(path);
        ExtendedStreamTokenizer est = new ExtendedStreamTokenizer(inputStream, '#', false);

        est.expectString("tmat");
        int numMatrices = est.getInt("numMatrices");
        est.expectString("X");
        // numStates = est.getInt("numStates");

        for (int i = 0; i < numMatrices; i++) {
            est.expectString("tmat");
            est.expectString("[" + i + ']');
            est.expectString("nstate");
            // Number of emitting states + 1, final non-emitting state
            int numStates = est.getInt("numStates") + 1;
            float[][] tmat = new float[numStates][numStates];

            for (int j = 0; j < numStates; j++) {
                for (int k = 0; k < numStates; k++) {

                    // the last row is just zeros, so we just do
                    // the first (numStates - 1) rows

                    if (j < numStates - 1) {
                         if (k == j || k == j + 1) {
                             tmat[j][k] = est.getFloat("tmat value");
                         }
                    }

                    tmat[j][k] = logMath.linearToLog(tmat[j][k]);

                    if (logger.isLoggable(Level.FINE)) {
                        logger.fine("tmat j " + j + " k "
                                + k + " tm " + tmat[j][k]);
                    }
View Full Code Here

            return Double.NEGATIVE_INFINITY;
        }
        float totalSim = LogMath.LOG_ZERO;
        float wordPairCount = (float) 0.0;
        HashSet<String> wordsSeen1 = new HashSet<String>();
        LogMath logMath = LogMath.getLogMath();

        for (Node node1 : c1.getElements()) {
            String word1 = node1.getWord().getSpelling();
            if (wordsSeen1.contains(word1)) {
                continue;
            }
            wordsSeen1.add(word1);
            HashSet<String> wordsSeen2 = new HashSet<String>();
            for (Node node2 : c2.getElements()) {
                String word2 = node2.getWord().getSpelling();
                if (wordsSeen2.contains(word2)) {
                    continue;
                }
                wordsSeen2.add(word2);
                float sim = (float) computePhoneticSimilarity(node1, node2);
                sim = logMath.linearToLog(sim);
                sim += wordSubClusterProbability(c1, word1);
                sim += wordSubClusterProbability(c2, word2);
                totalSim = logMath.addAsLinear(totalSim, sim);
                wordPairCount++;
            }
        }
        return totalSim - logMath.logToLinear(wordPairCount);
    }
View Full Code Here

     * @param cluster2 the second cluster
     * @return The intra-cluster distance, or Double.NEGATIVE_INFINITY if the clusters should never be clustered
     *         together.
     */
    protected double intraClusterDistance(Cluster cluster1, Cluster cluster2) {
        LogMath logMath = LogMath.getLogMath();
        double maxSim = Double.NEGATIVE_INFINITY;

        for (Node node1 : cluster1.getElements()) {
            for (Node node2 : cluster2.getElements()) {
                if (!node1.getWord().getSpelling().equals(
                            node2.getWord().getSpelling()))
                    return Double.NEGATIVE_INFINITY;

                if (node1.hasAncestralRelationship(node2))
                    return Double.NEGATIVE_INFINITY;

                double overlap = getOverlap(node1, node2);
                if (overlap > 0.0) {
                    overlap = logMath.logToLinear((float) overlap);
                    overlap += node1.getPosterior() + node2.getPosterior();
                    if (overlap > maxSim) {
                        maxSim = overlap;
                    }
                }
View Full Code Here

        }

        Pool<float[][]> pool = new Pool<float[][]>(path);
        ExtendedStreamTokenizer est =
            new ExtendedStreamTokenizer(inputStream, '#', false);
        LogMath logMath = LogMath.getLogMath();
        est.expectString("tmat");
        int numMatrices = est.getInt("numMatrices");
        int numStates = est.getInt("numStates");
        logger.fine("with " + numMatrices + " and " + numStates + " states");

        // read in the matrices
        for (int i = 0; i < numMatrices; i++) {
            est.expectString("tmat");
            est.expectString("[" + i + ']');
            float[][] tmat = new float[numStates][numStates];
            for (int j = 0; j < numStates; j++) {
                for (int k = 0; k < numStates; k++) {
                    // the last row is just zeros, so we just do
                    // the first (numStates - 1) rows
                    if (j < numStates - 1) {
                        if (k == j || k == j + 1) {
                            tmat[j][k] = est.getFloat("tmat value");
                        }
                    }
                    tmat[j][k] = logMath.linearToLog(tmat[j][k]);
                    if (logger.isLoggable(Level.FINE)) {
                        logger.fine("tmat j " + j + " k " + k + " tm " + tmat[j][k]);
                    }
                }
            }
View Full Code Here

    this.logger = Logger.getLogger(getClass().getName());
    this.acousticModel = acousticModel;
    this.grammar = grammar;
    this.unitManager = unitManager;

    LogMath logMath = LogMath.getLogMath();
    this.logWordInsertionProbability = logMath
        .linearToLog(wordInsertionProbability);
    this.logSilenceInsertionProbability = logMath
        .linearToLog(silenceInsertionProbability);
    this.logUnitInsertionProbability = logMath
        .linearToLog(unitInsertionProbability);
    this.logFillerInsertionProbability = logMath
        .linearToLog(fillerInsertionProbability);
    this.languageWeight = languageWeight;
    this.addOutOfGrammarBranch = addOutOfGrammarBranch;
    this.logOutOfGrammarBranchProbability = logMath
        .linearToLog(outOfGrammarBranchProbability);

    this.logPhoneInsertionProbability = logMath
        .linearToLog(logPhoneInsertionProbability);
    if (addOutOfGrammarBranch) {
      this.phoneLoopAcousticModel = phoneLoopAcousticModel;
    }
  }
View Full Code Here

    grammar = (Grammar) ps.getComponent(GRAMMAR);
    unitManager = (UnitManager) ps.getComponent(UNIT_MANAGER);

    // get the rest of the configuration data
    LogMath logMath = LogMath.getLogMath();
    logWordInsertionProbability = logMath.linearToLog(ps
        .getDouble(PROP_WORD_INSERTION_PROBABILITY));
    logSilenceInsertionProbability = logMath.linearToLog(ps
        .getDouble(PROP_SILENCE_INSERTION_PROBABILITY));
    logUnitInsertionProbability = logMath.linearToLog(ps
        .getDouble(PROP_UNIT_INSERTION_PROBABILITY));
    logFillerInsertionProbability = logMath.linearToLog(ps
        .getDouble(PROP_FILLER_INSERTION_PROBABILITY));
    languageWeight = ps.getFloat(Linguist.PROP_LANGUAGE_WEIGHT);
    addOutOfGrammarBranch = ps.getBoolean(ADD_OUT_OF_GRAMMAR_BRANCH);
    logOutOfGrammarBranchProbability = logMath.linearToLog(ps
        .getDouble(OUT_OF_GRAMMAR_PROBABILITY));

    logPhoneInsertionProbability = logMath.linearToLog(ps
        .getDouble(PHONE_INSERTION_PROBABILITY));
    if (addOutOfGrammarBranch) {
      phoneLoopAcousticModel = (AcousticModel) ps
          .getComponent(PHONE_LOOP_ACOUSTIC_MODEL);
    }
View Full Code Here

TOP

Related Classes of edu.cmu.sphinx.util.LogMath

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.