math icon indicating copy to clipboard operation
math copied to clipboard

Laplace: Add mean argument to helper distributions

Open WardBrian opened this issue 6 months ago • 2 comments

Summary

Closes #3202. Note that this is branched off of #3209, since doing the two changes independently would lead to a great many merge conflicts.

Tests

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

  • [x] 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/)

  • [x] the basic tests are passing

    • unit tests pass (to run, use: ./runTests.py test/unit)
    • header checks pass, (make test-headers)
    • dependencies checks pass, (make test-math-dependencies)
    • docs build, (make doxygen)
    • code passes the built in C++ standards checks (make cpplint)
  • [x] the code is written in idiomatic C++ and changes are documented in the doxygen

  • [x] the new changes are tested

WardBrian avatar Jun 17 '25 15:06 WardBrian

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)

laplace_marginal_poisson_log_lpmf(y | mu, [1], cov_fun, (sigmaz, N), theta_0)

avehtari avatar Jun 17 '25 15:06 avehtari

Thanks @avehtari.

Writing that test made me realize something else: The y_index argument to laplace_marginal_poisson_log_lpmf is currently 0-indexed rather than 1-indexed. Is that intentional @charlesm93 @SteveBronder?

WardBrian avatar Jun 17 '25 16:06 WardBrian

Writing that test made me realize something else: The y_index argument to laplace_marginal_poisson_log_lpmf is currently 0-indexed rather than 1-indexed. Is that intentional @charlesm93 @SteveBronder?

It should be 1-indexed to be consistent with the rest of Stan.

charlesm93 avatar Jun 24 '25 04:06 charlesm93

@charlesm93 y_index is now 1-indexed and I removed the newly redundant poisson_2_log helper

WardBrian avatar Jun 24 '25 20:06 WardBrian

@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

WardBrian avatar Jul 02 '25 14:07 WardBrian

@SteveBronder https://github.com/stan-dev/stanc3/pull/1523 still needs to be reviewed as well so they can be merged together

WardBrian avatar Jul 08 '25 14:07 WardBrian