com.aliasi.hmm
Class AbstractHmm

java.lang.Object
  extended by com.aliasi.hmm.AbstractHmm
All Implemented Interfaces:
HiddenMarkovModel
Direct Known Subclasses:
AbstractHmmEstimator

public abstract class AbstractHmm
extends Object
implements HiddenMarkovModel

An AbstractHmm is an abstract implementation of a hidden Markov model which manages a symbol table and defines the basic methods in terms of the symbolic linear probability methods. Specifically, the following four methods must be implemented by subclasses:

Abstract Methods to Implement
startProb(String) endProb(String)
transitProb(String,String) emitProb(String,CharSequence)
For efficiency, the log- and identifier-based versions of these methods may also be overridden. The symbol table is provided to the constructor and managed by this class.

Since:
LingPipe2.1
Version:
2.2
Author:
Bob Carpenter

Constructor Summary
AbstractHmm(SymbolTable stateSymbolTable)
          Construct an HMM with the specified symbol table.
 
Method Summary
 boolean addState(String state)
          Adds the state with the specified name to this hidden Markov model.
 double emitLog2Prob(int stateId, CharSequence emission)
          Return the log (base 2) of the emission estimate.
 double emitLog2Prob(String state, CharSequence emission)
          Returns the log (base 2) of the emission estimate.
 double emitProb(int stateId, CharSequence emission)
          Return an estimate of the likelihood of the state with the specified identifier to emit the specified string.
abstract  double emitProb(String state, CharSequence emission)
          Returns an estimate the emission of the specified string by the state with the specified label.
 double endLog2Prob(int stateId)
          Returns the log (base 2) of the end probability for the state with the specified identifier.
 double endLog2Prob(String state)
          Returns the log (base 2) of the end probability for the specified state.
 double endProb(int stateId)
          Returns the end probability for the state with the specified identifier.
abstract  double endProb(String state)
          Returns the end probability for the specified state.
 double startLog2Prob(int stateId)
          Returns the log (base 2) of the start probability for the state with the specified identifier.
 double startLog2Prob(String state)
          Returns the log (base 2) of the start probability for the specified state.
 double startProb(int stateId)
          Returns the start probability for the state with the specified identifier.
abstract  double startProb(String state)
          Returns the start probability for the specified state.
 SymbolTable stateSymbolTable()
          Return the symbol table for the states for this HMM.
 double transitLog2Prob(int sourceId, int targetId)
          Returns the log (base 2) of the transition estimate.
 double transitLog2Prob(String source, String target)
          Returns the log (base 2) estimate of a transition probability.
 double transitProb(int sourceId, int targetId)
          Return an estimate of the transition likelihood from the source state with the specified identifier to the target state with the specified identifier.
abstract  double transitProb(String source, String target)
          Returns an estimate of a transition from the source state with the specified name to the target state with the specified label.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHmm

public AbstractHmm(SymbolTable stateSymbolTable)
Construct an HMM with the specified symbol table.

Parameters:
stateSymbolTable - Symbol table for the HMM.
Method Detail

addState

public boolean addState(String state)
Adds the state with the specified name to this hidden Markov model.

Parameters:
state - Name of state to add.
Returns:
true if the state was not already a state in this HMM.

stateSymbolTable

public SymbolTable stateSymbolTable()
Return the symbol table for the states for this HMM. This is the actual symbol table used by this HMM and changes to it affect this HMM.

Specified by:
stateSymbolTable in interface HiddenMarkovModel
Returns:
The symbol table for the states for this HMM.

startProb

public abstract double startProb(String state)
Returns the start probability for the specified state.

Specified by:
startProb in interface HiddenMarkovModel
Parameters:
state - HMM state.
Returns:
Start probability of specified state.

startProb

public double startProb(int stateId)
Returns the start probability for the state with the specified identifier.

This method is implemented in terms of stateSymbolTable() and startProb(String).

Specified by:
startProb in interface HiddenMarkovModel
Parameters:
stateId - Identifier of state.
Returns:
Start probability of state with specified identifier.

startLog2Prob

public double startLog2Prob(String state)
Returns the log (base 2) of the start probability for the specified state.

This method is implemented in terms of Math.log2(double) and startProb(String).

Specified by:
startLog2Prob in interface HiddenMarkovModel
Parameters:
state - HMM State.
Returns:
Log start probability of state.

startLog2Prob

public double startLog2Prob(int stateId)
Returns the log (base 2) of the start probability for the state with the specified identifier.

This method is implemented in terms of Math.log2(double) and startProb(int).

