Reference / binference.priors.GeneralizedDirichlet

binference.priors.GeneralizedDirichlet

class binference.priors.GeneralizedDirichlet(a=1.0, b=None, order=None)[source]

Generalised Dirichlet (Connor & Mosimann 1969) via stick-breaking Betas.

\(\nu_k \sim \mathrm{Beta}(a_k, b_k)\) for k = 1..K-1 and \(\rho_k = \nu_k \prod_{j<k} (1 - \nu_j)\), breaking sticks in bin order (or order). It reduces to \(\mathrm{Dir}(\alpha_1, \dots, \alpha_K)\) with \(a_k = \alpha_k\) and \(b_k = \sum_{j>k}\alpha_j\), the sum including \(\alpha_K\); other choices give more flexible (including positive) correlations.

Parameters:
afloat or array_like (K-1,), optional

First Beta parameter of each stick.

bfloat or array_like (K-1,), optional

Second Beta parameter of each stick. None gives the Dirichlet-equivalent b_k = (K - k) * a for scalar a.

ordersequence of int, optional

Permutation of the bins defining the stick-breaking order; bin order by default on 1-D bins, and required on a grid of two or more dimensions. An order fits one number of bins, so binning_bias at a finer resolution needs its own prior=.

Notes

The bin taken by stick \(k\) (in stick order) has prior mean \(\bar\nu_k\prod_{j<k}(1-\bar\nu_j)\) with \(\bar\nu_k = a_k/(a_k+b_k)\), and the last bin \(\prod_{j<K}(1-\bar\nu_j)\). Equal a and b on every stick therefore halve the mean from each stick to the next, the last two bins equal. from_base_measure() sets a and b from a target mean instead.

__init__(a=1.0, b=None, order=None)[source]

Methods

__init__([a, b, order])

bind(bins)

describe(bins[, counts])

The tree on bins, drawn as text.

from_base_measure([concentration, base, order])

Sticks whose means give the bin masses of base as the prior mean.

describe(bins, counts=None)

The tree on bins, drawn as text.

Each line is a branch: its concentration α, the share of its parent it takes on average, the mean fraction of the population below it, and the bins it leads to. With counts the drawing shows the posterior given them, each branch’s concentration raised by the counts of the bins below it.

Parameters:
binsBins

The bins it is drawn on.

countsarray_like (K,), optional

Counts per bin.

Examples

>>> import binference
>>> bins = binference.Bins.linear(0.0, 1.0, 4)
>>> print(binference.priors.PolyaTree().describe(bins))
PolyaTree: prior, on 4 bins
root: bins 0–3
├── α=1  share 0.50  mass 0.500  bins 0–1
│   ├── α=4  share 0.50  mass 0.250  bin 0 [0, 0.25)
│   └── α=4  share 0.50  mass 0.250  bin 1 [0.25, 0.5)
└── α=1  share 0.50  mass 0.500  bins 2–3
    ├── α=4  share 0.50  mass 0.250  bin 2 [0.5, 0.75)
    └── α=4  share 0.50  mass 0.250  bin 3 [0.75, 1)
classmethod from_base_measure(concentration=2.0, base='flat', order=None)[source]

Sticks whose means give the bin masses of base as the prior mean.

Stick \(k\) takes the share \(\bar\nu_k = B_k / \sum_{j \ge k} B_j\) of the stick left, in stick order, with B the bin masses of base, and \(a_k + b_k\) = concentration. Every stick then has the same concentration, unlike a Dirichlet, whose sticks lose concentration as they break. a and b are None; binding derives them from the base.

Parameters:
concentrationfloat or array_like (K-1,), optional

\(a_k + b_k\) of each stick. The default, 2, matches a uniform Beta when the stick’s mean is 1/2.

baseDensity, str, callable or array_like, optional

Base measure whose bin masses are the prior mean, as for Dirichlet.from_base_measure(); flat in the measure coordinate by default.

ordersequence of int, optional

Stick-breaking order, as for the class.