*
* @param result
* Result object to collect counts from.
*/
public void collect(SpeechResult result) throws Exception {
Token token = result.getResult().getBestToken();
float[] componentScore, featureVector, posteriors, tmean;
float dnom, wtMeanVar, wtDcountVar, wtDcountVarMean, mean;
int mId, len, cluster;
if (token == null)
throw new Exception("Best token not found!");
do {
FloatData feature = (FloatData) token.getData();
SearchState ss = token.getSearchState();
if (!(ss instanceof HMMSearchState && ss.isEmitting())) {
token = token.getPredecessor();
continue;
}
componentScore = token.calculateComponentScore(feature);
featureVector = FloatData.toFloatData(feature).getValues();
mId = (int) ((HMMSearchState)token.getSearchState()).getHMMState().getMixtureId();
posteriors = this.computePosterios(componentScore);
len = loader.getVectorLength()[0];
for (int i = 0; i < componentScore.length; i++) {
cluster = means.getClassIndex(mId
* loader.getNumGaussiansPerState() + i);
dnom = posteriors[i];
if (dnom > 0.) {
tmean = loader.getMeansPool().get(
mId * loader.getNumGaussiansPerState() + i);
for (int j = 0; j < featureVector.length; j++) {
mean = posteriors[i] * featureVector[j];
wtMeanVar = mean
* loader.getVariancePool().get(mId
* loader.getNumGaussiansPerState()
+ i)[j];
wtDcountVar = dnom
* loader.getVariancePool().get(mId
* loader.getNumGaussiansPerState()
+ i)[j];
for (int p = 0; p < featureVector.length; p++) {
wtDcountVarMean = wtDcountVar * tmean[p];
for (int q = p; q < featureVector.length; q++) {
regLs[cluster][0][j][p][q] += wtDcountVarMean
* tmean[q];
}
regLs[cluster][0][j][p][len] += wtDcountVarMean;
regRs[cluster][0][j][p] += wtMeanVar * tmean[p];
}
regLs[cluster][0][j][len][len] += wtDcountVar;
regRs[cluster][0][j][len] += wtMeanVar;
}
}
}
token = token.getPredecessor();
} while (token != null);
}