learning-hmm-0.2.1.0: Yet another library for hidden Markov models

Safe HaskellNone
LanguageHaskell2010

Learning.HMM

Synopsis

Documentation

data HMM s o Source

Parameter set of the hidden Markov model. Direct use of the constructor is not recommended. Instead, call new or init.

Constructors

HMM 

Fields

states :: [s]

Hidden states

outputs :: [o]

Outputs

initialStateDist :: Categorical Double s

Categorical distribution of initial state

transitionDist :: s -> Categorical Double s

Categorical distribution of next state conditioned by the previous state

emissionDist :: s -> Categorical Double o

Categorical distribution of output conditioned by the hidden state

Instances

(Show s, Show o) => Show (HMM s o) 

new :: (Ord s, Ord o) => [s] -> [o] -> HMM s o Source

new states outputs returns a model from the states and outputs. The initialStateDist and emissionDist are set to be uniform distributions. The transitionDist is specified as follows: with probability 1/2, move to the same state, otherwise, move to a random state (which might be the same state).

>>> new [1, 2 :: Int] ['C', 'D']
HMM {states = [1,2], outputs = "CD", initialStateDist = fromList [(0.5,1),(0.5,2)], transitionDist = [(fromList [(0.75,1),(0.25,2)],1),(fromList [(0.25,1),(0.75,2)],2)], emissionDist = [(fromList [(0.5,'C'),(0.5,'D')],1),(fromList [(0.5,'C'),(0.5,'D')],2)]}

init :: (Eq s, Eq o) => [s] -> [o] -> RVar (HMM s o) Source

init states outputs returns a random variable of the model with states and outputs, wherein parameters are sampled from uniform distributions.

withEmission :: (Eq s, Eq o) => HMM s o -> [o] -> HMM s o Source

model `withEmission` xs returns a model in which the emissionDist is updated by re-estimations using the observed outputs xs. The emissionDist is set to be normalized histograms each of which is calculated from segumentations of xs based on the Viterbi state path.

viterbi :: (Eq s, Eq o) => HMM s o -> [o] -> ([s], LogLikelihood) Source

viterbi model xs performs the Viterbi algorithm using the observed outputs xs, and returns the most likely state path and its log likelihood.

baumWelch :: (Eq s, Eq o) => HMM s o -> [o] -> [(HMM s o, LogLikelihood)] Source

baumWelch model xs iteratively performs the Baum-Welch algorithm using the observed outputs xs, and returns a list of updated models and their corresponding log likelihoods.

simulate :: HMM s o -> Int -> RVar ([s], [o]) Source

simulate model t generates a Markov process of length t using the model, and returns its state path and observed outputs.