Hi I need to understand everything about hmm for my project. in the stan manual 2.17 page 174

```
int<lower=1,upper=K> z[T]; // categories
model {
for (k in 1:K)
theta[k] ~ dirichlet(alpha);
for (k in 1:K)
phi[k] ~ dirichlet(beta);
for (t in 1:T)
w[t] ~ categorical(phi[z[t]]);
for (t in 2:T)
z[t] ~ categorical(theta[z[t - 1]]);
}
```

The loop goes thru time slots t, which I can see, but what about the N users (or whatever data generators the use case involves)? You canâ€™t solve the hmm using a single line of data, can you? even if there are T data points in the line. Is this meant to be a case with one infinitely long time series data?

That is a special case where you know the values of the hidden states, which I donâ€™t think is a very common situation.

but what about the N users (or whatever data generators the

In that example, there are K different hidden states the model can be in and V different observables it might produce. The goal of the model is to use knowledge of the hidden states + the observables to figure out the transition probabilities (K length K simplexes) and emission probabilities (K length V simplexes).

You canâ€™t solve the hmm using a single line of data, can you?

This example is a little simple. If you end up doing HMMs youâ€™ll probably end up doing some forward algorithm stuff like on page 176/177. There was a talk at Stancon by @LuisDamiano and @weylandt on HMMs. I donâ€™t think the Stancon stuff is all up online in any one spot yet, but those guys can probly point you to the Github or wherever it lives.

Is this meant to be a case with one infinitely long time series data?

I donâ€™t think there are any constraints on time here.

2 Likes

The language is improper in my opinion. If you already know the states at any one point in time, then there is nothing hidden about it. It should be called a markov chain, without the h. Based on your answer, it is not what I am looking for.

Itâ€™s just an example. Maybe not the most practical, but just trying to write in code what all the words are saying.

If you want HMMs, the â€śSemisupervised Estimationâ€ť section of the manual is probably more useful. I Googleâ€™d for @LuisDamianoâ€™s presentation and itâ€™s got a lot more details: https://github.com/luisdamiano/stancon18, https://cdn.rawgit.com/luisdamiano/stancon18/11d75524/main.html

We are using â€śHMMâ€ť in the standard way. The sequence of latent/hidden states z is always Markovian, whether observed or not. But even if observed, the outputs y conditioned on z arenâ€™t typically Markovian.

As @bbbales2 points out, you can observe none (unsupervised), some (semi-supervised), or all (supervised) of the states.

1 Like