maxmouchet / HMMBase.jl

Hidden Markov Models for Julia.
MIT License
94 stars 12 forks source link

Improve documentation for novices #38

Open BioTurboNick opened 2 years ago

BioTurboNick commented 2 years ago

I'm coming in relatively fresh to HMMs and I'm having trouble matching up terms I'm seeing in other work.

1) "Emission matrix" doesn't appear in the documentation - I gather it can be provided in place of B, but the documentation doesn't show that or describe its form.

2) The form the "Transition matrix" should take isn't explicitly documented.

I'd be happy to make a contribution here, once I understand them.

maxmouchet commented 2 years ago

Hi,

Here is an example with the Weather guessing game from Wikipedia.
Does that makes things clearer?

# K: number of states

# a[i] = probability of starting in i
# vector of length K
start_probability = [0.6, 0.4]

# A[i,j] = probability of going from i to j
# matrix of size KxK
transition_probability = [
    0.7 0.3; # i=1 (Rainy)
    0.4 0.6  # i=2 (Sunny)
]

# B[i] = probability distribution of the observations in state i
# vector of size K
# We can model an emission matrix with the discrete `Categorical` distribution:
emission_probability = [
    # [walk, shop, clean]
    Categorical([0.1, 0.4, 0.5]), # i=1 (Rainy)
    Categorical([0.6, 0.3, 0.1]), # i=2 (Sunny)
]

hmm = HMM(start_probability, transition_probability, emission_probability)