예제 #1
0
        private void forwardPass(TrainerScore[] array)
        {
            for (int i = 0; i < this.graph.size(); i++)
            {
                this.outputProbs[i] = this.calculateScores(i);
                array[i]            = new TrainerScore(this.curFeature, this.outputProbs[i], (HMMState)this.graph.getNode(i).getObject(), this.componentScores);
                array[i].setAlpha(this.probCurrentFrame[i]);
            }
            float[] array2 = this.probCurrentFrame;
            this.probCurrentFrame = new float[this.graph.size()];
            int j;

            for (j = 0; j < this.graph.size(); j++)
            {
                Node node = this.graph.getNode(j);
                if (node.isType("STATE"))
                {
                    SenoneHMMState senoneHMMState = (SenoneHMMState)node.getObject();
                    SenoneHMM      senoneHMM      = (SenoneHMM)senoneHMMState.getHMM();
                    if (senoneHMMState.isEmitting())
                    {
                        this.probCurrentFrame[j] = float.MinValue;
                        node.startIncomingEdgeIterator();
                        while (node.hasMoreIncomingEdges())
                        {
                            Node     source   = node.nextIncomingEdge().getSource();
                            int      num      = this.graph.indexOf(source);
                            HMMState hmmstate = (HMMState)source.getObject();
                            float    num2;
                            if (hmmstate != null)
                            {
                                if (!BaumWelchLearner.assertionsDisabled && hmmstate.isEmitting() && hmmstate.getHMM() != senoneHMM)
                                {
                                    throw new AssertionError();
                                }
                                if (!hmmstate.isEmitting())
                                {
                                    num2 = 0f;
                                }
                                else
                                {
                                    num2 = senoneHMM.getTransitionProbability(hmmstate.getState(), senoneHMMState.getState());
                                }
                            }
                            else
                            {
                                num2 = 0f;
                            }
                            this.probCurrentFrame[j] = this.logMath.addAsLinear(this.probCurrentFrame[j], array2[num] + num2);
                        }
                        float[] array3 = this.probCurrentFrame;
                        int     num3   = j;
                        float[] array4 = array3;
                        array4[num3] += this.outputProbs[j];
                        array[j].setAlpha(this.probCurrentFrame[j]);
                    }
                }
            }
            j = 0;
            while (j < this.graph.size())
            {
                Node      node      = this.graph.getNode(j);
                HMMState  hmmstate2 = null;
                SenoneHMM senoneHMM = null;
                if (node.isType("STATE"))
                {
                    hmmstate2 = (HMMState)node.getObject();
                    senoneHMM = (SenoneHMM)hmmstate2.getHMM();
                    if (!hmmstate2.isEmitting())
                    {
                        goto IL_26F;
                    }
                }
                else
                {
                    if (!this.graph.isInitialNode(node))
                    {
                        goto IL_26F;
                    }
                    array[j].setAlpha(float.MinValue);
                    this.probCurrentFrame[j] = float.MinValue;
                }
IL_35D:
                j++;
                continue;
IL_26F:
                this.probCurrentFrame[j] = float.MinValue;
                node.startIncomingEdgeIterator();
                while (node.hasMoreIncomingEdges())
                {
                    Node  source2 = node.nextIncomingEdge().getSource();
                    int   num4    = this.graph.indexOf(source2);
                    float num5;
                    if (source2.isType("STATE"))
                    {
                        HMMState hmmstate3 = (HMMState)source2.getObject();
                        if (!BaumWelchLearner.assertionsDisabled && hmmstate3.isEmitting() && hmmstate3.getHMM() != senoneHMM)
                        {
                            throw new AssertionError();
                        }
                        if (!hmmstate3.isEmitting())
                        {
                            num5 = 0f;
                        }
                        else
                        {
                            num5 = senoneHMM.getTransitionProbability(hmmstate3.getState(), hmmstate2.getState());
                        }
                    }
                    else
                    {
                        num5 = 0f;
                    }
                    this.probCurrentFrame[j] = this.logMath.addAsLinear(this.probCurrentFrame[j], this.probCurrentFrame[num4] + num5);
                }
                array[j].setAlpha(this.probCurrentFrame[j]);
                goto IL_35D;
            }
        }
