be.ac.ulg.montefiore.run.jahmm
Class Hmm<O extends Observation>

java.lang.Object
  extended by be.ac.ulg.montefiore.run.jahmm.Hmm<O>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Hmm<O extends Observation>
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Main Hmm class; it implements an Hidden Markov Model. An HMM is composed of:

Important objects extensively used with HMMs are Observations, observation sequences and set of observation sequences. An observation sequence is simply a List of Observations (in the right order, the i-th element of the vector being the i-th element of the sequence). A set of observation sequences is a List of such sequences.

See Also:
Serialized Form

Constructor Summary
  Hmm(double[] pi, double[][] a, java.util.List<? extends Opdf<O>> opdfs)
          Creates a new HMM.
protected Hmm(int nbStates)
          Creates a new HMM.
  Hmm(int nbStates, OpdfFactory<? extends Opdf<O>> opdfFactory)
          Creates a new HMM.
 
Method Summary
 Hmm<O> clone()
           
 double getAij(int i, int j)
          Returns the probability associated with the transition going from state i to state j (ai,j).
 Opdf<O> getOpdf(int stateNb)
          Returns the opdf associated with a given state.
 double getPi(int stateNb)
          Returns the pi value associated with a given state.
 double lnProbability(java.util.List<? extends O> oseq)
          Returns the neperian logarithm of observation sequence's probability given this HMM.
 int[] mostLikelyStateSequence(java.util.List<? extends O> oseq)
          Returns an array containing the most likely state sequence matching an observation sequence given this HMM.
 int nbStates()
          Returns the number of states of this HMM.
 double probability(java.util.List<? extends O> oseq)
          Returns the probability of an observation sequence given this HMM.
 double probability(java.util.List<? extends O> oseq, int[] sseq)
          Returns the probability of an observation sequence along a state sequence given this HMM.
 void setAij(int i, int j, double value)
          Sets the probability associated to the transition going from state i to state j (Ai,j).
 void setOpdf(int stateNb, Opdf<O> opdf)
          Sets the opdf associated with a given state.
 void setPi(int stateNb, double value)
          Sets the pi value associated with a given state.
 java.lang.String toString()
          Gives a description of this HMM.
 java.lang.String toString(java.text.NumberFormat nf)
          Gives a description of this HMM.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Hmm

public Hmm(int nbStates,
           OpdfFactory<? extends Opdf<O>> opdfFactory)
Creates a new HMM. Each state has the same pi value and the transition probabilities are all equal.

Parameters:
nbStates - The (strictly positive) number of states of the HMM.
opdfFactory - A pdf generator that is used to build the pdfs associated to each state.

Hmm

public Hmm(double[] pi,
           double[][] a,
           java.util.List<? extends Opdf<O>> opdfs)
Creates a new HMM. All the HMM parameters are given as arguments.

Parameters:
pi - The initial probability values. pi[i] is the initial probability of state i. This array is copied.
a - The state transition probability array. a[i][j] is the probability of going from state i to state j. This array is copied.
opdfs - The observation distributions. opdfs.get(i) is the observation distribution associated with state i. The distributions are not copied.

Hmm

protected Hmm(int nbStates)
Creates a new HMM. The parameters of the created HMM set to null specified and must be set using the appropriate methods.

Parameters:
nbStates - The (strictly positive) number of states of the HMM.
Method Detail

nbStates

public int nbStates()
Returns the number of states of this HMM.

Returns:
The number of states of this HMM.

getPi

public double getPi(int stateNb)
Returns the pi value associated with a given state.

Parameters:
stateNb - A state number such that 0 ≤ stateNb < nbStates()
Returns:
The pi value associated to stateNb.

setPi

public void setPi(int stateNb,
                  double value)
Sets the pi value associated with a given state.

Parameters:
stateNb - A state number such that 0 ≤ stateNb < nbStates().
value - The pi value to associate to state number stateNb

getOpdf

public Opdf<O> getOpdf(int stateNb)
Returns the opdf associated with a given state.

Parameters:
stateNb - A state number such that 0 ≤ stateNb < nbStates().
Returns:
The opdf associated to state stateNb.

setOpdf

public void setOpdf(int stateNb,
                    Opdf<O> opdf)
Sets the opdf associated with a given state.

Parameters:
stateNb - A state number such that 0 ≤ stateNb < nbStates().
opdf - An observation probability function.

getAij

public double getAij(int i,
                     int j)
Returns the probability associated with the transition going from state i to state j (ai,j).

Parameters:
i - The first state number such that 0 ≤ i < nbStates().
j - The second state number such that 0 ≤ j < nbStates().
Returns:
The probability associated to the transition going from i to state j.

setAij

public void setAij(int i,
                   int j,
                   double value)
Sets the probability associated to the transition going from state i to state j (Ai,j).

Parameters:
i - The first state number such that 0 ≤ i < nbStates().
j - The second state number such that 0 ≤ j < nbStates().
value - The value of Ai,j.

mostLikelyStateSequence

public int[] mostLikelyStateSequence(java.util.List<? extends O> oseq)
Returns an array containing the most likely state sequence matching an observation sequence given this HMM. This sequence I maximizes the probability of P[I|O,Model] where O is the observation sequence and Model this HMM model.

Parameters:
oseq - A non-empty observation sequence.
Returns:
An array containing the most likely sequence of state numbers. This array can be modified.

probability

public double probability(java.util.List<? extends O> oseq)
Returns the probability of an observation sequence given this HMM.

Parameters:
oseq - A non-empty observation sequence.
Returns:
The probability of this sequence.

lnProbability

public double lnProbability(java.util.List<? extends O> oseq)
Returns the neperian logarithm of observation sequence's probability given this HMM. A scaling procedure is used in order to avoid underflows when computing the probability of long sequences.

Parameters:
oseq - A non-empty observation sequence.
Returns:
The probability of this sequence.

probability

public double probability(java.util.List<? extends O> oseq,
                          int[] sseq)
Returns the probability of an observation sequence along a state sequence given this HMM.

Parameters:
oseq - A non-empty observation sequence.
sseq - An array containing a sequence of state numbers. The length of this array must be equal to the length of oseq
Returns:
The probability P[oseq,sseq|H], where H is this HMM.

toString

public java.lang.String toString(java.text.NumberFormat nf)
Gives a description of this HMM.

Parameters:
nf - A number formatter used to print numbers (e.g. Aij values).
Returns:
A textual description of this HMM.

toString

public java.lang.String toString()
Gives a description of this HMM.

Overrides:
toString in class java.lang.Object
Returns:
A textual description of this HMM.

clone

public Hmm<O> clone()
                                 throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException


Copyright © 2004,2005 Jean-Marc François.