Reference / binference.priors.DirichletTree

binference.priors.DirichletTree

class binference.priors.DirichletTree(tree, alpha=1.0)[source]

Dirichlet-tree prior: independent Dirichlet splits along a tree of bins.

Generalises the Dirichlet (a single node) and the generalised Dirichlet (a “caterpillar” tree). Bins grouped under the same internal node can be positively correlated, and each split has its own concentration. Conjugate given latent counts.

Parameters:
treenested lists, or dicts of named groups

The groups of bins. A group is a list of members, or a dict from group names to members; a member is a group or a bin. Bins are indices 0..K-1 or, on categorical bins, their labels, and each appears exactly once. A named group of one member is that member. E.g. [[0, 1], [2, [3, 4]]], or {"spiral": ["Sa", "Sb"], "early": {"elliptical": ["E0", "E3"], "lenticular": ["S0"]}}.

alphafloat, sequence of arrays, or dict

A single concentration for every branch; one array per internal node (in pre-order, i.e. parents before children, left to right) with one value per member; or a dict from group names, and bins as the tree writes them, to the concentration of the branch leading into each, every other branch keeping 1.

Examples

>>> import binference
>>> prior = binference.priors.DirichletTree([[0, 1], [2, [3, 4]]], alpha=2.0)
>>> groups = {
...     "spiral": ["Sa", "Sb"],
...     "early": {"elliptical": ["E0", "E3"], "lenticular": ["S0"]},
... }
>>> named = binference.priors.DirichletTree(groups, alpha={"spiral": 3.0})
__init__(tree, alpha=1.0)[source]

Methods

__init__(tree[, alpha])

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)