예제 #2
0
        private void backwardPass(TrainerScore[] array)
        {
            for (int i = 0; i < this.graph.size(); i++)
            {
                this.outputProbs[i] = array[i].getScore();
                array[i].setBeta(this.probCurrentFrame[i]);
            }
            float[] array2 = this.probCurrentFrame;
            this.probCurrentFrame = new float[this.graph.size()];
            int j;

            for (j = 0; j < this.graph.size(); j++)
            {
                Node node = this.graph.getNode(j);
                if (node.isType("STATE"))
                {
                    HMMState  hmmstate  = (HMMState)node.getObject();
                    SenoneHMM senoneHMM = (SenoneHMM)hmmstate.getHMM();
                    if (hmmstate.isEmitting())
                    {
                        this.probCurrentFrame[j] = float.MinValue;
                        node.startOutgoingEdgeIterator();
                        while (node.hasMoreOutgoingEdges())
                        {
                            Node     destination = node.nextOutgoingEdge().getDestination();
                            int      num         = this.graph.indexOf(destination);
                            HMMState hmmstate2   = (HMMState)destination.getObject();
                            float    num2;
                            if (hmmstate2 != null)
                            {
                                if (!BaumWelchLearner.assertionsDisabled && hmmstate2.isEmitting() && hmmstate2.getHMM() != senoneHMM)
                                {
                                    throw new AssertionError();
                                }
                                if (hmmstate2.getHMM() != senoneHMM)
                                {
                                    num2 = 0f;
                                }
                                else
                                {
                                    num2 = senoneHMM.getTransitionProbability(hmmstate.getState(), hmmstate2.getState());
                                }
                            }
                            else
                            {
                                num2 = 0f;
                            }
                            this.probCurrentFrame[j] = this.logMath.addAsLinear(this.probCurrentFrame[j], array2[num] + num2 + this.outputProbs[num]);
                        }
                        array[j].setBeta(this.probCurrentFrame[j]);
                    }
                }
            }
            j = this.graph.size() - 1;
            while (j >= 0)
            {
                Node     node     = this.graph.getNode(j);
                HMMState hmmstate = null;
                if (node.isType("STATE"))
                {
                    hmmstate = (HMMState)node.getObject();
                    if (!hmmstate.isEmitting())
                    {
                        goto IL_21A;
                    }
                }
                else
                {
                    if (!this.graph.isFinalNode(node))
                    {
                        goto IL_21A;
                    }
                    array[j].setBeta(float.MinValue);
                    this.probCurrentFrame[j] = float.MinValue;
                }
IL_2DE:
                j--;
                continue;
IL_21A:
                this.probCurrentFrame[j] = float.MinValue;
                node.startOutgoingEdgeIterator();
                while (node.hasMoreOutgoingEdges())
                {
                    Node  destination2 = node.nextOutgoingEdge().getDestination();
                    int   num3         = this.graph.indexOf(destination2);
                    float num4;
                    if (destination2.isType("STATE"))
                    {
                        HMMState hmmstate3 = (HMMState)destination2.getObject();
                        if (!BaumWelchLearner.assertionsDisabled && !hmmstate3.isEmitting() && hmmstate3 != hmmstate)
                        {
                            throw new AssertionError();
                        }
                        num4 = 0f;
                    }
                    else
                    {
                        num4 = 0f;
                    }
                    this.probCurrentFrame[j] = this.logMath.addAsLinear(this.probCurrentFrame[j], this.probCurrentFrame[num3] + num4);
                }
                array[j].setBeta(this.probCurrentFrame[j]);
                goto IL_2DE;
            }
        }