-
-
Notifications
You must be signed in to change notification settings - Fork 116
Issue/838 hmm #840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Issue/838 hmm #840
Conversation
I took a look through this and while I'm in favor of minimal examples, this one's a bit too minimal. I would really like to see the model laid out in more detail than the conditional distributions. Here are some concrete suggestions:
array[3] simplex[3] gamma_arr;
matrix[3, 3] gamma;
for (n in 1:3) gamma[n] = gamma_arr[n];
for (n in 1:N) {
for (k in 1:3) {
log_omega[k, n] = normal_lpdf(y[n] | mu[k], sigma);
}
}
|
I'm rewriting the code to make the transition matrix less constrained (per comment 4) and I wanted to check: we don't have a stochastic matrix type, right? |
We have row and column but not double yet https://mc-stan.org/docs/reference-manual/types.html#stochastic-matrices |
@bob-carpenter I implemented your feedback. Some questions:
|
For (5), I think the idea's that there are three sources of error: measurement error, modeling error, and sampling error. For example, sampling error arises when you subsample a population and use that for estimation. You get modeling error if you use a linear regression for a relationship that's not linear or use normal errors when the errors are skewed, and so on. If you're weighing things with a scale and you know the scale's biased to the high side, you can correct that measurement error. You can explicitly add a measurement error model if you know your measurement model (e.g., gravitational lensing is part of the measurement error model; your work with Bruno et al. on deconvolving galactic dust is part of the measurement model for the CMB, etc.). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a ton of little things to fix, but nothing major.
@@ -294,6 +294,21 @@ pagetitle: Alphabetical Index | |||
- <div class='index-container'>[distribution statement](unbounded_discrete_distributions.qmd#index-entry-0c7465aa1beceb6e7e303af36b60e2b847fc562a) <span class='detail'>(unbounded_discrete_distributions.html)</span></div> | |||
|
|||
|
|||
<a id='beta_neg_binomial_cdf' href='#beta_neg_binomial_cdf' class='anchored unlink'>**beta_neg_binomial_cdf**:</a> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this PR touching negative binomial? Are you up to date with the main branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm... that's odd. Let me check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, I am up to date with the main branch, so I'm not sure how this error occurred. I suppose I could simply delete the extra lines.
latent state $k$ is parameterized by a $V$-simplex $\phi_k$. The | ||
observed output $y_t$ at time $t$ is generated based on the hidden | ||
state indicator $z_t$ at time $t$, | ||
When $z_{1:N}$ is continuous, the user can explicitly encode these distributions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't z_{1:N}
a subset of
Did you perhaps mean to say that the output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
z_{1:N}
denotes the latent variables. In general, the domain of z
can be continuous, say
src/stan-users-guide/time-series.qmd
Outdated
The model for the supervised data does not change; the unsupervised | ||
data are handled with the following Stan implementation of the forward | ||
algorithm. | ||
The last function `hmm_marginal` takes in all the ingredients of the HMM, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eliminate the comma---English doesn't use commas between conjunctions unless there are more than two. So it's just "A and B", but it's either "A, B, and C" (Oxford style) or "A, B and C" (defective American style).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Although I was under the impression they didn't use the Oxford comma in the UK. I remember noticing this during StanCon in Cambridge and I figured out the Cambridge folks were just taking a piss. But when I asked some of the locals, it turned out they were familiar with the Oxford comma.
different from sample to sample in the posterior. | ||
To obtain samples from the posterior distribution of $z$, | ||
we use the generated quantities block and draw, for each sample $\phi$, | ||
a sample from $p(z \mid y, \phi)$. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't typically need draws from
You can also use the forward-backward algorithm to work out marginally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added "If we desire samples from the posterior distribution of
and with the draw in generated quantities, we obtain draws from | ||
$p(\phi \mid y) p(z \mid y, \phi) = p(z, \phi \mid y)$. | ||
It is also possible to compute the posterior probbability of each hidden state, | ||
that is $\text{Pr}(z_n = k \mid \phi, y)$. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically this phi
is marginalized out and we look at
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You get
$\text{Pr}(z \mid \phi, y)$, because such calculation requires accounting | ||
for the posterior correlation between the different components of $z$. | ||
Therefore, `hidden_probs` should NOT be used to obtain posterior samples. | ||
Instead, users should rely on `hmm_latent_rng`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although not necessary, it's nice to have examples of how to do that. Like:
generated quantities {
array[N] int<lower=1, upper=K> z = hmm_latent_rng(...fill-in params here to match example...);
}
I know this feels obvious, but it can be hard for the users to put the arguments and result types together.
@bob-carpenter I completely missed your review. Sorry about that. Hopefully we'll merge this in soon. |
Submission Checklist
<<{ since VERSION }>>
Summary
Addresses issue #838 and updates user-doc on HMMs.
Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Charles Margossian, Simons Foundation
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: