org.apache.mahout.classifier.sequencelearning.hmm
Class HmmModel

java.lang.Object
  extended by org.apache.mahout.classifier.sequencelearning.hmm.HmmModel
All Implemented Interfaces:
com.google.gson.JsonDeserializer<HmmModel>, com.google.gson.JsonSerializer<HmmModel>, java.lang.Cloneable

public class HmmModel
extends java.lang.Object
implements com.google.gson.JsonDeserializer<HmmModel>, com.google.gson.JsonSerializer<HmmModel>, java.lang.Cloneable

Main class defining a Hidden Markov Model


Constructor Summary
HmmModel(int nrOfHiddenStates, int nrOfOutputStates)
          Construct a valid random Hidden-Markov parameter set with the given number of hidden and output states.
HmmModel(int nrOfHiddenStates, int nrOfOutputStates, long seed)
          Construct a valid random Hidden-Markov parameter set with the given number of hidden and output states using a given seed.
HmmModel(Matrix transitionMatrix, Matrix emissionMatrix, Vector initialProbabilities)
          Generates a Hidden Markov model using the specified parameters
 
Method Summary
 void assign(HmmModel model)
          Assign the content of another HMM model to this one
 HmmModel clone()
          Get a copy of this model
 HmmModel deserialize(com.google.gson.JsonElement json, java.lang.reflect.Type type, com.google.gson.JsonDeserializationContext context)
           
static HmmModel fromJson(java.lang.String json)
          Decode this HmmModel from a JSON string
 Matrix getEmissionMatrix()
          Getter function to get the output state probability matrix
 int getHiddenStateID(java.lang.String name)
          Lookup the ID for the given hidden state name
 java.lang.String getHiddenStateName(int id)
          Lookup the name for the given hidden state ID
 java.util.Map<java.lang.String,java.lang.Integer> getHiddenStateNames()
          Getter method for the hidden state Names map
 Vector getInitialProbabilities()
          Getter function to return the vector of initial hidden state probabilities
 int getNrOfHiddenStates()
          Getter Method for the number of hidden states
 int getNrOfOutputStates()
          Getter Method for the number of output states
 int getOutputStateID(java.lang.String name)
          Lookup the ID for the given output state name
 java.lang.String getOutputStateName(int id)
          Lookup the name for the given output state id
 java.util.Map<java.lang.String,java.lang.Integer> getOutputStateNames()
          Getter method for the output state Names map
 Matrix getTransitionMatrix()
          Getter function to get the hidden state transition matrix
 void registerHiddenStateNames(java.util.Map<java.lang.String,java.lang.Integer> stateNames)
          Register a map of hidden state Names/state IDs
 void registerHiddenStateNames(java.lang.String[] stateNames)
          Register an array of hidden state Names.
 void registerOutputStateNames(java.util.Map<java.lang.String,java.lang.Integer> stateNames)
          Register a map of hidden state Names/state IDs
 void registerOutputStateNames(java.lang.String[] stateNames)
          Register an array of hidden state Names.
 com.google.gson.JsonElement serialize(HmmModel model, java.lang.reflect.Type arg1, com.google.gson.JsonSerializationContext arg2)
           
 java.lang.String toJson()
          Encode this HMMmodel as a JSON string
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HmmModel

public HmmModel(int nrOfHiddenStates,
                int nrOfOutputStates,
                long seed)
Construct a valid random Hidden-Markov parameter set with the given number of hidden and output states using a given seed.

Parameters:
nrOfHiddenStates - Number of hidden states
nrOfOutputStates - Number of output states
seed - Seed for the random initialization, if set to 0 the current time is used

HmmModel

public HmmModel(int nrOfHiddenStates,
                int nrOfOutputStates)
Construct a valid random Hidden-Markov parameter set with the given number of hidden and output states.

Parameters:
nrOfHiddenStates - Number of hidden states
nrOfOutputStates - Number of output states

HmmModel

public HmmModel(Matrix transitionMatrix,
                Matrix emissionMatrix,
                Vector initialProbabilities)
Generates a Hidden Markov model using the specified parameters

