# Identifiability and convergence (Input-Output Hidden Markov Model)

**URL:** <https://discourse.mc-stan.org/t/identifiability-and-convergence-input-output-hidden-markov-model/1305>\
**Category:** Modeling\
**Tags:** hmm\
**Created:** [July 21, 2017, 1:42am UTC](https://discourse.mc-stan.org/t/identifiability-and-convergence-input-output-hidden-markov-model/1305 "2017-07-21T01:42:54Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Bob\_Carpenter](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/bob_carpenter/32/9230_2.png) [@Bob\_Carpenter](https://discourse.mc-stan.org/u/Bob_Carpenter)\
**Post date:** [July 23, 2017, 4:03pm UTC](https://discourse.mc-stan.org/t/identifiability-and-convergence-input-output-hidden-markov-model/1305/4 "2017-07-23T16:03:49Z")

</div>

For (3), you may want to try modeling only K-1 categories. Then each set of parameters is interpreted as log odds vs. that fixed category.

(2) sounds like a recipe for some pretty strong non-identifiability as you have moving components and states.

For the code (4), can’t you declare `unA_ij` as a matrix and define it by matrix multiplication? That’s more efficient than the loop. Every time I look at one of these complicated mixtures it makes me realize we need better vectorized mixtures built-in. But it’s a design challenge figuring out how to specify all the shared computations efficiently and on the right scale (log, log odds, linear). If you define `accumulator` in the forward algorithm as a vector, you can vectorize the innermost loop. Do you really need those `alpha_tk` or can you define them as generated quantities? As generated quantities, there’s no autodiff overhead. I didn’t follow the forwards-backwards bit. I found I only had to calculate the forward algorithm and then I could read the likelihood off the final row with a final `log_sum_exp`. I’ve been wondering if using more sufficient stats in forward-backward would be a win.

You want to vectorize that look over `K` in the model. It’s much more efficient. I don’t like variable names like “hyperparams”–it’s too much like naming a variable “variable”. They’re also too easy to get confused that way. The ony tricky vectorization is `mu_kl`, which will be

```
mu_kl ~ normal(hypermu_k, hyperparams[3]);

```

The others you just drop the loop and the `j` index.

The moveHMM package in R has a nice overview of the movement HMMs with covariates. The CRF paper by McCallum, Lafferty and Pereira also compares some similar alterntives and introduces CRFs—it’s in a natural languae setting, but there have been lots of other applications.

Do you really need to run Viterbi within the algorithm? What do you use it for? Viterbi only finds the first-best output (or the n-best in the natural generalization with backtracking).

---

_[View the full topic](https://discourse.mc-stan.org/t/identifiability-and-convergence-input-output-hidden-markov-model/1305)._
