Skip to content

Add to_distribution for Hidden Markov Models and BUGS models  #755

@yebai

Description

@yebai

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions