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 (a grid, not categories).

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(grid)

Per-axis masses of the components' factors in grid's intervals (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(grid)

(grid.K, C) sparse masses \(M_{qk} = \int_{B_q} \phi_k\,du\).

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(grid): the components' masses in the quadrature cells (cached).

is_identity

True when the components are the bins themselves (order 0, resolution 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(grid)[source]

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

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

Parameters:
gridBins

Grid covering the components’ range with the same measures.

property grid_masses

masses(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).

masses(grid)[source]

(grid.K, C) sparse masses \(M_{qk} = \int_{B_q} \phi_k\,du\).

grid 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 grid.

Parameters:
gridBins

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.