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.

\(V_k \sim \mathrm{Beta}(a_k, b_k)\) for k = 1..K-1 and \(\rho_k = V_k \prod_{j<k} (1 - V_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 - 1 - k) * a for scalar a.

ordersequence of int, optional

Permutation of the bins defining the stick-breaking order.

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

Attributes

kind

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

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)