Guides / Prepare your inputs
Prepare your inputs¶
binference needs one thing from your data. For each object \(i\) and bin \(k\) it needs
the bin-averaged likelihood \(L_{ik}\). That is how probable the object’s data are
if its true value lies in bin \(k\). A Likelihoods object holds these values
with their Bins. Its constructors turn the usual data products
into likelihoods.
Find your input¶
What you have for each object |
Constructor |
Page |
|---|---|---|
a measurement and its Gaussian error |
|
|
a likelihood function, or a SciPy distribution |
|
|
likelihood values per bin |
|
|
a posterior per bin, computed under some prior |
|
|
samples from a posterior or a likelihood |
|
|
a measured bin, or a classifier’s score or label |
|
If your code reports posteriors, they already contain a prior. Say which prior. Otherwise the fit biases the population toward that prior (Posteriors under an interim prior).
Bins¶
Every constructor takes the bins of the true value. Build them first:
import numpy as np
import binference
bins = binference.Bins.linear(0.0, 3.0, 30) # 30 equal bins on [0, 3]
logbins = binference.Bins.log(1e-2, 1e2, 20) # equal in log z
irregular = binference.Bins([0.0, 0.2, 0.5, 1.0, 3.0]) # explicit edges
grid = binference.Bins.grid(np.linspace(-0.5, 2.0, 26), np.linspace(-5.0, 15.0, 41))
classes = binference.Bins.categories(["star", "galaxy", "quasar"])
print(bins.K, grid.shape, grid.K, classes.labels)
Bins know their edges, centers and volumes (widths in 1-D), and index returns the
bin of each value. A 2-D grid is flattened in C order: unflatten and flatten move
between the vector of \(K\) values and the grid. Categories have unit volumes and no
geometry. Choose bins says how many bins to use and where to put them.