Conjugate Priors

Fast-BOCPD encapsulates likelihood–prior pairs inside observation models. Each model maintains sufficient statistics for the current run length and exposes a predictive density used by the BOCPD recursion. The table below summarises the conjugate pairs currently implemented (all definitions follow examples/math_foundation.md).

Observation model

Likelihood \(p(x \mid \theta)\)

Prior \(p(\theta)\)

Sufficient statistics (per run length)

Implementation (files)

Gaussian-NIG

Normal with unknown mean \(\mu\) and variance \(\sigma^2\)

Normal–Inverse-Gamma \((\mu,\sigma^2)\)

\(n\), \(\sum x\), \(\sum x^2\)

fast_bocpd/_c/gaussian_nig.{c,h}

Student-t (fixed \(\nu\))

Heavy-tailed Student-t (derived via Gaussian scale mixture)

Normal–Gamma on \((\mu,\tau)\)

Weighted sums \(S_0, S_1, S_2\)

student_t_ng.{c,h}

Student-t Grid

Mixture of Student-t components indexed by \(\nu_k\)

Same Normal–Gamma prior, discrete prior on \(\nu\)

Component stats + log weights

student_t_ng_grid.{c,h}

Bernoulli-Beta

Bernoulli \(x \in \{0,1\}\)

Beta \(\text{Beta}(\alpha_0,\beta_0)\)

\(n\), \(\sum x\)

bernoulli_beta.{c,h}

Binomial-Beta

Binomial with \(N\) trials per observation

Beta on success probability

\(n\), \(\sum k\)

binomial_beta.{c,h}

Poisson-Gamma

Poisson counts

Gamma on rate \(\lambda\)

\(n\), \(\sum x\)

poisson_gamma.{c,h}

Gamma-Gamma (fixed shape)

Gamma likelihood with known shape \(k\)

Gamma prior on rate

\(n\), \(\sum x\)

gamma_gamma_fixed_shape.{c,h}

Why Conjugacy?

The BOCPD recursion requires evaluating the posterior predictive \(P(x_t \mid x_t^{(r)})\). Conjugate priors yield closed-form updates:

\[p(\theta \mid x_t^{(r)}) \propto p(x_t^{(r)} \mid \theta) p(\theta),\]

and the predictive integrates parameters out analytically. In code terms:

  • *_prior_stats initialises sufficient statistics for a new segment.

  • *_update_stats increments the stats when a continuation branch is taken.

  • *_predictive_logpdf returns \(\log P(x_t \mid x_t^{(r)})\).

The Python classes under fast_bocpd.models expose the same hyperparameters, validate user input (finite/positive checks), and translate them to ctypes structures. The terminology “observation model” emphasises that the user chooses a pre-packaged likelihood–prior pair instead of writing custom probability code.

Adding new pairs requires defining the conjugate update, implementing the five functions above, wiring the model into bocpd_core.c’s virtual table, and adding a Python wrapper (see Adding New Models).