Parameters:
transitionMatrix - transition probabilities.
emissionMatrix - emission probabilities.
initialProbabilities - initial start probabilities.
Throws:
java.lang.IllegalArgumentException - If the given parameter set is invalid
Method Detail

clone

public HmmModel clone()
               throws java.lang.CloneNotSupportedException
Get a copy of this model

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

assign

public void assign(HmmModel model)
Assign the content of another HMM model to this one

Parameters:
model - The HmmModel that will be assigned to this one

getNrOfHiddenStates

public int getNrOfHiddenStates()
Getter Method for the number of hidden states

Returns:
Number of hidden states

getNrOfOutputStates

public int getNrOfOutputStates()
Getter Method for the number of output states

Returns:
Number of output states

getTransitionMatrix

public Matrix getTransitionMatrix()
Getter function to get the hidden state transition matrix

Returns:
returns the model's transition matrix.

getEmissionMatrix

public Matrix getEmissionMatrix()
Getter function to get the output state probability matrix

Returns:
returns the models emission matrix.

getInitialProbabilities

public Vector getInitialProbabilities()
Getter function to return the vector of initial hidden state probabilities

Returns:
returns the model's init probabilities.

getHiddenStateNames

public java.util.Map<java.lang.String,java.lang.Integer> getHiddenStateNames()
Getter method for the hidden state Names map

Returns:
hidden state names.

registerHiddenStateNames

public void registerHiddenStateNames(java.lang.String[] stateNames)
Register an array of hidden state Names. We assume that the state name at position i has the ID i

Parameters:
stateNames - names of hidden states.

registerHiddenStateNames

public void registerHiddenStateNames(java.util.Map<java.lang.String,java.lang.Integer> stateNames)
Register a map of hidden state Names/state IDs

Parameters:
stateNames - Map that assigns each state name an integer ID

getHiddenStateName

public java.lang.String getHiddenStateName(int id)
Lookup the name for the given hidden state ID

Parameters:
id - Integer id of the hidden state
Returns:
String containing the name for the given ID, null if this ID is not known or no hidden state names were specified

getHiddenStateID

public int getHiddenStateID(java.lang.String name)
Lookup the ID for the given hidden state name

Parameters:
name - Name of the hidden state
Returns:
int containing the ID for the given name, -1 if this name is not known or no hidden state names were specified

getOutputStateNames

public java.util.Map<java.lang.String,java.lang.Integer> getOutputStateNames()
Getter method for the output state Names map

Returns:
names of output states.

registerOutputStateNames

public void registerOutputStateNames(java.lang.String[] stateNames)
Register an array of hidden state Names. We assume that the state name at position i has the ID i

Parameters:
stateNames - state names to register.

registerOutputStateNames

public void registerOutputStateNames(java.util.Map<java.lang.String,java.lang.Integer> stateNames)
Register a map of hidden state Names/state IDs

Parameters:
stateNames - Map that assigns each state name an integer ID

getOutputStateName

public java.lang.String getOutputStateName(int id)
Lookup the name for the given output state id

Parameters:
id - Integer id of the output state
Returns:
String containing the name for the given id, null if this id is not known or no output state names were specified

getOutputStateID

public int getOutputStateID(java.lang.String name)
Lookup the ID for the given output state name

Parameters:
name - Name of the output state
Returns:
int containing the ID for the given name, -1 if this name is not known or no output state names were specified

toJson

public java.lang.String toJson()
Encode this HMMmodel as a JSON string

Returns:
String containing the JSON of this model

fromJson

public static HmmModel fromJson(java.lang.String json)
Decode this HmmModel from a JSON string

Parameters:
json - String containing JSON representation of this model
Returns:
Initialized model

deserialize

public HmmModel deserialize(com.google.gson.JsonElement json,
                            java.lang.reflect.Type type,
                            com.google.gson.JsonDeserializationContext context)
Specified by:
deserialize in interface com.google.gson.JsonDeserializer<HmmModel>

serialize

public com.google.gson.JsonElement serialize(HmmModel model,
                                             java.lang.reflect.Type arg1,
                                             com.google.gson.JsonSerializationContext arg2)
Specified by:
serialize in interface com.google.gson.JsonSerializer<HmmModel>


Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.