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

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

public final class HmmUtils
extends Object

A collection of utilities for handling HMMModel objects.


Method Summary
static List<String> decodeStateSequence(HmmModel model, int[] sequence, boolean observed, String defaultValue)
          Decodes a given collection of state IDs into the corresponding state names registered in a given model.
static int[] encodeStateSequence(HmmModel model, Collection<String> sequence, boolean observed, int defaultValue)
          Encodes a given collection of state names by the corresponding state IDs registered in a given model.
static Vector getCumulativeInitialProbabilities(HmmModel model)
          Compute the cumulative distribution of the initial hidden state probabilities for the given HMM model.
static Matrix getCumulativeOutputMatrix(HmmModel model)
          Compute the cumulative output probability matrix for the given HMM model.
static Matrix getCumulativeTransitionMatrix(HmmModel model)
          Compute the cumulative transition probability matrix for the given HMM model.
static void normalizeModel(HmmModel model)
          Function used to normalize the probabilities of a given HMM model
static HmmModel truncateModel(HmmModel model, double threshold)
          Method to reduce the size of an HMMmodel by converting the models DenseMatrix/DenseVectors to sparse implementations and setting every value < threshold to 0
static void validate(HmmModel model)
          Validates an HMM model set
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCumulativeTransitionMatrix

public static Matrix getCumulativeTransitionMatrix(HmmModel model)
Compute the cumulative transition probability matrix for the given HMM model. Matrix where each row i is the cumulative distribution of the transition probability distribution for hidden state i.

Parameters:
model - The HMM model for which the cumulative transition matrix should be computed
Returns:
The computed cumulative transition matrix.

getCumulativeOutputMatrix

public static Matrix getCumulativeOutputMatrix(HmmModel model)
Compute the cumulative output probability matrix for the given HMM model. Matrix where each row i is the cumulative distribution of the output probability distribution for hidden state i.

Parameters:
model - The HMM model for which the cumulative output matrix should be computed
Returns:
The computed cumulative output matrix.

getCumulativeInitialProbabilities

public static Vector getCumulativeInitialProbabilities(HmmModel model)
Compute the cumulative distribution of the initial hidden state probabilities for the given HMM model.

Parameters:
model - The HMM model for which the cumulative initial state probabilities should be computed
Returns:
The computed cumulative initial state probability vector.

validate

public static void validate(HmmModel model)
Validates an HMM model set

Parameters:
model - model to sanity check.

encodeStateSequence

public static int[] encodeStateSequence(HmmModel model,
                                        Collection<String> sequence,
                                        boolean observed,
                                        int defaultValue)
Encodes a given collection of state names by the corresponding state IDs registered in a given model.

Parameters:
model - Model to provide the encoding for
sequence - Collection of state names
observed - If set, the sequence is encoded as a sequence of observed states, else it is encoded as sequence of hidden states
defaultValue - The default value in case a state is not known
Returns:
integer array containing the encoded state IDs

decodeStateSequence

public static List<String> decodeStateSequence(HmmModel model,
                                               int[] sequence,
                                               boolean observed,
                                               String defaultValue)
Decodes a given collection of state IDs into the corresponding state names registered in a given model.

Parameters:
model - model to use for retrieving state names
sequence - int array of state IDs
observed - If set, the sequence is encoded as a sequence of observed states, else it is encoded as sequence of hidden states
defaultValue - The default value in case a state is not known
Returns:
list containing the decoded state names

normalizeModel

public static void normalizeModel(HmmModel model)
Function used to normalize the probabilities of a given HMM model

Parameters:
model - model to normalize

truncateModel

public static HmmModel truncateModel(HmmModel model,
                                     double threshold)
Method to reduce the size of an HMMmodel by converting the models DenseMatrix/DenseVectors to sparse implementations and setting every value < threshold to 0

Parameters:
model - model to truncate
threshold - minimum value a model entry must have to be retained.
Returns:
Truncated model


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