mixle.inference.blackbox module¶
Black-box likelihood/posterior curvature approximations for composable model parameters.
The conjugate path needs a registered closed form; the autograd VI/NUTS path needs a per-family
from-parameters scorer (so it covers flat models + mixtures of leaves). Neither works for an arbitrary
composable model. This module does: it treats a fitted model’s parameters as the latent, flattens them
to an UNCONSTRAINED vector (positive params via log, unit via logit, simplex via softmax), and fits a
Gaussian approximation in that space from a finite-difference Hessian of the model’s own
seq_log_density – which every model has. With an explicit log prior this is a Laplace posterior;
without one it is a likelihood-curvature approximation and is labelled accordingly.
post = laplace_posterior(fitted_model, data) post.sample(…) # parameter draws (a fitted model per draw) post.cov # unconstrained-space posterior covariance
Coverage is the parameter round-trip in _flatten() – the scalar exponential-family leaves, the
Categorical simplex, plus Composite, Mixture and HeterogeneousBayesianNetwork
(recursively), so heterogeneous records, mixtures-of-anything, and learned Bayesian networks (categorical
CPTs + conditional-linear-Gaussian coefficients) are covered out of the box. It is extensible exactly
like register_family: add a leaf’s
(extract, rebuild) and every composite over it works. A model whose structure is not yet flattenable
raises a clear error rather than returning a wrong answer.
- class LaplacePosterior(mode_model, u_mode, cov, rebuild, metadata)[source]
Bases:
objectValidated Gaussian Laplace approximation in unconstrained parameter space.
The compatibility name is retained, but
is_posterioris true only when the target included an explicit prior.
- laplace_posterior(model, data, *, log_prior=None, eps=1e-4, ridge=1e-6, mode_tol=1e-3)[source]
Build a validated Laplace approximation around
model’s parameters.log_prioris evaluated in the flattened unconstrained coordinates. If supplied, the target is the log posterior; otherwise the result is explicitly a likelihood-curvature approximation, despite the compatibility name of this function and result class.