Reference / binference.Measure

binference.Measure

class binference.Measure(name, forward, inverse, key, table=None)[source]

A strictly increasing map u = T(z) of one bin axis.

Build one with linear(), log(), transform() (a function and its inverse), density() (a positive density g(z), whose cumulative integral is the map) or tabulated(). Strings "linear" and "log" are accepted wherever a measure is.

__init__(name, forward, inverse, key, table=None)[source]

Methods

__init__(name, forward, inverse, key[, table])

coerce(measure)

A Measure from a measure or one of the names "linear" and "log".

density(g, lo, hi[, n])

The map whose derivative is the positive density g on [lo, hi].

forward(z)

u = T(z).

inverse(u)

z = T^{-1}(u).

linear()

u = z: flat within bins in the bin coordinate itself.

log()

u = log z (z > 0): flat within bins in the logarithm.

log_jacobian(z)

log dT/dz: the log of the within-bin population density in z, up to a constant.

tabulated(z, u[, name])

A piecewise-linear map through the points (z, u), both strictly increasing.

transform(forward, inverse[, name])

A user map u = forward(z) with its inverse; both take and return arrays.

Attributes

name

is_named

Whether this is one of the built-in measures "linear" and "log".

classmethod coerce(measure)[source]

A Measure from a measure or one of the names "linear" and "log".

Parameters:
measureMeasure or {“linear”, “log”}

A measure or its name.

classmethod density(g, lo, hi, n=4097)[source]

The map whose derivative is the positive density g on [lo, hi].

T(z) = integral of g from lo to z, computed by the trapezoidal rule on n points and interpolated linearly, as is its inverse.

Parameters:
gcallable

Positive density, evaluated on an array of z.

lo, hifloat

Range of z the map covers.

nint, optional

Points of the trapezoidal rule that tabulates the map.

forward(z)[source]

u = T(z).

Parameters:
zarray_like

Values of the bin coordinate.

inverse(u)[source]

z = T^{-1}(u).

Parameters:
uarray_like

Values of the measure coordinate.

property is_named

Whether this is one of the built-in measures "linear" and "log".

classmethod linear()[source]

u = z: flat within bins in the bin coordinate itself.

classmethod log()[source]

u = log z (z > 0): flat within bins in the logarithm.

log_jacobian(z)[source]

log dT/dz: the log of the within-bin population density in z, up to a constant.

Exact for linear, log and tabulated measures; a central difference for transform().

Parameters:
zarray_like

Values of the bin coordinate.

classmethod tabulated(z, u, name='tabulated')[source]

A piecewise-linear map through the points (z, u), both strictly increasing.

Parameters:
z, uarray_like

Points of the map, at least two.

namestr, optional

Name shown for the measure.

classmethod transform(forward, inverse, name='transform')[source]

A user map u = forward(z) with its inverse; both take and return arrays.

Parameters:
forward, inversecallable

The map z -> u and its inverse, strictly increasing.

namestr, optional

Name shown for the measure.