-
Notifications
You must be signed in to change notification settings - Fork 2
Description
ExponentialClassFamily: conjugate prior support and posterior hyperparameters
Task
Extend ExponentialClassFamily with a generic interface for conjugate priors and posterior hyperparameter updates.
Requirements
1. Conjugate prior family property
Add a property:
conjugate_prior_family(likely marked with@property),
which returns a ParametricFamily (or a subclass) representing the conjugate prior over the natural parameter (or over the model parameter, depending on design).
Expected shape (conceptually):
- if the model has density
f(x, θ) = h(x) * exp(<η(θ), T(x)> + A(θ)), - then the conjugate prior over the natural parameter
ηoften has log-density of the form
log π(η | α, β) = <η, α> + β * A(η) + const,
whereα,βare hyperparameters.
You do not need to fix a specific parametric form in this sub-issue, but:
- the
conjugate_prior_familyobject must expose parameters (“hyperparameters”) that can be updated in a generic way inposterior_hyperparameters.
2. Hyperparameter representation
Introduce a small, explicit representation of hyperparameters for the conjugate prior, for example:
- a dataclass-like structure
ExponentialConjugateHyperparameters, - or a clearly documented dictionary schema (
{"alpha": ..., "beta": ...}).
This structure will be the input and output of posterior_hyperparameters.
3. posterior_hyperparameters method
Add a method:
posterior_hyperparameters(prior_hyperparameters, sample),
which:
- takes:
prior_hyperparametersin the chosen representation,sample, a collection of observationsx_1, ..., x_n,
- returns:
- updated hyperparameters corresponding to the posterior.
In general exponential-family theory, for canonical parametrization:
- the posterior hyperparameters are obtained by:
- adding the sum of sufficient statistics to the “α-like” hyperparameter,
- adding the sample size
nto the “β-like” hyperparameter (or equivalent).
You should:
- implement this generic update rule in terms of:
T(x)(sufficient statistics),- the sample size
n = len(sample), - the prior hyperparameters.
Do not hard-code anything specific to a concrete family (Normal, Bernoulli, etc.) in this method.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status