Conjugate marginals¶
The closed-form marginals of the standard conjugate pairs.
conjugate
¶
Closed-form marginals of the standard conjugate pairs.
A conjugate pair is a parent site whose value is the parameter of a
child site: z ~ Beta(a, b); y ~ Bernoulli(z) and its kin. The child's
marginal, with the parent integrated out, has a closed form for the four
pairs documented in
Bernardo and Smith (1994):
Normal-Normal, Beta-Bernoulli, Gamma-Poisson, and Dirichlet-Categorical.
The solvers here compute those marginals from the parent's distribution
parameters and the child's value, and check that the child is the
identity-link form the marginal is derived for.
CONJUGATE_SOLVERS
module-attribute
¶
CONJUGATE_SOLVERS: Mapping[tuple[str, str], Solver] = {('Normal', 'Normal'): normal_normal, ('Beta', 'Bernoulli'): beta_bernoulli, ('Gamma', 'Poisson'): gamma_poisson, ('Dirichlet', 'Categorical'): dirichlet_categorical}
The closed-form solvers, keyed by (prior family, likelihood family).
Solver
¶
Solver = Callable[[Mapping[str, Tensor], Tensor, TorchSampleable, Tensor], Tensor]
A closed-form marginal: given the parent's parameters, the parent's drawn value, the child's sampleable at that value, and the child's value, the log marginal density of the child's value.
family_of
¶
family_of(sampleable: TorchSampleable) -> str
The registry family a sampleable's morphism draws from.
| PARAMETER | DESCRIPTION |
|---|---|
sampleable
|
The sampleable.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The family's registry name. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the morphism's class is registered for no family. |
Source code in src/quivers/effects/conjugate.py
normal_normal
¶
normal_normal(parent: Mapping[str, Tensor], parent_value: Tensor, child: TorchSampleable, value: Tensor) -> Tensor
The marginal of y ~ Normal(z, tau) under z ~ Normal(mu, sigma).
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent's
TYPE:
|
parent_value
|
The parent's drawn value.
TYPE:
|
child
|
The child at the parent's drawn value, whose
TYPE:
|
value
|
The child's value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the child's location is not the parent's value. |
Source code in src/quivers/effects/conjugate.py
beta_bernoulli
¶
beta_bernoulli(parent: Mapping[str, Tensor], parent_value: Tensor, child: TorchSampleable, value: Tensor) -> Tensor
The marginal of y ~ Bernoulli(z) under z ~ Beta(a, b).
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent's
TYPE:
|
parent_value
|
The parent's drawn value.
TYPE:
|
child
|
The child at the parent's drawn value.
TYPE:
|
value
|
The child's value, zero or one.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the child's probability is not the parent's value. |
Source code in src/quivers/effects/conjugate.py
gamma_poisson
¶
gamma_poisson(parent: Mapping[str, Tensor], parent_value: Tensor, child: TorchSampleable, value: Tensor) -> Tensor
The marginal of y ~ Poisson(z) under z ~ Gamma(alpha, beta).
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent's
TYPE:
|
parent_value
|
The parent's drawn value.
TYPE:
|
child
|
The child at the parent's drawn value.
TYPE:
|
value
|
The child's count.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The negative binomial log mass with |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the child's rate is not the parent's value. |
Source code in src/quivers/effects/conjugate.py
dirichlet_categorical
¶
dirichlet_categorical(parent: Mapping[str, Tensor], parent_value: Tensor, child: TorchSampleable, value: Tensor) -> Tensor
The marginal of y ~ Categorical(z) under z ~ Dirichlet(alpha).
| PARAMETER | DESCRIPTION |
|---|---|
parent
|
The parent's
TYPE:
|
parent_value
|
The parent's drawn value.
TYPE:
|
child
|
The child at the parent's drawn value.
TYPE:
|
value
|
The child's category.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the child's probabilities are not the parent's value. |
Source code in src/quivers/effects/conjugate.py
conjugate_solver
¶
conjugate_solver(parent_family: str, child_family: str) -> Solver
The solver of a conjugate pair.
| PARAMETER | DESCRIPTION |
|---|---|
parent_family
|
The parent's family.
TYPE:
|
child_family
|
The child's family.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Solver
|
The closed-form marginal. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the pair has no registered marginal. |