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

java.lang.Object
  extended by org.apache.mahout.classifier.sequencelearning.hmm.HmmEvaluator

public final class HmmEvaluator
extends Object

The HMMEvaluator class offers several methods to evaluate an HMM Model. The following use-cases are covered: 1) Generate a sequence of output states from a given model (prediction). 2) Compute the likelihood that a given model generated a given sequence of output states (model likelihood). 3) Compute the most likely hidden sequence for a given model and a given observed sequence (decoding).


Method Summary
static int[] decode(HmmModel model, int[] observations, boolean scaled)
          Returns the most likely sequence of hidden states for the given model and observation
static double modelLikelihood(HmmModel model, int[] outputSequence, boolean scaled)
          Returns the likelihood that a given output sequence was produced by the given model.
static double modelLikelihood(HmmModel model, int[] outputSequence, Matrix beta, boolean scaled)
          Computes the likelihood that a given output sequence was computed by a given model.
static double modelLikelihood(Matrix alpha, boolean scaled)
          Computes the likelihood that a given output sequence was computed by a given model using the alpha values computed by the forward algorithm.
static int[] predict(HmmModel model, int steps)
          Predict a sequence of steps output states for the given HMM model
static int[] predict(HmmModel model, int steps, long seed)
          Predict a sequence of steps output states for the given HMM model
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

predict

public static int[] predict(HmmModel model,
                            int steps)
Predict a sequence of steps output states for the given HMM model

Parameters:
model - The Hidden Markov model used to generate the output sequence
steps - Size of the generated output sequence
Returns:
integer array containing a sequence of steps output state IDs, generated by the specified model

predict

public static int[] predict(HmmModel model,
                            int steps,
                            long seed)
Predict a sequence of steps output states for the given HMM model

Parameters:
model - The Hidden Markov model used to generate the output sequence
steps - Size of the generated output sequence
seed - seed to use for the RNG
Returns:
integer array containing a sequence of steps output state IDs, generated by the specified model

modelLikelihood

public static double modelLikelihood(HmmModel model,
                                     int[] outputSequence,
                                     boolean scaled)
Returns the likelihood that a given output sequence was produced by the given model. Internally, this function calls the forward algorithm to compute the alpha values and then uses the overloaded function to compute the actual model likelihood.

Parameters:
model - Model to base the likelihood on.
outputSequence - Sequence to compute likelihood for.
scaled - Use log-scaled parameters for computation. This is computationally more expensive, but offers better numerically stability in case of long output sequences
Returns:
Likelihood that the given model produced the given sequence

modelLikelihood

public static double modelLikelihood(Matrix alpha,
                                     boolean scaled)
Computes the likelihood that a given output sequence was computed by a given model using the alpha values computed by the forward algorithm. // TODO I am a bit confused here - where is the output sequence referenced in the comment above in the code?

Parameters:
alpha - Matrix of alpha values
scaled - Set to true if the alpha values are log-scaled.
Returns:
model likelihood.

modelLikelihood

public static double modelLikelihood(HmmModel model,
                                     int[] outputSequence,
                                     Matrix beta,
                                     boolean scaled)
Computes the likelihood that a given output sequence was computed by a given model.

Parameters:
model - model to compute sequence likelihood for.
outputSequence - sequence to base computation on.
beta - beta parameters.
scaled - set to true if betas are log-scaled.
Returns:
likelihood of the outputSequence given the model.

decode

public static int[] decode(HmmModel model,
                           int[] observations,
                           boolean scaled)
Returns the most likely sequence of hidden states for the given model and observation

Parameters:
model - model to use for decoding.
observations - integer Array containing a sequence of observed state IDs
scaled - Use log-scaled computations, this requires higher computational effort but is numerically more stable for large observation sequences
Returns:
integer array containing the most likely sequence of hidden state IDs


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.