public void UpdateTopScores(IData feature) { if (feature is DoubleData) { Console.WriteLine("DoubleData conversion required on mixture level!"); } var firstSampleNumber = FloatData.ToFloatData(feature).FirstSampleNumber; if (_toStoreScore) { _curScores = GetStoredScores(firstSampleNumber); } else { if (_curScores != null && _curScores.FrameStartSample != firstSampleNumber) { _curScores = null; } } if (_curScores != null) { //component scores for this frame was already calculated return; } var featureVector = FloatData.ToFloatData(feature).Values; UpdateTopScores(featureVector); //store just calculated score in list _curScores = CreateFromTopGau(firstSampleNumber); if (_toStoreScore) { StoreScores(_curScores); } }
public void UpdateScores(IData feature) { if (feature is DoubleData) { this.LogInfo("DoubleData conversion required on mixture level!"); } var firstSampleNumber = FloatData.ToFloatData(feature).FirstSampleNumber; if (_gauCalcSampleNumber != firstSampleNumber) { var featureVector = FloatData.ToFloatData(feature).Values; UpdateScores(featureVector); _gauCalcSampleNumber = firstSampleNumber; } }
/// <summary> /// Calculates the scores for each component in the senone. /// </summary> /// <param name="feature">The feature to score.</param> /// <returns>The LogMath log scores for the feature, one for each component.</returns> public override float[] CalculateComponentScore(IData feature) { if (feature is DoubleData) this.LogInfo("DoubleData conversion required on mixture level!"); var featureVector = FloatData.ToFloatData(feature).Values; var logComponentScore = new float[_mixtureComponents.Length]; for (var i = 0; i < _mixtureComponents.Length; i++) { // In linear form, this would be: // // Total += Mixture[i].score * MixtureWeight[i] logComponentScore[i] = _mixtureComponents[i].GetScore(featureVector) + MixtureWeights.Get(_Id, 0, i); } return logComponentScore; }
public override float CalculateScore(IData feature) { if (feature is DoubleData) { this.LogInfo("DoubleData conversion required on mixture level!"); } var featureVector = FloatData.ToFloatData(feature).Values; var logTotal = LogMath.LogZero; for (var 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) + MixtureWeights.Get(_Id, 0, i)); } return(logTotal); }
public void Collect(SpeechResult result) { Token token = result.Result.GetBestToken(); float[] componentScore, featureVector, posteriors, tmean; int[] len; float dnom, wtMeanVar, wtDcountVar, wtDcountVarMean, mean; int mId, cluster; int numStreams, gauPerState; if (token == null) { throw new Exception("Best token not found!"); } do { FloatData feature = (FloatData)token.Data; ISearchState ss = token.SearchState; if (!(ss is IHMMSearchState && ss.IsEmitting)) { token = token.Predecessor; continue; } componentScore = token.CalculateComponentScore(feature); featureVector = FloatData.ToFloatData(feature).Values; mId = (int)((IHMMSearchState)token.SearchState).HmmState .GetMixtureId(); if (_loader is Sphinx3Loader && _loader.HasTiedMixtures()) { // use CI phone ID for tied mixture model mId = _loader.Senone2Ci[mId]; } len = _loader.VectorLength; numStreams = _loader.NumStreams; gauPerState = _loader.NumGaussiansPerState; posteriors = ComputePosterios(componentScore, numStreams); int featVectorStartIdx = 0; for (int i = 0; i < numStreams; i++) { for (int j = 0; j < gauPerState; j++) { cluster = _means.GetClassIndex(mId * numStreams * gauPerState + i * gauPerState + j); dnom = posteriors[i * gauPerState + j]; if (dnom > 0f) { tmean = _loader.MeansPool.Get( mId * numStreams * gauPerState + i * gauPerState + j); for (int k = 0; k < len[i]; k++) { mean = posteriors[i * gauPerState + j] * featureVector[k + featVectorStartIdx]; wtMeanVar = mean * _loader.VariancePool.Get( mId * numStreams * gauPerState + i * gauPerState + j)[k]; wtDcountVar = dnom * _loader.VariancePool.Get( mId * numStreams * gauPerState + i * gauPerState + j)[k]; for (int p = 0; p < len[i]; p++) { wtDcountVarMean = wtDcountVar * tmean[p]; for (int q = p; q < len[i]; q++) { RegLs[cluster][i][k][p][q] += wtDcountVarMean * tmean[q]; } RegLs[cluster][i][k][p][len[i]] += wtDcountVarMean; RegRs[cluster][i][k][p] += wtMeanVar * tmean[p]; } RegLs[cluster][i][k][len[i]][len[i]] += wtDcountVar; RegRs[cluster][i][k][len[i]] += wtMeanVar; } } } featVectorStartIdx += len[i]; } token = token.Predecessor; } while (token != null); }