Reference / binference.priors.Dirichlet

binference.priors.Dirichlet

class binference.priors.Dirichlet(alpha=1.0)[source]

Dirichlet prior \(\rho \sim \mathrm{Dir}(\alpha)\) on bin fractions.

The default prior of binference (alpha=1, uniform on the simplex).

Parameters:
alphafloat, array_like (K,), or “reference”

Concentration parameters (strictly positive). "reference" uses alpha = 1/K (Berger, Bernardo & Sun 2015), which avoids swamping sparse problems with many bins.

Notes

A symmetric alpha over bins of unequal volume is not consistent under merging bins; from_base_measure() makes alpha proportional to a base measure (flat in the measure coordinate by default) instead.

__init__(alpha=1.0)[source]

Methods

__init__([alpha])

bind(bins)

describe(bins[, counts])

The prior as a one-node tree, drawn as text (see DirichletTree.describe()).

from_base_measure([concentration, base])

alpha_k = concentration * B_k, with B the normalised bin masses of base.

from_counts(counts[, strength, base])

Prior from a reference sample: alpha = base + strength * counts.

reference([K])

Reference prior alpha = 1/K.

resolve_alpha(bins)

Attributes

kind

"fractions" (a distribution on the simplex) or "rates"

describe(bins, counts=None)[source]

The prior as a one-node tree, drawn as text (see DirichletTree.describe()).

Parameters:
binsBins

The bins it is drawn on.

countsarray_like (K,), optional

Counts per bin; the drawing then shows the posterior given them.

classmethod from_base_measure(concentration=1.0, base='flat')[source]

alpha_k = concentration * B_k, with B the normalised bin masses of base.

base is a Density (or anything Density.coerce accepts; an array is read as masses per bin). The default is flat in the measure coordinate, proportional to bin volumes on linear bins.

Parameters:
concentrationfloat, optional

Total concentration, spread over the bins by the base measure.

baseDensity, str, callable or array_like, optional

Base measure whose bin masses shape alpha.

classmethod from_counts(counts, strength=1.0, base=1.0)[source]

Prior from a reference sample: alpha = base + strength * counts.

strength < 1 down-weights a reference sample that may not be fully representative (for a coherent model of an unrepresentative reference use a reference-centred LogisticNormal or LogisticRandomWalk with mean=log(reference)).

Parameters:
countsarray_like (K,)

Counts of the reference sample in each bin.

strengthfloat, optional

Weight of the reference counts in alpha.

basefloat, optional

Concentration added to every bin.

classmethod reference(K=None)[source]

Reference prior alpha = 1/K.

Parameters:
Kint, optional

Number of bins; None takes it from the bins when the prior is bound.