Reference / binference.engines.Laplace
binference.engines.Laplace¶
- class binference.engines.Laplace(model, *, importance=True, n_proposals=None, df=5.0, inflate=1.0, step=1e-05, rng=None, progress=False)[source]¶
Gaussian (Laplace) approximation in unconstrained coordinates.
The posterior mode in unconstrained coordinates is found with L-BFGS, and the Hessian \(H\) there from central differences of the exact gradient;
info["cov"]holds \((-H)^{-1}\). Proposals with scale matrixinflate**2times \((-H)^{-1}\) (seedf) are mapped to the simplex (or rates) and, withimportance=True, resampled towards the exact posterior by Pareto-smoothed importance weights. The result is flaggedapproximate=Truewheninfo["k_hat"]reachesinfo["k_hat_threshold"](psis_threshold()), and always without importance, whose draws are Gaussian.The approximation is excellent for well-populated bins with many objects and poorer for nearly empty bins, whose log-fractions have long tails.
- Parameters:
- modelPopulationModel
- importancebool
Apply PSIS importance resampling.
- n_proposalsint, optional
Number of proposals for importance resampling (default
max(2 * n_samples, 5)); without it the draws are the proposals themselves.- dffloat or None
Degrees of freedom of the multivariate Student-t importance proposal (default 5);
Noneuses the Gaussian itself. Heavier tails make the importance correction more robust.- inflatefloat
Factor on the scale of the proposals, or of the draws without
importance.- stepfloat
Relative step for the finite-difference Hessian.
- rngint, numpy.random.Generator, or None
For the proposals and the resampling.
- progressbool
Accepted for a common signature; unused.
Notes
In ILR coordinates the posterior of nearly empty bins has a long one-sided tail, so for more than a handful of bins the importance correction often fails (
k_hatabove the threshold) and the result is flagged approximate: the Laplace approximation is then a fast summary of well-populated bins, not a replacement for NUTS.- __init__(model, *, importance=True, n_proposals=None, df=5.0, inflate=1.0, step=1e-05, rng=None, progress=False)[source]¶
Methods
__init__(model, *[, importance, ...])Mode, covariance and Hessian in unconstrained coordinates.
run([n_samples])Draw
n_samples(approximately) from the posterior.unsupported(model)Why the engine cannot run on
model, orNonewhen it can.Attributes
whether the engine infers a selection from injections or a tallied response jointly
markovwhether its draws are Markov chains, described by R-hat and ESS
- joint = True¶
whether the engine infers a selection from injections or a tallied response jointly