laplace_sample: expose CmdStan's diagnostic_file (the Hessian at the mode)

Geschlossen
#868 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

@atarutin arbeitet bereits daran.

Seit 09.10.2026.

  • #870 von @atarutin — offen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
25/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
backend

Rechercherichtung

Start from CmdStanModel.laplace_sample and compare it with how sample handles save_diagnostics, since the issue proposes mirroring that argument. The result would be exposed on CmdStanLaplace as a hessian attribute. Pull request #870 is already open against this issue, so check it before starting. Done means the diagnostic file is requested, parsed, and its Hessian is available when requested.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Summary

CmdStan's laplace method can write a diagnostic file (output diagnostic_file=...), but CmdStanModel.laplace_sample has no argument to request it. That file is where CmdStan reports the Hessian at the mode, so cmdstanpy users can't get the Hessian the Laplace approximation was built from.

Details
  • laplace_sample's signature in 1.3.0 is (data, mode, draws, *, jacobian, seed, output_dir, sig_figs, save_profile, show_console, refresh, time_fmt, timeout, opt_args). There is no diagnostic_file or save_diagnostics, unlike sample(save_diagnostics=...).
  • In CmdStan 2.40.0, running laplace mode=<mode.csv> ... output file=lap.csv diagnostic_file=lap_diag.json writes a JSON file whose "Hessian" key holds the Hessian of the log density at the mode, on the unconstrained scale. We confirmed this by running it directly.
Use case

We fit a model by optimize (MLE, jacobian=False) and want observed-information standard errors at the optimum. The Hessian at the mode is that object. Through cmdstanpy we can only get the Laplace draws, and from those we'd have to re-estimate a covariance that CmdStan has already computed exactly.

Suggested API

Add a save_diagnostics: bool = False argument, mirroring sample. It would pass diagnostic_file=<output_dir>/<name>-diagnostic.json to CmdStan, and expose the parsed file on CmdStanLaplace. For example, CmdStanLaplace.hessian would return an np.ndarray, or None if the diagnostic file wasn't requested.

We are happy to open a PR with a test, if this API is acceptable.

Versions

cmdstanpy 1.3.0, CmdStan 2.40.0, Python 3.12, Linux x86_64.

Vorherrschende Sprache
Python
Sterne
198
Forks
82
Ø Merge
3 T. 14 Std.
Gemergte PRs (30 T.)
4

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus stan-dev/cmdstanpy

Alle Issues in stan-dev/cmdstanpy

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.