-
-
Notifications
You must be signed in to change notification settings - Fork 195
Laplace: Add mean argument to helper distributions #3210
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
Conversation
This example https://discourse.mc-stan.org/t/embedded-laplace-numerical-problem/39700 uses non-zero mean (mu) and Poisson. So with the helper it should look something like (not certain what is the argument order now)
|
Thanks @avehtari. Writing that test made me realize something else: The |
test/unit/math/laplace/laplace_marginal_poisson_log_lpmf_test.cpp
Outdated
Show resolved
Hide resolved
It should be 1-indexed to be consistent with the rest of Stan. |
@charlesm93 y_index is now 1-indexed and I removed the newly redundant poisson_2_log helper |
d3fdfac
to
6b19281
Compare
const ThetaVec& theta_0, CovarFun&& covariance_function, | ||
CovarArgs&& covar_args, double tolerance, int max_num_steps, | ||
const Mean& mean, CovarFun&& covariance_function, CovarArgs&& covar_args, | ||
const ThetaVec& theta_0, double tolerance, int max_num_steps, |
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 @avehtari so with this change the user will always have to supply a mean. Are there a lot of instances where the mean would be zero? aka do we want a signature without a mean as well?
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.
Re-reading the OP and discussion in #3202, it seems like the consensus is to have the signature with the mean be the only one at the moment. We can add one that allows a scalar (as @charlesm93 requested) to make it easier to pass e.g. 0
instead of a rep_vector(0, N)
, or a signature without it, but both of those would require some extra work as the compiler isn't currently set up for 'overloads' of the laplace functions as easily
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.
it seems like the consensus is to have the signature without the mean be the only one at the moment.
Sorry @WardBrian I'm confused. Does that mean we should close this PR for now?
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.
That means we should merge this PR... I meant "with"
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.
lol icic got it
6b19281
to
0acf4e4
Compare
@SteveBronder similar to the last PR, the tests for math are passing, the failure is just because the compiler update needs to be merged simultaneously. So this is ready to review |
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.
Few small things but looks good!
* \laplace_common_args | ||
* \rng_arg | ||
* \msg_arg | ||
*/ | ||
template <typename CovarFun, typename CovarArgs, typename RNG> | ||
template <typename Mean, typename CovarFun, typename CovarArgs, typename RNG, | ||
require_eigen_vector_t<Mean>* = nullptr> |
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.
Should we delete this so that it is easier to make into a scalar later?
require_eigen_vector_t<Mean>* = nullptr> | |
> |
inline Eigen::VectorXd laplace_latent_tol_poisson_log_rng( | ||
const std::vector<int>& y, const std::vector<int>& y_index, | ||
CovarFun&& covariance_function, CovarArgs&& covar_args, ThetaVec&& theta_0, | ||
const double tolerance, const int max_num_steps, | ||
const Mean& mean, CovarFun&& covariance_function, CovarArgs&& covar_args, |
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.
const Mean& mean, CovarFun&& covariance_function, CovarArgs&& covar_args, | |
Mean&& mean, CovarFun&& covariance_function, CovarArgs&& covar_args, |
const int hessian_block_size, const int solver, | ||
const int max_steps_line_search, RNG& rng, std::ostream* msgs) { | ||
laplace_options_user_supplied ops{hessian_block_size, solver, | ||
max_steps_line_search, tolerance, | ||
max_num_steps, value_of(theta_0)}; | ||
return laplace_base_rng(poisson_log_likelihood{}, | ||
std::forward_as_tuple(y, y_index), | ||
std::forward_as_tuple(y, y_index, mean), |
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.
std::forward_as_tuple(y, y_index, mean), | |
std::forward_as_tuple(y, y_index, std::forward<Mean>(mean)), |
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.
This and the forwarding for all the functions
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.
Done
@@ -4,12 +4,9 @@ | |||
|
|||
#include <boost/random/mersenne_twister.hpp> | |||
#include <boost/math/distributions.hpp> | |||
#include "Eigen/src/Core/Matrix.h" |
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.
Does this need to be here?
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.
No, it was 'helpfully' inserted by autocomplete in vscode...
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.
One header include needs changed then this is good!
@SteveBronder stan-dev/stanc3#1523 still needs to be reviewed as well so they can be merged together |
Summary
Closes #3202.
Adds a mean argument to the helpers. It is templated such that it can be a vector or scalar.
The
poisson_log_2
helper is redundant with this change and is therefore removed.Additionally, it fixes the
y_index
argument to be 1-indexed to match the rest of StanTests
Existing tests updated to pass 0 as the mean. It would be nice to add some tests
with a non-zero mean, if there are suggestions (@avehtari @charlesm93)
Side Effects
Release notes
Checklist
Copyright holder: (fill in copyright holder information)
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
)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