Sautrela

edu.gtts.sautrela.wfsa.models
Class HMM

java.lang.Object
  extended by edu.gtts.sautrela.wfsa.models.HMM
All Implemented Interfaces:
NdWFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>, WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>

public class HMM
extends java.lang.Object
implements NdWFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>

Array version of Discrete Hidden Markov Model

Author:
mpenagar

Nested Class Summary
 class HMM.State
           
 class HMM.Symbol
           
 
Nested classes/interfaces inherited from interface edu.gtts.sautrela.wfsa.WFSA
WFSA.Factory
 
Field Summary
static WFSA.Factory myFactory
           
 
Constructor Summary
HMM(org.xml.sax.InputSource is)
          Creates a HMM using an XML description found via an InputSource
HMM(org.xml.sax.InputSource is, Alphabet<HMM.Symbol> alphabet)
          Creates a HMM using a XML description found via an InputSource and using an existing Alphabet.
 
Method Summary
 void dumpTrainCounts()
          Dumps the trained data to the HMM.
 Alphabet<HMM.Symbol> getAlphabet()
          Returns the alphabet of the Model.
 double getFinProb(HMM.State state)
          Returns the probability of being final
 HMM.State getIniState()
          Returns the initial State
 java.lang.String getName()
          Returns the name of the Model.
 DefaultTransition<HMM.State,HMM.Symbol> getRandomTrans(HMM.State state)
          Returns a random transitions from a state
 HMM.Symbol getSymbolByName(java.lang.String name)
           
 DefaultTransition<HMM.State,HMM.Symbol>[] getTrans(HMM.State from)
          Returns all possible transitions from a state.
 DefaultTransition<HMM.State,HMM.Symbol>[] getTrans(HMM.State from, HMM.Symbol symbol)
          Returns all possible transitions for the given source state and symbol.
 java.lang.Iterable<DefaultTransition<HMM.State,HMM.Symbol>> getTrans2(HMM.State state)
           
 java.lang.Iterable<DefaultTransition<HMM.State,HMM.Symbol>> getTrans2(HMM.State state, HMM.Symbol symbol)
           
 void incrementTrainCount(DefaultTransition<HMM.State,HMM.Symbol> t, double count)
          Increments the training counts associated to a Transition.
 void incrementTrainCount(HMM.State state, double count)
          Increments the training counts associated to a final state.
 void initTrainCounts(double initCount)
          Initializes the training counts.
 void setName(java.lang.String name)
          Sets the name of the HMM.
 java.lang.String toString()
          Returns a string representation of the object.
 java.lang.String toXML()
          Returns a XML representation of the HMM
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

myFactory

public static final WFSA.Factory myFactory
Constructor Detail

HMM

public HMM(org.xml.sax.InputSource is)
    throws javax.xml.parsers.ParserConfigurationException,
           org.xml.sax.SAXException,
           java.io.IOException
Creates a HMM using an XML description found via an InputSource

Parameters:
is - the InputSource used to locate the XML description
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException

HMM

public HMM(org.xml.sax.InputSource is,
           Alphabet<HMM.Symbol> alphabet)
    throws javax.xml.parsers.ParserConfigurationException,
           org.xml.sax.SAXException,
           java.io.IOException
Creates a HMM using a XML description found via an InputSource and using an existing Alphabet. The alphabet could grow.

Parameters:
is - the InputSource used to locate the XML description
alphabet - an existing Alphabet
Throws:
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException
Method Detail

setName

public void setName(java.lang.String name)
Sets the name of the HMM.

Parameters:
name - the name of this HMM

toString

public java.lang.String toString()
Returns a string representation of the object.

Overrides:
toString in class java.lang.Object
Returns:
A string representation of the object

getName

public java.lang.String getName()
Description copied from interface: WFSA
Returns the name of the Model.

Specified by:
getName in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Returns:
The name of the Model

getSymbolByName

public HMM.Symbol getSymbolByName(java.lang.String name)

getAlphabet

public Alphabet<HMM.Symbol> getAlphabet()
Description copied from interface: WFSA
Returns the alphabet of the Model.

Specified by:
getAlphabet in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Returns:
The Alphabet

getFinProb

public double getFinProb(HMM.State state)
Description copied from interface: WFSA
Returns the probability of being final

Specified by:
getFinProb in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Returns:
The probability of being final

getIniState

public HMM.State getIniState()
Description copied from interface: WFSA
Returns the initial State

Specified by:
getIniState in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Returns:
The initial state

getTrans

public DefaultTransition<HMM.State,HMM.Symbol>[] getTrans(HMM.State from)
Description copied from interface: WFSA
Returns all possible transitions from a state.

Specified by:
getTrans in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Parameters:
from - The source State
Returns:
an array containing all possible transitions from a state. If there is no transition, and empty array must be returned.

getRandomTrans

public DefaultTransition<HMM.State,HMM.Symbol> getRandomTrans(HMM.State state)
Description copied from interface: WFSA
Returns a random transitions from a state

Specified by:
getRandomTrans in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Parameters:
state - The source State
Returns:
a random transition

getTrans2

public java.lang.Iterable<DefaultTransition<HMM.State,HMM.Symbol>> getTrans2(HMM.State state)
                                                                      throws java.lang.UnsupportedOperationException
Throws:
java.lang.UnsupportedOperationException

getTrans2

public java.lang.Iterable<DefaultTransition<HMM.State,HMM.Symbol>> getTrans2(HMM.State state,
                                                                             HMM.Symbol symbol)
                                                                      throws java.lang.UnsupportedOperationException
Throws:
java.lang.UnsupportedOperationException

getTrans

public DefaultTransition<HMM.State,HMM.Symbol>[] getTrans(HMM.State from,
                                                          HMM.Symbol symbol)
Description copied from interface: NdWFSA
Returns all possible transitions for the given source state and symbol. The array should be ordered in descending probability (the most probable transition is the first and the less probable is the last).

Specified by:
getTrans in interface NdWFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Parameters:
from - the source State
symbol - the observed symbol
Returns:
an array containing all possible transitions. If there is no transition, an empty array must be returned.

initTrainCounts

public void initTrainCounts(double initCount)
Description copied from interface: WFSA
Initializes the training counts. Al previous counts are cleared and initCount is used as initial posterior probability count of the WFSA (MAP training). This count must be distributed among all the internal parameters according to their prior probabilities.

Specified by:
initTrainCounts in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Parameters:
initCount - initial posterior probability count

incrementTrainCount

public void incrementTrainCount(HMM.State state,
                                double count)
Description copied from interface: WFSA
Increments the training counts associated to a final state. These counts are related to the final probability of a State.

Specified by:
incrementTrainCount in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Parameters:
state - the final Sate
count - the training count.

incrementTrainCount

public void incrementTrainCount(DefaultTransition<HMM.State,HMM.Symbol> t,
                                double count)
Description copied from interface: WFSA
Increments the training counts associated to a Transition. These counts are related to the probability of a Transition.

Specified by:
incrementTrainCount in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>
Parameters:
t - the Transition
count - the training count.

dumpTrainCounts

public void dumpTrainCounts()
Dumps the trained data to the HMM. The Gopalakrishnan transformation

p'= (p * C + count) / Norma


is implemented using the value C=Max{(1-count)/prob,0} for each probability distribution. This constant ensures that the minimun probability (prior to normalization) will be 1.

Specified by:
dumpTrainCounts in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>

toXML

public java.lang.String toXML()
Returns a XML representation of the HMM

Specified by:
toXML in interface WFSA<HMM.State,HMM.Symbol,DefaultTransition<HMM.State,HMM.Symbol>>

Sautrela