Reference / binference.infer
binference.infer¶
- binference.infer(likelihoods, prior=None, *, bins=None, selection=None, selection_mode=None, method='auto', n_samples=None, rng=None, progress=False, check=True, **engine_kwargs)[source]¶
Infer a population distribution from per-object likelihoods in one call.
- Parameters:
- likelihoodsLikelihoods, PopulationModel, or array_like (N, K)
Per-object likelihoods over bins (see
Likelihoodsfor converting posteriors, samples, Gaussian measurements, response matrices or classifier outputs). A raw array is treated as likelihoods over categorical bins (orbins).- priorPopulationPrior, optional
Population prior (default
Dirichlet(1.0)). UseGammaRatesto infer rates.- binsBins, optional
Bins for a raw array input.
- selectionarray_like (K,), callable or Selection, optional
Detection probability (fractions) or exposure (rates) per bin.
- selection_mode{“on_measurement”, “on_truth”}, optional
Required with an array or callable
selection(seeSelection).- method{“auto”, “nuts”, “gibbs”, “map”, “em”, “laplace”, “vb”, “bootstrap”}
Inference engine.
"auto"(default) picks Gibbs, Laplace or NUTS from rules set by a benchmark of the engines (Auto); its optionstarget_ess,gibbs_max_missing,max_gibbs_drawsandnnz_limitgo inengine_kwargs, and the choice and its reason are inresult.info["auto_method"]andresult.info["auto_reason"]."nuts"samples the exact posterior with any prior;"em"is MAP by EM on the simplex (algorithm="em") rather than mix-SQP; it needs a conjugate prior, and a jointly inferred selection or response runs L-BFGS.- n_samplesint, optional
Draws per chain (NUTS, Gibbs, and
"auto") or in total (Laplace, VB, bootstrap). Under"auto"it fixes the run length (seeAuto).- rngint, numpy.random.Generator, or None
Random number generator or seed (SPEC 7).
- progressbool
Show progress bars.
- checkbool
Warn about convergence problems after sampling (NUTS, Gibbs).
- **engine_kwargs
Passed to the engine (e.g.
n_chains,n_warmup,target_acceptfor NUTS; seebinference.samplers).
- Returns:
- PopulationResult or PointEstimate
Posterior draws, or the MAP estimate for
method="map"and"em".
Examples
>>> import numpy as np, binference >>> rng = np.random.default_rng(1) >>> bins = binference.Bins.linear(0.0, 1.0, 5) >>> z = rng.uniform(0, 1, 300) >>> lk = binference.Likelihoods.from_gaussian(z + rng.normal(0, 0.05, 300), 0.05, bins) >>> res = binference.infer(lk, rng=0) >>> res.mean.shape (5,)