Пример #1
0
            /**
             * /// Expands the given hmm state tree
             *
             * /// @param parent the parent of the tree
             * /// @param tree   the tree to expand
             * /// @return the final state in the tree
             */
            private HMMStateState ExpandHMMTree(UnitState parent, HMMStateState tree)
            {
                HMMStateState retState = tree;

                foreach (HmmStateArc arc in tree.HmmState.GetSuccessors())
                {
                    HMMStateState newState;
                    if (arc.HmmState.IsEmitting)
                    {
                        newState = new HMMStateState(parent, arc.HmmState);
                    }
                    else
                    {
                        newState = new NonEmittingHMMState(parent, arc.HmmState);
                    }
                    SentenceHMMState existingState = GetExistingState(newState);
                    float            logProb       = arc.LogProbability;
                    if (existingState != null)
                    {
                        AttachState(tree, existingState, LogOne, logProb);
                    }
                    else
                    {
                        AttachState(tree, newState, LogOne, logProb);
                        AddStateToCache(newState);
                        retState = ExpandHMMTree(parent, newState);
                    }
                }
                return(retState);
            }
        /**
         * /// Expands the given hmm state tree
         *
         * /// @param parent the parent of the tree
         * /// @param tree   the tree to expand
         * /// @return the final state in the tree
         */
        protected HMMStateState ExpandHMMTree(UnitState parent, HMMStateState tree)
        {
            var retState = tree;

            foreach (var arc in tree.HmmState.GetSuccessors())
            {
                HMMStateState newState;
                if (arc.HmmState.IsEmitting)
                {
                    newState = new HMMStateState(parent, arc.HmmState);
                }
                else
                {
                    newState = new NonEmittingHMMState(parent, arc.HmmState);
                }
                var existingState = GetExistingState(newState);
                var logProb       = arc.LogProbability;
                if (existingState != null)
                {
                    AttachState(tree, existingState, _parent.LogOne, logProb);
                }
                else
                {
                    AttachState(tree, newState, _parent.LogOne, logProb);
                    AddStateToCache(newState);
                    retState = ExpandHMMTree(parent, newState);
                }
            }
            return(retState);
        }
Пример #3
0
            /**
             * /// Given a unit state, return the set of sentence hmm states associated with the unit
             *
             * /// @param unitState the unit state of intereset
             * /// @return the hmm tree for the unit
             */
            private HMMStateState GetHMMStates(UnitState unitState)
            {
                HMMStateState hmmTree;
                HMMStateState finalState;
                Unit          unit         = unitState.Unit;
                HMMPosition   position     = unitState.GetPosition();
                IHMM          hmm          = _parent._acousticModel.LookupNearestHMM(unit, position, false);
                IHMMState     initialState = hmm.GetInitialState();

                hmmTree = new HMMStateState(unitState, initialState);
                AttachState(unitState, hmmTree, LogOne, LogOne);
                AddStateToCache(hmmTree);
                finalState = ExpandHMMTree(unitState, hmmTree);
                return(finalState);
            }
        /** Constructs a phone loop search graph. */
        public PhoneLoopSearchGraph(CIPhoneLoop parent)
        {
            _parent        = parent;
            ExistingStates = new Dictionary <string, ISearchState>();
            FirstState     = new UnknownWordState();
            SentenceHMMState branchState = new BranchOutState(FirstState);

            AttachState(FirstState, branchState, _parent.LogOne, _parent.LogOne);

            SentenceHMMState lastState = new LoopBackState(FirstState);

            lastState.SetFinalState(true);
            AttachState(lastState, branchState, _parent.LogOne, _parent.LogOne);

            for (var i = _parent.Model.GetContextIndependentUnitIterator(); i.MoveNext();)
            {
                var unitState = new UnitState(i.Current, HMMPosition.Undefined);
                var debug     = unitState.ToString();

                // attach unit state to the branch out state
                AttachState(branchState, unitState, _parent.LogOne, _parent.LogPhoneInsertionProbability);

                var hmm          = _parent.Model.LookupNearestHMM(unitState.Unit, unitState.GetPosition(), false);
                var initialState = hmm.GetInitialState();
                var hmmTree      = new HMMStateState(unitState, initialState);
                AddStateToCache(hmmTree);

                // attach first HMM state to the unit state
                AttachState(unitState, hmmTree, _parent.LogOne, _parent.LogOne);

                // expand the HMM tree
                var finalState = ExpandHMMTree(unitState, hmmTree);

                // attach final state of HMM tree to the loopback state
                AttachState(finalState, lastState, _parent.LogOne, _parent.LogOne);
            }
        }