This is an old version, view current version.

26 Hidden Markov Models

An elementary first-order Hidden Markov model is a probabilistic model over N observations, yn, and N hidden states, xn, which can be fully defined by the conditional distributions p(ynxn,ϕ) and p(xnxn1,ϕ). Here we make the dependency on additional model parameters, ϕ, explicit. When x is continuous, the user can explicitly encode these distributions in Stan and use Markov chain Monte Carlo to integrate x out.

When each state x takes a value over a discrete and finite set, say {1,2,...,K}, we can take advantage of the dependency structure to marginalize x and compute p(yϕ). We start by defining the conditional observational distribution, stored in a K×N matrix ω with ωkn=p(ynxn=k,ϕ). Next, we introduce the K×K transition matrix, Γ, with Γij=p(xn=jxn1=i,ϕ). Each row defines a probability distribution and must therefore be a simplex (i.e. its components must add to 1). Currently, Stan only supports stationary transitions where a single transition matrix is used for all transitions. Finally we define the initial state K-vector ρ, with ρk=p(x0=kϕ).

The Stan functions that support this type of model are special in that the user does not explicitly pass y and ϕ as arguments. Instead, the user passes logω, Γ, and ρ, which in turn depend on y and ϕ.