Reference / binference.Density
binference.Density¶
- class binference.Density(*, flat=None, values=None, per_volume=False, func=None, dist=None)[source]¶
A fixed probability density over the bin coordinate.
Build one with
flat(),from_masses(),from_densities(),from_function()orfrom_distribution(). Wherever a density is expected, the string"flat", a callable, a distribution object and an array are also accepted (seecoerce()).Methods
__init__(*[, flat, values, per_volume, ...])coerce(value[, representation, name])A
Densityfrom a density,"flat", a callable, a distribution or an array.flat([coordinate])Uniform in the measure coordinate
uof each axis (default) or inz.from_densities(densities)Density per unit
z-volume in each bin; masses are densities times volumes.from_distribution(dist)A distribution object with
cdf,logpdforpdf(e.g. frozenscipy.stats).from_function(func)A callable density of
z, averaged over each bin by quadrature.from_masses(masses)Probability mass per bin (normalised on use).
masses(bins, *[, tol, max_depth, n_sub])Normalised probability mass of each bin, shape
(K,).- classmethod coerce(value, representation=None, name='interim')[source]¶
A
Densityfrom a density,"flat", a callable, a distribution or an array.An array is read as masses or densities by
representation(which applies to arrays only). Without it the array is accepted only on bins where both readings agree (categories and bins of equal volume);masses()raises otherwise.- Parameters:
- valueDensity, “flat”, callable, distribution or array_like (K,)
What to read as a density.
- representation{“mass”, “density”}, optional
Whether an array holds masses or densities.
- namestr, optional
Name of the argument, used in error messages.
- classmethod flat(coordinate='measure')[source]¶
Uniform in the measure coordinate
uof each axis (default) or inz.On linear bins the two agree. On log bins, flat in
ugives equal mass per decade. On categories, every category has equal mass.- Parameters:
- coordinate{“measure”, “z”}, optional
Flat in the measure coordinate
uor inz.
- classmethod from_densities(densities)[source]¶
Density per unit
z-volume in each bin; masses are densities times volumes.- Parameters:
- densitiesarray_like (K,)
Non-negative density per bin.
- classmethod from_distribution(dist)[source]¶
A distribution object with
cdf,logpdforpdf(e.g. frozenscipy.stats).On 1-D grids a
cdfgives exact bin masses; otherwise the density is averaged over each bin by quadrature.- Parameters:
- distobject
A distribution with
cdf,logpdforpdf.
- classmethod from_function(func)[source]¶
A callable density of
z, averaged over each bin by quadrature.On grids
funcreceives points of shape(M,)(1-D) or(M, ndim); on categories it receives the category labels.- Parameters:
- funccallable
Non-negative density of
z.
- classmethod from_masses(masses)[source]¶
Probability mass per bin (normalised on use).
- Parameters:
- massesarray_like (K,)
Non-negative mass per bin.
- masses(bins, *, tol=0.001, max_depth=12, n_sub=None)[source]¶
Normalised probability mass of each bin, shape
(K,).Callables and distributions without a usable
cdfare integrated by adaptive quadrature totol(at mostmax_depthrefinements), or withn_subfixed Gauss-Legendre points per bin and axis (seeLikelihoods.from_density).- Parameters:
- binsBins
The bins.
- tolfloat, optional
Relative tolerance of the adaptive quadrature over each bin.
- max_depthint, optional
Most refinements of the adaptive quadrature.
- n_subint, optional
Fixed Gauss-Legendre points per bin and axis in place of adaptive quadrature.