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_npeobject fromnpe()ornpe_sequential(), annsbi_nleobject fromnle(), or annsbi_nreobject fromnre().- x_obs
Optional default observation to condition on. If supplied it becomes the default
xforsample(),log_prob()andmap_estimate(). For an NLE or NRE fit, rows ofx_obsare independent observations.- ...
Passed to methods. See
posterior.nsbi_nle()andposterior.nsbi_nre()for the MCMC controls those fits accept.
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.
