
Check the arguments of an MCMC-sampled posterior and assemble it
Source:R/nle_posterior.R
mcmc_posterior.RdShared by posterior.nsbi_nle() and posterior.nsbi_nre(). Both wrap a fit
and a sampler configuration around a draw cache, and every argument except
the sampler is checked the same way; only the class they carry and the
samplers they allow differ, and both of those are settled by the caller
before it gets here.
Usage
mcmc_posterior(
fit,
x_obs,
sampler,
n_chains,
warmup,
thin,
init_strategy,
seed,
max_batch,
dots,
class
)Arguments
- fit
An
nsbi_nleobject fromnle().- x_obs
Observation to condition on. Rows are treated as independent observations from the same parameter, and the log-likelihood sums over them.
- sampler
"slice"(the default) or"stan".- n_chains
Number of chains. The default depends on the sampler: 20 for
"slice", which evaluates every chain in one batched call per step and so pays almost nothing for more of them, and 4 for"stan", where each chain is a separate process with its own warmup to pay for.- warmup
Steps discarded at the start of each chain.
- thin
Keep one draw in
thin. The default is 2: the slice width is adapted during warmup, and with that the retained draws are already close to independent – on a Gaussian target with 20 chains,thin = 2gives a bulk ESS of about 96% of them. Since each evaluation is a forward pass over every observation, thinning harder buys very little for what it costs. Raise it if the reported ESS says you need to. (Pythonsbithins by 1 by default; it thinned by 10 up to v0.21.)- init_strategy
"resample"(default, andsbi's) weights a pool of prior draws by the posterior density and resamples the starting points from it, drawing more pools as needed if the first one lands fewer thann_chainsdraws in the posterior's support;"proposal"skips the weighting and keeps whichever prior draws land inside the posterior's support, also drawing more pools as needed."proposal"is cheaper per accepted draw, but every draw the posterior excludes is wasted: if only a fractionaof the prior's mass survives, roughly1 / adraws are needed per starting point, so a posterior that rules out most of the prior can make"proposal"far slower than"resample"to find enough starting points, and it errors out once its draw budget is spent. The pool is 1000 draws, set withn_pool.sbiuses 10,000 per chain, which on a surrogate summed over thousands of observations is a large bill before the first MCMC step.- seed
Optional integer seed.
- max_batch
Largest number of
(theta, x)pairs evaluated in one call to the estimator, both at every MCMC step and inlog_prob(). Only affects memory and speed; seemax_batchonlog_lik()for the same knob on a direct likelihood evaluation.- dots
The sampler arguments the caller collected from
....- class
The posterior class to stamp on the result.