Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data HMM s o = HMM {
- states :: [s]
- outputs :: [o]
- initialStateDist :: Categorical Double s
- transitionDist :: s -> Categorical Double s
- emissionDist :: s -> Categorical Double o
- type LogLikelihood = Double
- new :: (Ord s, Ord o) => [s] -> [o] -> HMM s o
- init :: (Eq s, Eq o) => [s] -> [o] -> RVar (HMM s o)
- withEmission :: (Eq s, Eq o) => HMM s o -> [o] -> HMM s o
- viterbi :: (Eq s, Eq o) => HMM s o -> [o] -> ([s], LogLikelihood)
- baumWelch :: (Eq s, Eq o) => HMM s o -> [o] -> [(HMM s o, LogLikelihood)]
- simulate :: HMM s o -> Int -> RVar ([s], [o])
Documentation
Parameter set of the hidden Markov model. Direct use of the
constructor is not recommended. Instead, call new
or init
.
HMM | |
|
type LogLikelihood = Double Source
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.