hmm-lapack-0.3.0.2: Hidden Markov Models using LAPACK primitives

Safe HaskellNone
LanguageHaskell2010

Math.HiddenMarkovModel.Example.TrafficLight

Description

Warning: do not import that module, it is only intended for demonstration

This is an example of an HMM with discrete emissions. We model a traffic light consisting of the colors red, yellow, green, where only one lamp can be switched on at every point in time. This way, when it is yellow you cannot tell immediately whether it will switch to green or red. We can only infer this from the light seen before.

There are four hidden states: StateRed emits red, StateYellowRG emits yellow between red and green, StateGreen emits green, StateYellowGR emits yellow between green and red.

We quantise time in time steps. The transition matrix of the model hmm encodes the expected duration of every state counted in time steps and what states follow after each other. E.g. transition probability of 0.8 of a state to itself means that the expected duration of the state is 5 time steps (1/(1-0.8)). However, it is a geometric distribution, that is, shorter durations are always more probable.

The distribution of hmm encodes which lights a state activates. In our case everything is deterministic: Every state can switch exactly one light on.

Given a sequence of observed lights the function reveal tells us the most likely sequence of states. We test this with the light sequences in stateSequences where we already know the hidden states as they are stored in labeledSequences. verifyRevelation compares the computed state sequence with the given one.

We also try some trainings in hmmTrainedSupervised et.al.

Synopsis

Documentation

type HMM = Discrete Color StateSet Double Source #

data Color Source #

Constructors

Red 
Yellow 
Green 
Instances
Enum Color Source # 
Instance details

Defined in Math.HiddenMarkovModel.Example.TrafficLightPrivate

Eq Color Source # 
Instance details

Defined in Math.HiddenMarkovModel.Example.TrafficLightPrivate

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

Ord Color Source # 
Instance details

Defined in Math.HiddenMarkovModel.Example.TrafficLightPrivate

Methods

compare :: Color -> Color -> Ordering #

(<) :: Color -> Color -> Bool #

(<=) :: Color -> Color -> Bool #

(>) :: Color -> Color -> Bool #

(>=) :: Color -> Color -> Bool #

max :: Color -> Color -> Color #

min :: Color -> Color -> Color #

Read Color Source # 
Instance details

Defined in Math.HiddenMarkovModel.Example.TrafficLightPrivate

Show Color Source # 
Instance details

Defined in Math.HiddenMarkovModel.Example.TrafficLightPrivate

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

NFData Color Source # 
Instance details

Defined in Math.HiddenMarkovModel.Example.TrafficLightPrivate

Methods

rnf :: Color -> () #

Format Color Source # 
Instance details

Defined in Math.HiddenMarkovModel.Example.TrafficLightPrivate

Methods

format :: String -> Color -> Box #

CSVSymbol Color Source #

Using show and read is not always a good choice since they must format and parse Haskell expressions which is not of much use to the outside world.

Instance details

Defined in Math.HiddenMarkovModel.Example.TrafficLightPrivate

red :: (State, Color) Source #

yellowRG :: (State, Color) Source #

green :: (State, Color) Source #

yellowGR :: (State, Color) Source #

labeledSequences :: T [] (T [] (State, Color)) Source #

hmmTrainedSupervised :: HMM Source #

Construct a Hidden Markov model by watching a set of manually created sequences of emissions and according states.

hmmTrainedUnsupervised :: HMM Source #

Construct a Hidden Markov model starting from a known model and a set of sequences that contain only the emissions, but no states.

hmmIterativelyTrained :: HMM Source #

Repeat unsupervised training until convergence.