コード例 #1
0
 /**
  * Calculates probability p = w[1]*p[1] + w[2]*p[2] + ... (in log domain)
  *
  * @see
  *     edu.cmu.sphinx.linguist.language.ngram.LanguageModel#getProbability(edu.cmu.sphinx.linguist.WordSequence)
  */
 public float getProbability(WordSequence wordSequence) {
   float prob = 0;
   for (int i = 0; i < numberOfLanguageModels; i++) {
     float p = weights[i] + (languageModels.get(i)).getProbability(wordSequence);
     if (i == 0) {
       prob = p;
     } else {
       prob = logMath.addAsLinear(prob, p);
     }
   }
   return prob;
 }
コード例 #2
0
  public float calculateScore(Data feature) {
    if (feature instanceof DoubleData) {
      System.err.println("DoubleData conversion required on mixture level!");
    }

    float[] featureVector = FloatData.toFloatData(feature).getValues();

    float logTotal = LogMath.getLogZero();
    for (int i = 0; i < mixtureComponents.length; i++) {
      // In linear form, this would be:
      //
      // Total += Mixture[i].score * MixtureWeight[i]
      logTotal =
          logMath.addAsLinear(
              logTotal, mixtureComponents[i].getScore(featureVector) + logMixtureWeights[i]);
    }

    return logTotal;
  }