-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
hmm rng states start at 1, not 0. #2113
Conversation
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.
Looks good. Thanks for the quick fix! The doc typo correction is optional, so I'll just approve this. If you want to correct it, I can approve again quickly.
// states are identifcal and follow a Bernoulli distribution parameterized | ||
// by rho. | ||
// The samples live on {1, 2}, so we need to deduct one to male the |
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.
"male" -> "make"
@@ -70,18 +70,22 @@ inline std::vector<int> hmm_latent_rng(const T_omega& log_omegas, | |||
Eigen::Map<Eigen::VectorXd> probs_vec(probs.data(), n_states); | |||
probs_vec = alphas.col(n_transitions) / alphas.col(n_transitions).sum(); | |||
boost::random::discrete_distribution<> cat_hidden(probs); | |||
hidden_states[n_transitions] = cat_hidden(rng); | |||
hidden_states[n_transitions] = cat_hidden(rng) + 1; |
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.
@charlesm93, there's a terribly named variable that stores the indexing. If you wanted to be proper about this, you could change this (and other instances) of + 1
with + stan::error_index::value
. https://github.com/stan-dev/math/blob/develop/stan/math/prim/meta/error_index.hpp
It's not only terribly named... it has no doc and I don't know how you would have known about it. I'll create issues to tackle that later.
The intention was if someone really wanted to 0-index things (like if it were from a C++ function), they'd compile with -DERROR_INDEX=0
and that would magically make things like this, bounds checks on arrays, and other places where there is indexing, be 0-indexed. By default, it's 1-indexed.
Alternately, we can just ditch the generality and explicitly say that everything is 1-indexed, as confusing as it is with C++ being 0-indexed, and make life simpler.
Anyway, just adding a comment so you know that there's a variable that defines the indexing. If you want to switch it, great. If not, also great.
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.
@charlesm93 I think it makes sense to do what @syclik is saying here.
I think how this works is you just add/subtract stan::error_index::value
everywhere before you added/subtracted 1
(including the tests). It's all tested in 1-indexing mode (how Stan uses it) and then if someone wants the 0-indexing they can do the make flag.
Release is the 19th and code freeze is the 12th for reference.
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.
@charlesm93 since this was sitting here and it was a relatively simple but confusing change I just did it (and made Bob's edit). Have a look and if you approve we can merge this.
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 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.
@bbbales2 you missed one +1, I translated it into an index error. Once the integration tests pass, I'll merge it (small caprice, I love pushing the merge button!)
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
Got this error on the Mac integration tests (log):
I'm not sure what it's about. Just restarting the integration tests. |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
The same error popped up again. Do you recognize this one @rok-cesnovar? Log here: https://jenkins.mc-stan.org/blue/organizations/jenkins/Stan/detail/downstream_tests/2044/pipeline
|
This looks as if the stanc download failed and did not retry (it fails on the first attempt of using it). Restart it and I will make an issue to make this more robust. |
I restarted the tests, will go green once they pass. https://jenkins.mc-stan.org/blue/organizations/jenkins/Math%20Pipeline/detail/PR-2113/4/pipeline |
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
…stan-dev/math into bugfix/issue-2112-hmm_rng_index
Jenkins Console Log Machine informationProductName: Mac OS X ProductVersion: 10.11.6 BuildVersion: 15G22010CPU: G++: Clang: |
All the comments by @bob-carpenter and @syclik have been addressed. Can one of the reviewers approve the PR? |
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.
Thanks for updating!
Summary
Solves issue#2112. The states returned by hmm_hidden_state_rng now live on {1, 2, ..., K}, rather than {0, 1, ..., K - 1}.
Tests
The existing unit tests were adjusted to handle state values that start at 1.
Release notes
The states returned by hmm_hidden_state_rng now live on {1, 2, ..., K}, rather than {0, 1, ..., K - 1}.
Checklist
Math issue Simulated states from hidden Markov model should be sampled from {1, 2,...,N} (rather than 0,1,2,...,N-1) #2112
Copyright holder: Charles Margossian and Columbia University.
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit/math/prim/prob/hmm_latent_rng_test.cpp
)make test-headers
)make test-math-dependencies
)make doxygen
)make cpplint
)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested