예제 #1
0
        public virtual void updateTopScores(Data feature)
        {
            if (feature is DoubleData)
            {
                java.lang.System.err.println("DoubleData conversion required on mixture level!");
            }
            long firstSampleNumber = FloatData.toFloatData(feature).getFirstSampleNumber();

            if (this.toStoreScore)
            {
                this.curScores = this.getStoredScores(firstSampleNumber);
            }
            else if (this.curScores != null && this.curScores.getFrameStartSample() != firstSampleNumber)
            {
                this.curScores = null;
            }
            if (this.curScores != null)
            {
                return;
            }
            float[] values = FloatData.toFloatData(feature).getValues();
            this.updateTopScores(values);
            this.curScores = this.createFromTopGau(firstSampleNumber);
            if (this.toStoreScore)
            {
                this.storeScores(this.curScores);
            }
        }
예제 #2
0
 public override float[] calculateComponentScore(Data feature)
 {
     if (feature is DoubleData)
     {
         java.lang.System.err.println("DoubleData conversion required on mixture level!");
     }
     float[] values = FloatData.toFloatData(feature).getValues();
     float[] array  = new float[this.mixtureComponents.Length];
     for (int i = 0; i < this.mixtureComponents.Length; i++)
     {
         array[i] = this.mixtureComponents[i].getScore(values) + this.mixtureWeights.get(this.id, 0, i);
     }
     return(array);
 }
예제 #3
0
        protected internal override float calculateScore(Data feature)
        {
            if (feature is DoubleData)
            {
                java.lang.System.err.println("DoubleData conversion required on mixture level!");
            }
            float[] values = FloatData.toFloatData(feature).getValues();
            float   num    = float.MinValue;

            for (int i = 0; i < this.mixtureComponents.Length; i++)
            {
                num = this.logMath.addAsLinear(num, this.mixtureComponents[i].getScore(values) + this.mixtureWeights.get(this.id, 0, i));
            }
            return(num);
        }
예제 #4
0
        public virtual void updateScores(Data feature)
        {
            if (feature is DoubleData)
            {
                java.lang.System.err.println("DoubleData conversion required on mixture level!");
            }
            long firstSampleNumber = FloatData.toFloatData(feature).getFirstSampleNumber();

            if (this.gauCalcSampleNumber != firstSampleNumber)
            {
                float[] values = FloatData.toFloatData(feature).getValues();
                this.updateScores(values);
                this.gauCalcSampleNumber = firstSampleNumber;
            }
        }
예제 #5
0
        public override float[] calculateComponentScore(Data data)
        {
            float[] values = FloatData.toFloatData(data).getValues();
            int     num    = this.meansInvVars.Length;
            int     num2   = this.gconsts.Length;
            int     num3   = (num2 != -1) ? (num / num2) : (-num);

            if (values.Length != num3)
            {
                string text  = "feature vector must be of length %d, got %d";
                string text2 = String.format(text, new object[]
                {
                    Integer.valueOf(num3),
                    Integer.valueOf(values.Length)
                });
                string text3 = text2;

                throw new IllegalArgumentException(text3);
            }
            float[] array = Arrays.copyOf(this.gconsts, this.gconsts.Length);
            for (int i = 0; i < array.Length; i++)
            {
                for (int j = 0; j < values.Length; j++)
                {
                    int     num4   = i * values.Length + j;
                    float[] array2 = array;
                    int     num5   = i;
                    float[] array3 = array2;
                    array3[num5] += this.meansInvVars[num4] * values[j];
                    float[] array4 = array;
                    num5          = i;
                    array3        = array4;
                    array3[num5] -= 0.5f * this.invVars[num4] * values[j] * values[j];
                }
                array[i] = LogMath.getLogMath().lnToLog(array[i]);
            }
            return(array);
        }
예제 #6
0
        public void collect(SpeechResult result)
        {
            Token token = result.getResult().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.getData();
                ISearchState ss      = token.getSearchState();

                if (!(ss is IHMMSearchState && ss.isEmitting()))
                {
                    token = token.getPredecessor();
                    continue;
                }

                componentScore = token.calculateComponentScore(feature);
                featureVector  = FloatData.toFloatData(feature).getValues();
                mId            = (int)((IHMMSearchState)token.getSearchState()).getHMMState()
                                 .getMixtureId();
                if (loader is Sphinx3Loader && ((Sphinx3Loader)loader).hasTiedMixtures())
                {
                    // use CI phone ID for tied mixture model
                    mId = ((Sphinx3Loader)loader).getSenone2Ci()[mId];
                }
                len         = loader.getVectorLength();
                numStreams  = loader.getNumStreams();
                gauPerState = loader.getNumGaussiansPerState();
                posteriors  = this.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.getMeansPool().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.getVariancePool().get(
                                    mId * numStreams * gauPerState + i
                                    * gauPerState + j)[k];
                                wtDcountVar = dnom
                                              * loader.getVariancePool().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.getPredecessor();
            } while (token != null);
        }
예제 #7
0
        public virtual void collect(SpeechResult result)
        {
            Token token = result.getResult().getBestToken();

            if (token == null)
            {
                string text = "Best token not found!";

                throw new Exception(text);
            }
            do
            {
                FloatData   floatData   = (FloatData)token.getData();
                SearchState searchState = token.getSearchState();
                if (!(searchState is HMMSearchState) || !searchState.isEmitting())
                {
                    token = token.getPredecessor();
                }
                else
                {
                    this.nFrames++;
                    float[] array  = token.calculateComponentScore(floatData);
                    float[] values = FloatData.toFloatData(floatData).getValues();
                    int     num    = (int)((HMMSearchState)token.getSearchState()).getHMMState().getMixtureId();
                    if (this.loader is Sphinx3Loader && this.loader.hasTiedMixtures())
                    {
                        num = this.loader.getSenone2Ci()[num];
                    }
                    int[]   vectorLength         = this.loader.getVectorLength();
                    int     numStreams           = this.loader.getNumStreams();
                    int     numGaussiansPerState = this.loader.getNumGaussiansPerState();
                    float[] array2 = this.computePosterios(array, numStreams);
                    int     num2   = 0;
                    for (int i = 0; i < numStreams; i++)
                    {
                        for (int j = 0; j < numGaussiansPerState; j++)
                        {
                            int   classIndex = this.means.getClassIndex(num * numStreams * numGaussiansPerState + i * numGaussiansPerState + j);
                            float num3       = array2[i * numGaussiansPerState + j];
                            if ((double)num3 > (double)0f)
                            {
                                float[] array3 = (float[])this.loader.getMeansPool().get(num * numStreams * numGaussiansPerState + i * numGaussiansPerState + j);
                                for (int k = 0; k < vectorLength[i]; k++)
                                {
                                    float    num4 = array2[i * numGaussiansPerState + j] * values[k + num2];
                                    float    num5 = num4 * ((float[])this.loader.getVariancePool().get(num * numStreams * numGaussiansPerState + i * numGaussiansPerState + j))[k];
                                    float    num6 = num3 * ((float[])this.loader.getVariancePool().get(num * numStreams * numGaussiansPerState + i * numGaussiansPerState + j))[k];
                                    int      num8;
                                    double[] array5;
                                    for (int l = 0; l < vectorLength[i]; l++)
                                    {
                                        float num7 = num6 * array3[l];
                                        for (int m = l; m < vectorLength[i]; m++)
                                        {
                                            double[] array4 = this.regLs[classIndex][i][k][l];
                                            num8          = m;
                                            array5        = array4;
                                            array5[num8] += (double)(num7 * array3[m]);
                                        }
                                        double[] array6 = this.regLs[classIndex][i][k][l];
                                        num8          = vectorLength[i];
                                        array5        = array6;
                                        array5[num8] += (double)num7;
                                        double[] array7 = this.regRs[classIndex][i][k];
                                        num8          = l;
                                        array5        = array7;
                                        array5[num8] += (double)(num5 * array3[l]);
                                    }
                                    double[] array8 = this.regLs[classIndex][i][k][vectorLength[i]];
                                    num8          = vectorLength[i];
                                    array5        = array8;
                                    array5[num8] += (double)num6;
                                    double[] array9 = this.regRs[classIndex][i][k];
                                    num8          = vectorLength[i];
                                    array5        = array9;
                                    array5[num8] += (double)num5;
                                }
                            }
                        }
                        num2 += vectorLength[i];
                    }
                    token = token.getPredecessor();
                }
            }while (token != null);
        }