public TrainerScore(Data feature, float probability, HMMState state, float logAlpha, float logBeta, float[] logComponentProb)
		{
			this.feature = feature;
			this.hmmState = state;
			this.logScalingFactor = 0f;
			if (state != null && state.isEmitting())
			{
				int i = state.getState();
				SenoneHMM senoneHMM = (SenoneHMM)state.getHMM();
				SenoneSequence senoneSequence = senoneHMM.getSenoneSequence();
				this.senone = senoneSequence.getSenones()[i];
			}
			this.logOutputProbability = probability;
			this.logAlpha = logAlpha;
			this.logBeta = logBeta;
			this.logGamma = logAlpha + logBeta;
			if (logComponentProb != null)
			{
				this.logComponentProb = new float[logComponentProb.Length];
				this.logComponentGamma = new float[logComponentProb.Length];
				for (int i = 0; i < logComponentProb.Length; i++)
				{
					this.logComponentProb[i] = logComponentProb[i];
					this.logComponentGamma[i] = logComponentProb[i] + this.logGamma;
				}
			}
			else
			{
				this.logComponentProb = null;
				this.logComponentGamma = null;
			}
		}
 public PhoneHmmSearchState(HMMState hmmState, AllphoneLinguist linguist, float insertionProb, float languageProb)
 {
     this.state         = hmmState;
     this.linguist      = linguist;
     this.insertionProb = insertionProb;
     this.languageProb  = languageProb;
 }
Example #3
0
            public PhoneLoopSearchGraph(CIPhoneLoop this_0)
            {
                this.this_0           = this_0;
                this.__existingStates = new HashMap();
                this.__firstState     = new UnknownWordState();
                BranchOutState branchOutState = new BranchOutState(this.__firstState);

                this.attachState(this.__firstState, branchOutState, 0f, 0f);
                LoopBackState loopBackState = new LoopBackState(this.__firstState);

                loopBackState.setFinalState(true);
                this.attachState(loopBackState, branchOutState, 0f, 0f);
                Iterator contextIndependentUnitIterator = this_0.__model.getContextIndependentUnitIterator();

                while (contextIndependentUnitIterator.hasNext())
                {
                    UnitState unitState = new UnitState((Unit)contextIndependentUnitIterator.next(), HMMPosition.__UNDEFINED);
                    this.attachState(branchOutState, unitState, 0f, CIPhoneLoop.access_000(this_0));
                    HMM           hmm           = this_0.__model.lookupNearestHMM(unitState.getUnit(), unitState.getPosition(), false);
                    HMMState      initialState  = hmm.getInitialState();
                    HMMStateState hmmstateState = new HMMStateState(unitState, initialState);
                    this.addStateToCache(hmmstateState);
                    this.attachState(unitState, hmmstateState, 0f, 0f);
                    HMMStateState prevState = this.expandHMMTree(unitState, hmmstateState);
                    this.attachState(prevState, loopBackState, 0f, 0f);
                }
            }
Example #4
0
            private HMMStateState getHMMStates(UnitState unitState)
            {
                Unit          unit          = unitState.getUnit();
                HMMPosition   position      = unitState.getPosition();
                HMM           hmm           = FlatLinguist.access_700(this.this_0).lookupNearestHMM(unit, position, false);
                HMMState      initialState  = hmm.getInitialState();
                HMMStateState hmmstateState = new HMMStateState(unitState, initialState);

                this.attachState(unitState, hmmstateState, 0f, 0f);
                this.addStateToCache(hmmstateState);
                return(this.expandHMMTree(unitState, hmmstateState));
            }
Example #5
0
        /** Constructs a phone loop search graph. */
        public PhoneLoopSearchGraph(SentenceHMMState initState, AcousticModel model, float logPhoneInsertionProbability)
        {
            this.inititalState = initState;
            this.model         = model;
            this.logPhoneInsertionProbability = logPhoneInsertionProbability;
            existingStates = new Dictionary <string, SearchState>();
            firstState     = new UnknownWordState();
            SentenceHMMState branchState = new BranchOutState(firstState);

            attachState(firstState, branchState, logOne, logOne);

            SentenceHMMState lastState = new LoopBackState(firstState);

            //lastState.setFinalState(true);
            //attachState(lastState, branchState, LogMath.getLogZero(),
            //		LogMath.getLogZero());
            attachState(lastState, inititalState, logOne, logOne);

            for (java.util.Iterator i = model.getContextIndependentUnitIterator(); i.hasNext();)
            {
                Unit      unit      = (Unit)i.next();
                UnitState unitState = new UnitState(unit, HMMPosition.UNDEFINED);

                // attach unit state to the branch out state
                attachState(branchState, unitState, logOne, logPhoneInsertionProbability);

                HMM hmm = model.lookupNearestHMM
                              (unitState.getUnit(), unitState.getPosition(), false);
                HMMState      initialState = hmm.getInitialState();
                HMMStateState hmmTree      = new HMMStateState(unitState, initialState);
                addStateToCache(hmmTree);

                // attach first HMM state to the unit state
                attachState(unitState, hmmTree, logOne, logOne);

                // expand the HMM tree
                HMMStateState finalState = expandHMMTree(unitState, hmmTree);

                // attach final state of HMM tree to the loopback state
                attachState(finalState, lastState, logOne, logOne);
            }
        }
