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\) |
|
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 Grid |
Mixture of Student-t components indexed by \(\nu_k\) |
Same Normal–Gamma prior, discrete prior on \(\nu\) |
Component stats + log weights |
|
Bernoulli-Beta |
Bernoulli \(x \in \{0,1\}\) |
Beta \(\text{Beta}(\alpha_0,\beta_0)\) |
\(n\), \(\sum x\) |
|
Binomial-Beta |
Binomial with \(N\) trials per observation |
Beta on success probability |
\(n\), \(\sum k\) |
|
Poisson-Gamma |
Poisson counts |
Gamma on rate \(\lambda\) |
\(n\), \(\sum x\) |
|
Gamma-Gamma (fixed shape) |
Gamma likelihood with known shape \(k\) |
Gamma prior on rate |
\(n\), \(\sum x\) |
|
Why Conjugacy?
The BOCPD recursion requires evaluating the posterior predictive \(P(x_t \mid x_t^{(r)})\). Conjugate priors yield closed-form updates:
and the predictive integrates parameters out analytically. In code terms:
*_prior_statsinitialises sufficient statistics for a new segment.*_update_statsincrements the stats when a continuation branch is taken.*_predictive_logpdfreturns \(\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).