Skip to content

Issue/873 embedded laplace#874

Merged
SteveBronder merged 41 commits into
masterfrom
issue/873-embeddedLaplace
May 11, 2026
Merged

Issue/873 embedded laplace#874
SteveBronder merged 41 commits into
masterfrom
issue/873-embeddedLaplace

Conversation

@charlesm93
Copy link
Copy Markdown
Contributor

Submission Checklist

  • Builds locally
  • New functions marked with <<{ since VERSION }>>
  • Declare copyright holder and open-source license: see below

Summary

Documentation for suite of functions for the embedded Laplace approximation. Starting a PR to allow easy file comparison and will fill in the details soon.

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): (Figuring this out)

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@WardBrian WardBrian linked an issue Apr 22, 2025 that may be closed by this pull request
2 tasks
@avehtari avehtari self-requested a review April 24, 2025 16:28
The Laplace approximation is especially useful if $p(\theta)$ is
multivariate normal and $p(y \mid \phi, \theta)$ is
log-concave. Stan's embedded Laplace approximation is restricted to
have multivariate normal prior $p(\theta)$ and ... likelihood
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add here the restrictions for the likelihood

Copy link
Copy Markdown
Contributor Author

@charlesm93 charlesm93 May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two kinds of restrictions:

  • what the user can do without breaking Stan, i.e. the operations in the likelihood need to support higher-order autodiff.
  • what the user should do to insure the approximation is reliable.

I'll assume you have the first in mind.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was thinking the first as a restriction. For the second one we can say which kind of likelihood are more likely to work, ie, log concave and maybe near log concave

@avehtari
Copy link
Copy Markdown
Member

I made some edits to use the statistical terms correctly. In the end of first section, it would be good to tell the constraints on the likelihood function and I left there three dots.

@WardBrian
Copy link
Copy Markdown
Member

@charlesm93 I started to fill in some of the boilerplate we have in our functions reference. Those comments and things are actually useful for building the index page

@WardBrian WardBrian force-pushed the issue/873-embeddedLaplace branch from 4db967a to 7a07abd Compare May 29, 2025 14:30
@charlesm93
Copy link
Copy Markdown
Contributor Author

@WardBrian In the doc, what are the lupmf suffixes for? Is this a typo?

@WardBrian
Copy link
Copy Markdown
Member

The unnormalized versions, which correspond to propto=true in the C++. For these functions they may be equivalent, but for technical reasons they still need to exist. If they don’t do anything we could remove the documentation, but it would be less consistent with others then

<!-- real; laplace_marginal; (function ll_function, tuple(...), vector theta0, function K_function, tuple(...)); -->
\index{{\tt \bfseries laplace\_marginal }!{\tt (function ll\_function, tuple(...), vector theta0, function K\_function, tuple(...)): real}|hyperpage}

`real` **`laplace_marginal`**`(function ll_function, tuple(...), vector theta0, function K_function, tuple(...))`<br>\newline
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call theta0 theta_init? I just think it sounds more clear

* `hessian_block_size`: the size of the blocks, assuming the Hessian
$\partial \log p(y \mid \theta, phi) \ \partial \theta$ is block-diagonal.
The structure of the Hessian is determined by the dependence structure of $y$
on $\theta$. By default, the Hessian is treated as diagonal
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should note where that if Hessian block size is not 1 or N then theta needs to be divisible by the Hessian block size

```
matrix K_function(...)
```
There is no type restrictions for the variadic arguments. The variables $\phi$
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is phi here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think moreso from the section it's not clear how this is related to the k function

The only restriction is that this function returns a positive-definite matrix
with size $n \times n$ where $n$ is the size of $\theta$. The signature is:
```
matrix K_function(...)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call this covariance_function?

Comment thread src/functions-reference/embedded_laplace.qmd Outdated
Comment thread src/functions-reference/embedded_laplace.qmd Outdated
@mitzimorris
Copy link
Copy Markdown
Member

does the pdf build?

\index{{\tt \bfseries laplace\_marginal\_tol }!{\tt (function ll\_function, tuple(...), vector theta\_init, function K\_function, tuple(...), real tol, int max\_steps, int hessian\_block\_size, int solver, int max\_steps\_linesearch): real}|hyperpage}

<!-- real; laplace_marginal_tol; (function likelihood_function, tuple(...), vector theta_init, function covariance_function, tuple(...), real tol, int max_steps, int hessian_block_size, int solver, int max_steps_linesearch); -->

I had to go through the file and change the theta_init in the \index directive to theta\_init ?

@mitzimorris
Copy link
Copy Markdown
Member

mitzimorris commented Jun 11, 2025

just pulled the latest version and can't build the html.
nevermind - in wrong conda environment.

@charlesm93
Copy link
Copy Markdown
Contributor Author

charlesm93 commented Jun 11, 2025

how do I add the section on the embedded Laplace approximation in the reference manual? I made edits to reference-manual/_quarto.yml and added laplace_embedded.qmd as a chapter, but building the webpage doesn't render the new chapter.

@WardBrian
Copy link
Copy Markdown
Member

@charlesm93 that is the correct place to add it for it to show up in the pdf, you should separately add it to the _quarto.yml in the folder above

@charlesm93
Copy link
Copy Markdown
Contributor Author

I updated the docs to reflect two ongoing changes:

  • theta_init is now an optional argument.
  • the helper functions require users to pass a prior mean. For the latter, I assumed that the prior mean was a vector and that we are getting rid of the poisson_log_2 wrapper.

@SteveBronder
Copy link
Copy Markdown
Contributor

@charlesm93 I have a few changes here if you want to merge them. I mostly updated some wording and added the tuple for the laplace options

fix/laplace-1

differentiation (AD). Most functions in Stan support higher-order AD.
The exceptions are functions with specialized calls for reverse-mode AD, and
these are higher-order functions (algebraic solvers, differential equation
solvers, and integrators), the marginalization function for hidden Markov
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the discussion in issue stan-dev/math#3280, at least integrate_1d should work (Steve is fixing this)

@WardBrian
Copy link
Copy Markdown
Member

Just as a reminder for @charlesm93 @avehtari @SteveBronder: The next release is scheduled for approximately one month away (will likely be May 11th or May 18th).

It would be great to finish this API documentation and provide at least one runnable case study!

@SteveBronder SteveBronder merged commit 20bed8b into master May 11, 2026
@SteveBronder
Copy link
Copy Markdown
Contributor

@charlesm93 I merged this! I think it looks good so far and I'd like to make sure we have docs for the next release. We can always make new branches for new docs when needed.

@avehtari
Copy link
Copy Markdown
Member

Sorry for not checking this earlier. I'll check it this week and before the next release

@WardBrian WardBrian mentioned this pull request May 11, 2026
3 tasks
@WardBrian WardBrian deleted the issue/873-embeddedLaplace branch May 11, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation for embedded Laplace approximation

5 participants