API reference¶
Everything a typical analysis needs is importable from the top-level binference
namespace; priors, engines and helpers live in sub-modules. The names are grouped by
what you are doing.
Inferring a population¶
infer fits a population in one call; the estimator wraps the same fit for
scikit-learn, and the model holds the inputs of a fit for reuse.
Infer a population distribution from per-object likelihoods in one call. |
|
Population inference with the scikit-learn estimator conventions. |
|
Likelihoods + prior (+ selection): the object every inference engine works on. |
Inputs and bins¶
The bins, how volume is measured in them, and the per-object likelihoods and response that a fit takes.
The bins (or categories) over which populations and likelihoods are defined. |
|
Components of the population model over reporting bins. |
|
A strictly increasing map |
|
A fixed probability density over the bin coordinate. |
|
Bin-averaged per-object likelihoods \(L_{ik} \propto p(d_i \mid z_i \in B_k)\). |
|
The probability of each measured bin, and of being observed, given the true bin. |
Priors¶
Priors on the population fractions or rates; pass one to infer as prior=.
Dirichlet prior \(\rho \sim \mathrm{Dir}(\alpha)\) on bin fractions. |
|
Generalised Dirichlet (Connor & Mosimann 1969) via stick-breaking Betas. |
|
Dirichlet-tree prior: independent Dirichlet splits along a tree of bins. |
|
Finite Polya-tree prior on an ordered 1-D grid (a balanced binary Dirichlet-tree). |
|
Logistic-normal prior on the population fractions. |
|
Random-walk (intrinsic GMRF) smoothness prior on log-fractions over a grid. |
|
Gaussian-process prior on log-fractions over a 1-D or N-D grid. |
|
Independent Gamma priors on per-bin rates, \(\lambda_k \sim \mathrm{Gamma}(a_k, b_k)\). |
Hyperpriors for the hyperparameters of the logistic priors are parametrised on the log scale internally; pass a plain number to fix a hyperparameter.
Half-normal prior with scale |
|
Log-normal prior: |
|
Inverse-gamma prior with shape |
|
Gamma prior with shape |
|
A hyperparameter held fixed at |
A new prior subclasses one of these base classes; bind returns its numerical form.
Base class for priors on population fractions or rates. |
|
Numerical interface of a prior bound to specific bins (internal). |
|
Base class for priors on a positive scalar hyperparameter. |
Selection¶
Which objects enter the sample, given their true or measured values; pass a
Selection to infer as selection=.
Per-bin detection probability (fractions) or exposure (rates), with its mode. |
Normalise user input: |
|
The values of |
|
The values of |
Engines¶
infer(..., method=...) builds one of these for you; use them directly for fine
control, generator-style sampling or resuming a run.
No-U-Turn Sampler on the exact posterior, for every prior. |
|
Data-augmentation Gibbs sampler (the "hierarchical" sampler). |
|
Maximum a posteriori (or maximum-likelihood) estimate of the population. |
|
Gaussian (Laplace) approximation in unconstrained coordinates. |
|
Mean-field variational Bayes: \(q(\rho)\prod_i q(z_i)\). |
|
Bootstrap over objects of the MAP / maximum-likelihood estimator. |
|
Base class of all inference engines. |
method="auto", the default, is an engine that picks one of the others; METHODS
maps each method= name to its engine.
Picks Gibbs, Laplace or NUTS from rules set by a benchmark of the engines. |
|
Registry of inference methods accepted by |
Results and summaries¶
What a fit returns: posterior draws or a point estimate, and their summary table.
Posterior draws of a population (fractions and, for rate models, rates). |
|
A MAP / maximum-likelihood estimate of the population. |
|
A small per-bin summary table with a readable |
Diagnostics and validation¶
Checks of a single fit: convergence of draws, importance sampling for approximations, and optimality of a point estimate.
Rank-normalised split R-hat (maximum of bulk and folded/tail versions). |
|
Effective sample size of a scalar quantity. |
|
Monte Carlo standard error of the mean of a scalar quantity. |
|
Integrated autocorrelation time with Sokal's adaptive window. |
|
Normalised autocorrelation function of a 1-D chain (or average over chains). |
|
Pareto-smoothed importance sampling. |
|
The Pareto |
|
Kish's effective sample size of importance weights, \((\sum_s w_s)^2 / \sum_s w_s^2\) (normalised or not). |
|
First-order optimality violation of a point estimate. |
|
Largest fraction of missing information. |
Checks of a method: exact posteriors for small problems, simulation-based calibration and coverage.
Quadrature posterior of the fractions for |
|
Simulation-based calibration. |
|
Empirical coverage of central credible intervals over simulated data sets. |
|
Posterior on quadrature nodes over the simplex ( |
|
Ranks from simulation-based calibration. |
|
Empirical coverage of central credible intervals. |
Simulation¶
Mock data sets with a known truth, for trying a method before it meets real data.
A 1-D mock catalogue with heteroscedastic Gaussian measurement errors. |
|
A 2-D mock catalogue (e.g. a colour-magnitude-like ridge) with Gaussian errors. |
|
A quantification problem: classifier outputs over unordered classes. |
|
An unfolding problem: an exponential spectrum smeared by a detector. |
|
A simulator |
|
Population fractions per bin from a density name, |
|
A mock catalogue: bins, likelihoods, truth and alternative input forms. |
|
The true population and objects behind a mock catalogue. |
Plotting¶
Figures of a population, its draws, the per-object posteriors and calibration.
Plot a population posterior: bands for 1-D bins, images for 2-D grids, bars for categories. |
|
Corner plot of the fractions (or |
|
Trace plots of the fractions (or |
|
Compare object |
|
Rank histograms from |
|
The coral of single objects and samples in the binference docs (their brand |
Saving and loading¶
Write a result to disk, read it back, or convert it to an xarray DataTree for ArviZ.
Save a result to a compressed |
|
Load a result saved with |
|
Arrays and metadata of a result as a plain dictionary: what |
|
Convert to an |
Warnings¶
The warnings binference emits, and the error a strict convergence check raises.
Base class for all binference warnings. |
|
Inputs look inconsistent with the declared conventions. |
|
A sampler or optimiser shows signs of non-convergence. |
|
A result comes from an approximation with known failure modes. |
|
|