public float[] calculateComponentScore(Data feature){ return new float[((FloatData) feature).getValues().length]; }
/** * Calculate the score for this mixture against the given feature. * <p> * Note: The support of <code>DoubleData</code>-features would require an array conversion to * float[]. Because getScore might be invoked with very high frequency, features are restricted * to be <code>FloatData</code>s. * * @param feature the feature to score * @return the score, in log, for the given feature */ public float getScore(FloatData feature) { return getScore(feature.getValues()); }
/** * Converts DoubleData object to FloatDatas. * @param data data to convert * @return converted data */ public static DoubleData FloatData2DoubleData(FloatData data) { int numSamples = data.getValues().length; double[] doubleData = new double[numSamples]; float[] values = data.getValues(); for (int i = 0; i < values.length; i++) { doubleData[i] = values[i]; } return new DoubleData(doubleData, data.getSampleRate(), data.getFirstSampleNumber()); }
public float[] calculateComponentScore(Data data) { float[] features = FloatData.toFloatData(data).getValues(); int dim = meansInvVars.length / gconsts.length; if (features.length != dim) { String fmt = "feature vector must be of length %d, got %d"; String msg = String.format(fmt, dim, features.length); throw new IllegalArgumentException(msg); } float[] likelihoods = Arrays.copyOf(gconsts, gconsts.length); for (int i = 0; i < likelihoods.length; ++i) { for (int j = 0; j < features.length; ++j) { int k = i * features.length + j; likelihoods[i] += meansInvVars[k] * features[j]; likelihoods[i] -= .5f * invVars[k] * features[j] * features[j]; } likelihoods[i] = LogMath.getLogMath().lnToLog(likelihoods[i]); } return likelihoods; }
} else if (input instanceof FloatData) { FloatData fd = (FloatData) input; float[] values = fd.getValues(); System.out.print("Frame " + values.length); for (float val : values) {
float[] featureData = ((FloatData) feature).getValues(); if (featureLength < 0) { featureLength = featureData.length;
public void updateScores(Data feature) { if (feature instanceof DoubleData) System.err.println("DoubleData conversion required on mixture level!"); long firstSampleNumber = FloatData.toFloatData(feature).getFirstSampleNumber(); if (gauCalcSampleNumber != firstSampleNumber) { float[] featureVector = FloatData.toFloatData(feature).getValues(); updateScores(featureVector); gauCalcSampleNumber = firstSampleNumber; } }
float[] featureData = ((FloatData) feature).getValues(); if (featureLength < 0) { featureLength = featureData.length;
/** * Calculates the scores for each component in the senone. * * @param feature the feature to score * @return the LogMath log scores for the feature, one for each component */ public float[] calculateComponentScore(Data feature) { if (feature instanceof DoubleData) System.err.println("DoubleData conversion required on mixture level!"); float[] featureVector = FloatData.toFloatData(feature).getValues(); float[] logComponentScore = new float[mixtureComponents.length]; for (int 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; }
@Override 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.LOG_ZERO; 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) + mixtureWeights.get(id, 0, i)); } return logTotal; }
@Override public Data getData() throws DataProcessingException { Data data = getPredecessor().getData(); if (data instanceof FloatData) { float[] values = ((FloatData) data).getValues(); if (gainFactor != 1.0) { // apply the gain-factor for (int i = 0; i < values.length; i++) { values[i] *= gainFactor; } } } else if (data instanceof DoubleData) { double[] values = ((DoubleData) data).getValues(); if (gainFactor != 1.0) { // apply the gain-factor for (int i = 0; i < values.length; i++) { values[i] *= gainFactor; } } } return data; }
float[] spectrumData = ((FloatData) spectrum).getValues(); float[] intensities = new float[spectrumData.length]; for (int i = 0; i < intensities.length; i++) {
float[] features = floatData.getValues();
String[] tokens = line.split(" "); Assert.assertTrue(data instanceof FloatData); float[] values = ((FloatData) data).getValues(); Assert.assertEquals(values.length, (int) Integer.valueOf(tokens[1]));
@Override public Data getData() throws DataProcessingException { Data d = getPredecessor().getData(); if (d instanceof DoubleData && convMode.equals(CONVERT_D2F)) { DoubleData dd = (DoubleData) d; d = new FloatData(MatrixUtils.double2float(dd.getValues()), dd.getSampleRate(), dd.getFirstSampleNumber()); } else if (d instanceof FloatData && convMode.equals(CONVERT_F2D)) { FloatData fd = (FloatData) d; d = new DoubleData(MatrixUtils.float2double(fd.getValues()), fd.getSampleRate(), fd.getFirstSampleNumber()); } return d; } }
public void updateTopScores(Data feature) { if (feature instanceof DoubleData) System.err.println("DoubleData conversion required on mixture level!"); long firstSampleNumber = FloatData.toFloatData(feature).getFirstSampleNumber(); if (toStoreScore) { curScores = getStoredScores(firstSampleNumber); } else { if (curScores != null && curScores.getFrameStartSample() != firstSampleNumber) curScores = null; } if (curScores != null) //component scores for this frame was already calculated return; float[] featureVector = FloatData.toFloatData(feature).getValues(); updateTopScores(featureVector); //store just calculated score in list curScores = createFromTopGau(firstSampleNumber); if (toStoreScore) storeScores(curScores); }
/** Accumulate the means. */ private void accumulateMean(int senone, TrainerScore score) { if (senone == TrainerAcousticModel.ALL_MODELS) { for (int i = 0; i < senonePool.size(); i++) { accumulateMean(i, score); } } else { GaussianMixture gaussian = (GaussianMixture)senonePool.get(senone); MixtureComponent[] mix = gaussian.getMixtureComponents(); for (int i = 0; i < mix.length; i++) { float[] mean = mix[i].getMean(); // int indexMean = meansPool.indexOf(mean); int indexMean = indexMap.get(mean); assert indexMean >= 0; assert indexMean == senone; Buffer buffer = meansBufferPool.get(indexMean); float[] feature = ((FloatData) score.getData()).getValues(); double[] data = new double[feature.length]; float prob = score.getComponentGamma()[i]; prob -= currentLogLikelihood; double dprob = logMath.logToLinear(prob); // prob = (float) logMath.logToLinear(prob); for (int j = 0; j < data.length; j++) { data[j] = feature[j] * dprob; } buffer.accumulate(data, dprob); } } }
/** Accumulate the variance. */ private void accumulateVariance(int senone, TrainerScore score) { if (senone == TrainerAcousticModel.ALL_MODELS) { for (int i = 0; i < senonePool.size(); i++) { accumulateVariance(i, score); } } else { GaussianMixture gaussian = (GaussianMixture)senonePool.get(senone); MixtureComponent[] mix = gaussian.getMixtureComponents(); for (int i = 0; i < mix.length; i++) { float[] mean = mix[i].getMean(); float[] variance = mix[i].getVariance(); // int indexVariance = variancePool.indexOf(variance); int indexVariance = indexMap.get(variance); Buffer buffer = varianceBufferPool.get(indexVariance); float[] feature = ((FloatData) score.getData()).getValues(); double[] data = new double[feature.length]; float prob = score.getComponentGamma()[i]; prob -= currentLogLikelihood; double dprob = logMath.logToLinear(prob); for (int j = 0; j < data.length; j++) { data[j] = (feature[j] - mean[j]); data[j] *= data[j] * dprob; } buffer.accumulate(data, dprob); } } }
lastFeature; feature = new FloatData (floatLastFeature.getValues(), floatLastFeature.getSampleRate(), floatLastFeature.getFirstSampleNumber());
featureVector = FloatData.toFloatData(feature).getValues(); mId = (int) ((HMMSearchState) token.getSearchState()).getHMMState().getMixtureId(); if (loader instanceof Sphinx3Loader && ((Sphinx3Loader) loader).hasTiedMixtures())