Specified by:
startLog2Prob in interface HiddenMarkovModel
Parameters:
stateId - Identifier of state.
Returns:
Start probability of state with specified identifier.

endProb

public abstract double endProb(String state)
Returns the end probability for the specified state.

Specified by:
endProb in interface HiddenMarkovModel
Parameters:
state - HMM state.
Returns:
End probability of specified state.

endProb

public double endProb(int stateId)
Returns the end probability for the state with the specified identifier.

This method is implemented with stateSymbolTable() and and endProb(String).

Specified by:
endProb in interface HiddenMarkovModel
Parameters:
stateId - Identifier of state.
Returns:
End probability of state with specified identifier.

endLog2Prob

public double endLog2Prob(String state)
Returns the log (base 2) of the end probability for the specified state.

This method is implemented in terms of Math.log2(double) and endProb(String)

Specified by:
endLog2Prob in interface HiddenMarkovModel
Parameters:
state - HMM State.
Returns:
Log end probability of state.

endLog2Prob

public double endLog2Prob(int stateId)
Returns the log (base 2) of the end probability for the state with the specified identifier.

This method is implemented in terms of Math.log2(double) and endProb(int)

Specified by:
endLog2Prob in interface HiddenMarkovModel
Parameters:
stateId - Identifier of state.
Returns:
End probability of state with specified identifier.

transitProb

public abstract double transitProb(String source,
                                   String target)
Returns an estimate of a transition from the source state with the specified name to the target state with the specified label.

Specified by:
transitProb in interface HiddenMarkovModel
Parameters:
source - Label of source state.
target - Label of target state.
Returns:
Estimate of likelihood of transition from the source to the target state.

transitProb

public double transitProb(int sourceId,
                          int targetId)
Return an estimate of the transition likelihood from the source state with the specified identifier to the target state with the specified identifier.

This method is implemented in terms of stateSymbolTable() and transitProb(String,String).

Specified by:
transitProb in interface HiddenMarkovModel
Parameters:
sourceId - Source state identifier.
targetId - Target state identifier.
Returns:
Estimate of the transition probability.

transitLog2Prob

public double transitLog2Prob(String source,
                              String target)
Returns the log (base 2) estimate of a transition probability. See transitProb(String,String) for more information.

This method is implemented in terms of Math.log2(double) and transitProb(String,String).

Specified by:
transitLog2Prob in interface HiddenMarkovModel
Parameters:
source - Label of source state.
target - Label of target state.
Returns:
Log (base 2) Estimate of likelihood of transition from the source to the target state.

transitLog2Prob

public double transitLog2Prob(int sourceId,
                              int targetId)
Returns the log (base 2) of the transition estimate. See transitProb(int,int) for more information.

This method is implemented in terms of Math.log2(double) and transitProb(int,int)

Specified by:
transitLog2Prob in interface HiddenMarkovModel
Parameters:
sourceId - Source state identifier.
targetId - Target state identifier.
Returns:
Estimate of the transition probability.

emitProb

public abstract double emitProb(String state,
                                CharSequence emission)
Returns an estimate the emission of the specified string by the state with the specified label.

Specified by:
emitProb in interface HiddenMarkovModel
Parameters:
state - Label of state.
emission - Character sequence emitted.
Returns:
Estimate of likelihood of the state emitting the string.

emitProb

public double emitProb(int stateId,
                       CharSequence emission)
Return an estimate of the likelihood of the state with the specified identifier to emit the specified string.

This method is implemented in terms of emitProb(String,CharSequence).

Specified by:
emitProb in interface HiddenMarkovModel
Parameters:
stateId - State identifier.
emission - Character sequence emitted.
Returns:
Estimate of probability of the specified state emitting the specified string.

emitLog2Prob

public double emitLog2Prob(int stateId,
                           CharSequence emission)
Return the log (base 2) of the emission estimate. See emitProb(int,CharSequence) for more details.

This method is implemented in terms of Math.log2(double) and emitProb(int,CharSequence).

Specified by:
emitLog2Prob in interface HiddenMarkovModel
Parameters:
stateId - State identifier.
emission - Character sequence emitted.
Returns:
Log (base 2) estimate of probability of the specified state emitting the specified string.

emitLog2Prob

public double emitLog2Prob(String state,
                           CharSequence emission)
Returns the log (base 2) of the emission estimate. See emitProb(String,CharSequence) for more information.

This method is implemented in terms of Math.log2(double) and emitProb(String,CharSequence).

Specified by:
emitLog2Prob in interface HiddenMarkovModel
Parameters:
state - Label of state.
emission - Character sequence emitted.
Returns:
Log (base 2) estimate of likelihood of the state emitting the string.