Reference / binference.samplers.MeanFieldVB

binference.samplers.MeanFieldVB

class binference.samplers.MeanFieldVB(model, *, tol=1e-09, max_iter=10000, rng=None, progress=False)[source]

Mean-field variational Bayes: \(q(\rho)\prod_i q(z_i)\).

Coordinate ascent alternates \(q(z_i) \propto L_{ik}\exp E_q[\log\rho_k]\) and the conjugate update of \(q(\rho)\) (e.g. a Dirichlet). This is the algorithm of RAIL’s VarInfStackSummarizer. It is fast but under- estimates posterior widths, severely so when per-object PDFs are broad compared with the bins (it ignores the correlation between labels and the population). Results are always flagged approximate=True and emit an ApproximationWarning; prefer NUTS for error bars.

With a selection function on fractions, the expected number of missed objects is plugged in at the current mean (an additional approximation).

No evidence lower bound is computed (with selection the plug-in update does not ascend one): iterations stop when the largest change of the mean is below tol times its largest value.

Parameters:
modelPopulationModel

Must use a conjugate prior.

tolfloat

Relative tolerance on the change of the mean.

max_iterint

Maximum number of coordinate-ascent iterations.

rngint, numpy.random.Generator, or None

For the draws from the variational posterior.

progressbool

Accepted for a common signature; unused.

__init__(model, *, tol=1e-09, max_iter=10000, rng=None, progress=False)[source]

Methods

__init__(model, *[, tol, max_iter, rng, ...])

fit()

Run coordinate ascent; returns (state, n_iter, converged).

run([n_samples])

Fit and return n_samples independent draws from the variational posterior.

unsupported(model)

Why the engine cannot run on model, or None when it can.

Attributes

approximate

joint

whether the engine infers a selection from injections or a tallied response jointly (DECISIONS #30, #80, #81)

markov

whether its draws are Markov chains, described by R-hat and ESS

name

fit()[source]

Run coordinate ascent; returns (state, n_iter, converged).

run(n_samples=4000)[source]

Fit and return n_samples independent draws from the variational posterior.

Parameters:
n_samplesint, optional

Draws from the variational posterior.

classmethod unsupported(model)[source]

Why the engine cannot run on model, or None when it can.

Parameters:
modelPopulationModel

The model to run on.