Skip to contents

A posterior wraps a trained npe() fit together with (optionally) a default observation x_obs. It knows how to draw posterior samples, evaluate the posterior log-density, and find the maximum-a-posteriori (MAP) estimate. All transforms between standardized training space and the original parameter space are handled internally.

The three inference methods reach a posterior by different routes, and posterior() hides the difference. An npe() fit already is a posterior estimator, so the returned object samples with a forward pass. An nle() fit only knows the likelihood and an nre() fit only the likelihood ratio, so both return an object that samples with MCMC and takes the extra arguments that implies.

Usage

posterior(fit, x_obs = NULL, ...)

# Default S3 method
posterior(fit, x_obs = NULL, ...)

# S3 method for class 'nsbi_npe'
posterior(fit, x_obs = NULL, ...)

Arguments

fit

An nsbi_npe object from npe() or npe_sequential(), an nsbi_nle object from nle(), or an nsbi_nre object from nre().

x_obs

Optional default observation to condition on. If supplied it becomes the default x for sample(), log_prob() and map_estimate(). For an NLE or NRE fit, rows of x_obs are independent observations.

...

Passed to methods. See posterior.nsbi_nle() and posterior.nsbi_nre() for the MCMC controls those fits accept.

Value

An nsbi_posterior object.

Details

For bounded priors, samples that fall outside the prior support are rejected ("leakage" correction), and log_prob() is renormalized by the estimated acceptance probability so it integrates to one over the support.

See also

save_npe(), which is how a torch-backed fit gets to disk and back; readRDS() returns one whose network is dead, and posterior() says so rather than failing later.