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 matrix inflate**2 times \((-H)^{-1}\) (see df) are mapped to the simplex (or rates) and, with importance=True, resampled towards the exact posterior by Pareto-smoothed importance weights. The result is flagged approximate=True when info["k_hat"] reaches info["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); None uses 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_hat above 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_and_covariance()

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, or None when it can.

Attributes

joint

whether the engine infers a selection from injections or a tallied response jointly

markov

whether 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

mode_and_covariance()[source]

Mode, covariance and Hessian in unconstrained coordinates.

run(n_samples=4000)[source]

Draw n_samples (approximately) from the posterior.

Parameters:
n_samplesint, optional

Draws returned in total.