Re: Hierarchical HMMs in Stan?

96 views
Skip to first unread message

Bob Carpenter

unread,
Nov 8, 2015, 3:01:53 AM11/8/15
to Yarden Katz, Stan users mailing list
No, Stan doesn't support discrete parameters, so that model
won't compile.

You can do inference through marginalization, as in HMMs.
Please see the manual chapter on latent discrete parameters
and on HMMs. I can't repeat all that in an email.

And would you mind asking subsequent questions on the users
list? Every member is allowed to post. You probably found
your way to stan-dev, not stan-users.

- Bob

> On Nov 6, 2015, at 5:40 PM, Yarden Katz <yar...@mit.edu> wrote:
>
> Thanks for this. To clarify, I meant models where you're doing inference over discrete variables. I.e., where the "parameters" section contains categorical variables. In particular, I'm trying to see if Stan can solve a problem from a problem set I wrote a long time ago (see problem 1, attached). There are many variants of this segmentation problem (like switching Kalman filters and other models described in Kevin Murphy's PhD thesis on DBNs.)
>
> The HMM examples you link to are helpful; but as far as I can tell, they all infer only continuous (simplex-type) variables.
>
> I tried writing the casino switcher model from the attachment in Stan below. I just wanted to check if this is the kind of thing Stan can do, or if inference over categorical types isn't possible.
>
> Thanks very much. Best, Yarden
>
> My attempt:
>
> data {
> int<lower=1> N; // number of observations
> vector[N] flips; // observed flips
> real<lower=0, upper=1> alpha; // switching probability
> real<lower=0, upper=1> coinA; // weight of coin A
> real<lower=0, upper=1> coinB; // weight of coin B
> }
> parameters {
> vector[N] coins;
> }
> model {
> for (k in 1:N) {
> coins[k] ~ bernoulli(alpha);
> if (coins[k])
> flips[k] ~ bernoulli(coinA);
> else
> flips[k] ~ bernoulli(coinB);
> }
> }
>
> data = {"K": 10,
> "flips": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
> "alpha": 0.5,
> "coinA": 0.2,
> "coinB": 0.8}
>
>
> <pset3.pdf>
>
> On Nov 6, 2015, at 4:02 PM, Bob Carpenter <ca...@alias-i.com> wrote:
>
>> HMMs always have discrete stats, so I'm assuming you mean
>> continuous outputs. I'm not sure what your plan is to mix
>> them, but feel free to write into the list.
>>
>> That link should be a very indirect one to this:
>>
>> http://mc-stan.org/documentation/
>>
>> To save you fishing, the directory you want is here:
>>
>> https://github.com/stan-dev/example-models/tree/master/misc/hmm
>>
>> I'm going to be reorganizing all of our examples over the
>> next year or so, so that location may change.
>>
>> Thanks for reporting and I'll change the link for the next
>> manual release:
>>
>> https://github.com/stan-dev/stan/issues/1617#issuecomment-154533786
>>
>> You might want to write to Jeffrey Arnold about his examples.
>> He has things like Kalman filters if you're looking for continous
>> output HMMs. We keep meaning to make those official examples, but
>> I don't know what their current state is.
>>
>> - Bob
>>
>>> On Nov 6, 2015, at 10:16 AM, Yarden Katz <yar...@mit.edu> wrote:
>>>
>>> Hi Bob,
>>>
>>> I had a quick question about stan that I was hoping to get your thoughts on (I tried joining the Google groups, but it doesn't let me post).
>>>
>>> What is the up to date example of running a (discrete) HMM in Stan? There's an example in the manual (section 6.6, p. 88) but I can't find the complete code. The manual points to http://mc-stan.org/examples.html for the complete code, but that link is broken (404). The main examples page from mc-stan.org links to: https://github.com/stan-dev/example-models/wiki -- but the discrete HMM model doesn't appear there, as far as I can see.
>>>
>>> Through github, I found a repository on state space models in stan (https://github.com/jrnold/ssmodels-in-stan) but not sure if those are up to date. (The readme says "Work in progress, nothing to see here, move along".)
>>>
>>> Any code examples of running discrete HMMs would be helpful. I'd like to see if it's possible, using Stan, to fit a hierarchical HMM that has a combination of discrete and continuous state variables.
>>>
>>> Thanks very much! Best, Yarden
>>>
>>
>

Reply all
Reply to author
Forward
0 new messages