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.6k stars 370 forks source link

Add option to output Hessian, disable LP calculations in Laplace #3261

Closed WardBrian closed 9 months ago

WardBrian commented 10 months ago

Submission Checklist

Summary

Closes #3215 Closes #3260

Intended Effect

This adds two new options to the laplace approximation service function. The first is a boolean calculate_lp, similar to #3249

The second is a structured writer which will save the result of the evaluation at the mode, namely it will produce a JSON file like

{
  "lp_mode" : 0,
  "gradient" : [ 0, 0 ],
  "Hessian" : [ [ -2.77778, 2.22222 ], [ 2.22222, -2.77778 ] ]
}

How to Verify

Tests added

Side Effects

I left the existing function for backwards compatibility. The above arguments default to true and a no-op writer, respectively.

Documentation

Added inline documentation, online doc will come with the cmdstan PR.

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 9 months ago

Great!