Reference / binference.priors.PolyaTree

binference.priors.PolyaTree

class binference.priors.PolyaTree(c=1.0, power=2.0, base='flat')[source]

Finite Polya-tree prior on an ordered 1-D grid (a balanced binary Dirichlet-tree).

Bins are split recursively into halves by bin index (the larger half first when a group has an odd number of bins), whatever the base measure. With a base far from flat, the two halves of a split can carry very different masses. A split at level \(h\) (root = 1) has Beta concentrations \(c_{\rm PT}\,h^{p_{\rm PT}}\cdot 2 G_0(\text{child})/G_0(\text{parent})\), so the prior mean is the base measure \(G_0\) and fluctuations shrink at finer scales (power=2 gives absolutely continuous limits; Lavine 1992). A conjugate, multi-scale alternative to smoothness priors.

Parameters:
cfloat

Overall concentration \(c_{\rm PT}\) (larger = closer to the base measure).

powerfloat

Growth exponent \(p_{\rm PT}\) of concentration with depth \(h\).

baseDensity, “flat”, callable or array_like (K,)

Base measure, read by Density.coerce (an array is masses per bin). The default is flat in the measure coordinate.

__init__(c=1.0, power=2.0, base='flat')[source]

Methods

__init__([c, power, base])

bind(bins)

describe(bins[, counts])

The tree on bins, drawn as text.

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)