protocol
Protocols for Bayesian online components.
This module defines structural typing interfaces (PEP 544 protocols) used by
Bayesian online change-point detection algorithms. The three protocols –
IBayesianCPF, IHazard, and ILikelihood – describe the contracts
that concrete component implementations must satisfy.
Public API
IBayesianCPF– Protocol for scalar change-point score functions. Converts a run-length log-posterior vector into a single detection score. Seecpf.pyfor method details.IHazard– Protocol for hazard models. Returns log-hazard and log-survival arrays given run-length indices. Seehazard.pyfor method details.ILikelihood– Protocol for predictive likelihood models. Providespredictandupdatemethods for sequential Bayesian inference. Seelikelihood.pyfor method details.
Examples
Create concrete instances that satisfy each protocol:
>>> import numpy as np
>>> from pysatl_cpd.algorithms.online.bayesian.component.cpf import DropCPF
>>> from pysatl_cpd.algorithms.online.bayesian.component.hazard import ConstantHazard
>>> from pysatl_cpd.algorithms.online.bayesian.component.likelihood import GaussianConjugate
>>> from pysatl_cpd.algorithms.online.bayesian.protocol import IBayesianCPF, IHazard, ILikelihood
>>> cpf: IBayesianCPF = DropCPF()
>>> hazard: IHazard = ConstantHazard(lambda_=100.0)
>>> likelihood: ILikelihood = GaussianConjugate(mu_0=0.0, k_0=1.0, alpha_0=1.0, beta_0=1.0)
Use the likelihood protocol to process observations sequentially:
>>> likelihood.clear()
>>> log_probs = likelihood.predict(np.float64(1.5))
>>> likelihood.update(np.float64(1.5))
Use the hazard protocol to compute hazard values:
>>> run_lengths = np.arange(5)
>>> log_h, log_s = hazard.hazard(run_lengths)
Use the CPF protocol to compute a change-point score:
>>> log_posterior = np.array([-10.0, -5.0, -2.0, -1.0, 0.0])
>>> score = cpf.calculate(log_posterior)
>>> cpf.clear()
Notes
All protocols use structural subtyping (
typing.Protocol). Any class that implements the required methods is compatible – no explicit inheritance is needed.These protocols are consumed by the factory helpers in
pysatl_cpd.algorithms.online.bayesian.utilsand by the concrete component implementations inpysatl_cpd.algorithms.online.bayesian.component.All log-space computations use
numpy.float64. Arrays usenumpy.typing.NDArraywith appropriate dtypes.