private float ConvertScore(float val) { // Convert to the appropriate base. val = LogMath.LnToLog(val); // TODO: Need to use mean and variance transforms here if (float.IsNaN(val)) { this.LogInfo("gs is Nan, converting to 0"); val = LogMath.LogZero; } if (val < DistFloor) { val = DistFloor; } return(val); }
/** * /// Calculate the score for this mixture against the given feature. We model the output * /// distributions using a mixture of Gaussians, therefore the current implementation is simply * /// the computation of a multi-dimensional Gaussian. <p/> <p><b>Normal(x) = exp{-0.5/// (x-m)' * * /// inv(Var)/// (x-m)} / {sqrt((2/// PI) ^ N)/// det(Var))}</b></p> * /// <p/> * /// where <b>x</b> and <b>m</b> are the incoming cepstra and mean vector respectively, * /// <b>Var</b> is the Covariance matrix, <b>det()</b> is the determinant of a matrix, * /// <b>inv()</b> is its inverse, <b>exp</b> is the exponential operator, <b>x'</b> is the * /// transposed vector of <b>x</b> and <b>N</b> is the dimension of the vectors <b>x</b> and * /// <b>m</b>. * * /// @param feature the feature to score * /// @return the score, in log, for the given feature */ public float GetScore(float[] feature) { // float logVal = 0.0f; var logDval = LogPreComputedGaussianFactor; // First, compute the argument of the exponential function in // the definition of the Gaussian, then convert it to the // appropriate base. If the log base is <code>Math.E</code>, // then no operation is necessary. for (var i = 0; i < feature.Length; i++) { var logDiff = feature[i] - MeanTransformed[i]; logDval += logDiff * logDiff * PrecisionTransformed[i]; } // logDval = -logVal / 2; // At this point, we have the ln() of what we need, that is, // the argument of the exponential in the javadoc comment. // Convert to the appropriate base. logDval = LogMath.LnToLog(logDval); // System.out.println("MC: getscore " + logDval); // TODO: Need to use mean and variance transforms here if (float.IsNaN(logDval)) { this.LogInfo("gs is Nan, converting to 0"); logDval = LogMath.LogZero; } if (logDval < DistFloor) { logDval = DistFloor; } return(logDval); }
/** * Converts the probability from -ln to logmath * * @param lnProb the probability to convert. Probabilities in the arpa format in negative natural log format. We * convert them to logmath. * @return the converted probability in logMath log base */ private float ConvertProbability(float lnProb) { return(_logMath.LnToLog(-lnProb)); }