Example #6
0
        private void accumulateStateTransition(int num, TrainerScore[] array, TrainerScore[] array2)
        {
            HMMState state = array[num].getState();

            if (state == null)
            {
                return;
            }
            int       state2    = state.getState();
            SenoneHMM senoneHMM = (SenoneHMM)state.getHMM();

            float[][] transitionMatrix = senoneHMM.getTransitionMatrix();
            int       id = ((Integer)this.indexMap.get(transitionMatrix)).intValue();

            Buffer[] array3 = (Buffer[])this.matrixBufferPool.get(id);
            float[]  array4 = transitionMatrix[state2];
            for (int i = 0; i < array4.Length; i++)
            {
                if (array4[i] != -3.40282347E+38f)
                {
                    int num2 = i - state2;
                    int num3 = num + num2;
                    if (!HMMPoolManager.assertionsDisabled && array2[num3].getState() != null && array2[num3].getState().getHMM() != senoneHMM)
                    {
                        throw new AssertionError();
                    }
                    float alpha = array[num].getAlpha();
                    float beta  = array2[num3].getBeta();
                    float num4  = array4[i];
                    float score = array2[num3].getScore();
                    float num5  = alpha + beta + num4 + score;
                    num5 -= this.currentLogLikelihood;
                    array3[state2].logAccumulate(num5, i, this.logMath);
                }
            }
        }
Example #7
0
 internal HMMStateSearchState(DynamicFlatLinguist dynamicFlatLinguist, DynamicFlatLinguist.FullHMMSearchState fullHMMSearchState, HMMState hmmstate) : this(dynamicFlatLinguist, fullHMMSearchState, hmmstate, 0f)
 {
 }
 public HMMStateState(SentenceHMMState parent, HMMState hmmState) : base("S", parent, hmmState.getState())
 {
     this.hmmState    = hmmState;
     this._isEmitting = hmmState.isEmitting();
 }
        public virtual SearchState getInitialState()
        {
            HMMState initialState = this.linguist.getAcousticModel().lookupNearestHMM(UnitManager.__SILENCE, HMMPosition.__UNDEFINED, true).getInitialState();

            return(new PhoneHmmSearchState(initialState, this.linguist, 0f, 0f));
        }
Example #10
0
 internal OogHMMState(PhoneLoop phoneLoop, HMMState hmmstate, float num) : base(phoneLoop)
 {
     this.hmmState       = hmmstate;
     this.logProbability = num;
 }
Example #11
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;
            }
        }
Example #12
0
 internal HMMStateSearchState(AFlatLinguist aflatLinguist, AFlatLinguist.FullHMMSearchState fullHMMSearchState, HMMState hmmstate) : this(aflatLinguist, fullHMMSearchState, hmmstate, 0f)
 {
 }
Example #13
0
 public HMMStateArc(HMMState hmmState, float probability)
 {
     this.hmmState    = hmmState;
     this.probability = probability;
 }
Example #14
0
 internal OogHMMState(OutOfGrammarGraph outOfGrammarGraph, HMMState hmmstate, float num) : base(outOfGrammarGraph)
 {
     this.hmmState       = hmmstate;
     this.logProbability = num;
 }
 public NonEmittingHMMState(SentenceHMMState parent, HMMState hmmState) : base(parent, hmmState)
 {
 }
Example #16
0
 internal HMMStateSearchState(DynamicFlatLinguist dynamicFlatLinguist, DynamicFlatLinguist.FullHMMSearchState fullHMMSearchState, HMMState hmmstate, float num) : base(dynamicFlatLinguist)
 {
     this.probability        = num;
     this.fullHMMSearchState = fullHMMSearchState;
     this.hmmState           = hmmstate;
 }
		public TrainerScore(Data feature, float probability, HMMState state) : this(feature, probability, state, 0f, 0f, null)
		{
		}
Example #18
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()][]));
        }
		public TrainerScore(Data feature, float probability, HMMState state, float[] logComponentProb) : this(feature, probability, state, 0f, 0f, logComponentProb)
		{
		}
Example #20
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;
            }
        }