Reference / binference.Basis

binference.Basis

class binference.Basis(bins, order=0, resolution=1, oversample=None)[source]

Components of the population model over reporting bins.

Parameters:
binsBins

The reporting bins. Categories take only the identity basis (the defaults).

order{0, 1}

B-spline order of the components: 0 flat in u on each cell, 1 linear (hats). See the module documentation.

resolutionint or sequence of int

Components per reporting bin along each axis (default 1).

oversampleint, optional

Quadrature cells per component and axis. They integrate likelihoods and selection functions against the components (default 1 for order 0, where the integrals are exact; for order 1, 8 in 1-D, 4 in 2-D and 2 in more dimensions).

Attributes:
binsBins

The reporting bins.

componentsBins

The component cells (the bins refined resolution times); priors are placed on these.

gridBins

The quadrature cells (the components refined oversample times).

grid_to_binsndarray (grid.K,)

The reporting bin of each quadrature cell.

matrixsparse array (K, C)

\(A_{jk}\), the mass of component k in reporting bin j; each column sums to one.

Examples

>>> import binference
>>> basis = binference.Basis(binference.Bins.linear(0, 3, 10), order=1)
>>> basis.K, basis.C
(10, 10)
__init__(bins, order=0, resolution=1, oversample=None)[source]

Methods

__init__(bins[, order, resolution, oversample])

axis_masses(bins)

Per-axis masses of the components' factors in the intervals of bins (no mask).

height(k, d, u)

Height (at most one) along axis d of the unnormalised components k at u; u has k's shape, or one more trailing axis of points per component.

masses(bins)

(bins.K, C) sparse masses \(A_{qk} = \int_{B_q} \psi_k\,du\) of the components in the cells \(B_q\) of bins (\(A\) when bins are the reporting bins).

support(k)

(lo, hi) in u of the supports of components k, each (n, ndim).

to_bins(weights)

Map component weights (..., C) to reporting-bin fractions (..., K).

Attributes

C

Number of components.

K

Number of reporting bins.

grid_masses

masses(self.grid): the components' masses in the quadrature cells (cached).

is_identity

True when the components are the bins themselves (order 0, resolution 1).

is_plain

True for the plain bins themselves: the identity with no finer quadrature cells (order 0, resolution 1, oversample 1).

shares

(C, K): each component's mass in each reporting bin (rows sum to one; cached).

property C

Number of components.

property K

Number of reporting bins.

axis_masses(bins)[source]

Per-axis masses of the components’ factors in the intervals of bins (no mask).

On unmasked bins masses() is their Kronecker product, so separable inputs can be projected one axis at a time.

Parameters:
binsBins

A grid covering the components’ range with the same measures: the reporting bins, the components, the quadrature grid or a refinement of them.

property grid_masses

masses(self.grid): the components’ masses in the quadrature cells (cached).

height(k, d, u)[source]

Height (at most one) along axis d of the unnormalised components k at u; u has k’s shape, or one more trailing axis of points per component.

A component’s shape is the product of its heights over the axes (one for flat components inside their cell).

Parameters:
kint or array_like of int

Component indices.

dint

Axis.

uarray_like

Points in u along axis d.

property is_identity

True when the components are the bins themselves (order 0, resolution 1).

property is_plain

True for the plain bins themselves: the identity with no finer quadrature cells (order 0, resolution 1, oversample 1).

masses(bins)[source]

(bins.K, C) sparse masses \(A_{qk} = \int_{B_q} \psi_k\,du\) of the components in the cells \(B_q\) of bins (\(A\) when bins are the reporting bins).

bins must cover the components’ range with the same measures (the reporting bins, the components or any refinement of them). Each column sums to one over the active cells of bins.

Parameters:
binsBins

A grid covering the components’ range with the same measures.

property shares

(C, K): each component’s mass in each reporting bin (rows sum to one; cached).

support(k)[source]

(lo, hi) in u of the supports of components k, each (n, ndim).

Parameters:
kint or array_like of int

Component indices.

to_bins(weights)[source]

Map component weights (..., C) to reporting-bin fractions (..., K).

Parameters:
weightsarray_like (…, C)

Component weights.