-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Description
Copied from #595 (comment)
HMMs can be straightforwardly supported via the new to_distribution
interface:
"""
hmm(K, T)
A Hidden Markov Model with `K` states and `T` observations with marginalized hidden states.
"""
@model function hmm(K, T)
# Transition matrix.
π ~ product_distribution(fill(Dirichlet(fill(1 / K, K)), K))
# Mean of emission distribution.
μ ~ Bijectors.ordered(MvNormal(zeros(K), 10I))
# HMM(init, trans, emissions).
hmm = HMM(π[:, 1], permutedims(π), Normal.(μ, 1))
y ~ to_distribution(hmm, T)
return y
end
For to_distribution(hmm, T)
, we need to implement two methods, i.e.,
rand(to_distribution(hmm, T))
which samplesy
of lengthT
log pdf (to_distribution(hmm), y)
, which computes the marginal log density ofy
by the forward-backward algorithm.
Metadata
Metadata
Assignees
Labels
No labels