Skip to content

ExponentialClassFamily: conjugate prior support and posterior hyperparameters #50

@LeonidElkin

Description

@LeonidElkin

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_family object must expose parameters (“hyperparameters”) that can be updated in a generic way in posterior_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_hyperparameters in the chosen representation,
    • sample, a collection of observations x_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 n to 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

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions