Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to_distribution for Hidden Markov Models and BUGS models #755

Open
yebai opened this issue Dec 16, 2024 · 0 comments
Open

Add to_distribution for Hidden Markov Models and BUGS models #755

yebai opened this issue Dec 16, 2024 · 0 comments

Comments

@yebai
Copy link
Member

yebai commented Dec 16, 2024

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 samples y of length T
  • log pdf (to_distribution(hmm), y), which computes the marginal log density of y by the forward-backward algorithm.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant