stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.57k stars 368 forks source link

Feature/3149 jacobian optimize #3152

Closed bob-carpenter closed 1 year ago

bob-carpenter commented 1 year ago

Submission Checklist

Summary

Add a template parameter to all optimization functions (Newton, BFGS, L-BFGS) to indicate whether or not to include Jacobian adjustments. Until now, we had hard coded turning the Jacobian off to provide maximum likelihood estimates. With the Jacobian turned on, we will now support an option for max a posteriori (MAP) estimates.

Intended Effect

Use MAP estimates in Laplace approximation.

How to Verify

Unit tests with a new model with the Jacobian calculated and optimized explicitly.

Side Effects

Shouldn't be any because I made it the last argument and gave it a default of false so that it falls back on existing behavior.

Documentation

Yes, in code.

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):

Simons Foundation

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

avehtari commented 1 year ago

I missed this one earlier, too

we will now support an option for max a posteriori (MAP) estimates.

It would be good to be explicit whether the MAP is in unconstrained or constrained space (as these are not in general the same)

bob-carpenter commented 1 year ago

We compute the optimization in the unconstrained space using the Jacobian adjustment. We then map the posterior mode in the unconstrained space back to the constrained space.

Then for the Laplace approximation, we map back from constrained to unconstrained, lay down the normal approximation in the unconstrained space (including Jacobian for the MAP option), sample from the approximate normal in the unconstrained space, and then inverse transform the draws back to the constrained space.