Ejemplo n.º 1
0
        public virtual TrainerScore[] getScore()
        {
            if (this.scoreArray == null)
            {
                this.scoreArray          = this.prepareScore();
                this.currentFeatureIndex = this.lastFeatureIndex;
            }
            this.currentFeatureIndex--;
            if (this.currentFeatureIndex < 0)
            {
                this.scoreArray = (TrainerScore[][])null;
                return(null);
            }
            float num = float.MinValue;

            TrainerScore[] array = this.scoreArray[this.currentFeatureIndex];
            if (!BaumWelchLearner.assertionsDisabled && array.Length != this.betas.Length)
            {
                throw new AssertionError();
            }
            this.backwardPass(array);
            for (int i = 0; i < this.betas.Length; i++)
            {
                array[i].setGamma();
                num = this.logMath.addAsLinear(num, array[i].getGamma());
            }
            if (this.currentFeatureIndex == this.lastFeatureIndex - 1)
            {
                TrainerScore.setLogLikelihood(num);
                this.totalLogScore = num;
            }
            else if (Math.abs(this.totalLogScore - num) > Math.abs(this.totalLogScore))
            {
                [email protected](new StringBuilder().append("WARNING: log probabilities differ: ").append(this.totalLogScore).append(" and ").append(num).toString());
            }
            return(array);
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        private TrainerScore[][] prepareScore()
        {
            ArrayList arrayList = new ArrayList();
            int       num       = this.graph.size();

            TrainerScore[] array = new TrainerScore[num];
            this.betas            = new float[num];
            this.outputProbs      = new float[num];
            this.probCurrentFrame = new float[num];
            Node initialNode = this.graph.getInitialNode();
            int  num2        = this.graph.indexOf(initialNode);

            for (int i = 0; i < num; i++)
            {
                this.probCurrentFrame[i] = float.MinValue;
            }
            this.probCurrentFrame[num2] = 0f;
            initialNode.startOutgoingEdgeIterator();
            while (initialNode.hasMoreOutgoingEdges())
            {
                Edge edge        = initialNode.nextOutgoingEdge();
                Node destination = edge.getDestination();
                int  num3        = this.graph.indexOf(destination);
                if (!destination.isType("STATE"))
                {
                    this.probCurrentFrame[num3] = 0f;
                }
                else
                {
                    HMMState hmmstate = (HMMState)destination.getObject();
                    if (!hmmstate.isEmitting())
                    {
                        this.probCurrentFrame[num3] = 0f;
                    }
                    if (!BaumWelchLearner.assertionsDisabled)
                    {
                        throw new AssertionError();
                    }
                }
            }
            this.lastFeatureIndex = 0;
            while (this.getFeature())
            {
                this.forwardPass(array);
                arrayList.add(array);
                this.lastFeatureIndex++;
            }
            BaumWelchLearner.logger.info(new StringBuilder().append("Feature frames read: ").append(this.lastFeatureIndex).toString());
            for (int i = 0; i < this.probCurrentFrame.Length; i++)
            {
                this.probCurrentFrame[i] = float.MinValue;
            }
            Node finalNode = this.graph.getFinalNode();
            int  num4      = this.graph.indexOf(finalNode);

            this.probCurrentFrame[num4] = 0f;
            finalNode.startIncomingEdgeIterator();
            while (finalNode.hasMoreIncomingEdges())
            {
                Edge edge2  = finalNode.nextIncomingEdge();
                Node source = edge2.getSource();
                int  num5   = this.graph.indexOf(source);
                if (!source.isType("STATE"))
                {
                    this.probCurrentFrame[num5] = 0f;
                    if (!BaumWelchLearner.assertionsDisabled)
                    {
                        throw new AssertionError();
                    }
                }
                else
                {
                    HMMState hmmstate2 = (HMMState)source.getObject();
                    if (!hmmstate2.isEmitting())
                    {
                        this.probCurrentFrame[num5] = 0f;
                    }
                }
            }
            return((TrainerScore[][])arrayList.toArray(new TrainerScore[arrayList.size()][]));
        }