abstract_bayesian

Abstract Bayesian base implementation.

class pysatl_cpd.algorithms.online.bayesian.algorithm.abstract_bayesian.BayesianOnlineCPDConfiguration(*, learning_period_size=0, window=None, cpf_type=BayesianCPFType.MAX_RUN_LENGTH)[source]

Bases: OnlineAlgorithmConfiguration

Base configuration for Bayesian online CPD algorithms.

Parameters:
  • learning_period_size (int)

  • window (int | None)

  • cpf_type (BayesianCPFType)

window: int | None = None
cpf_type: BayesianCPFType = 'max_run_length'
__post_init__()[source]

Validate configuration fields after initialisation.

Raises:

ValueError – If learning_period_size is negative, or window is non-positive when provided.

Return type:

None

__init__(*, learning_period_size=0, window=None, cpf_type=BayesianCPFType.MAX_RUN_LENGTH)
Parameters:
  • learning_period_size (int)

  • window (int | None)

  • cpf_type (BayesianCPFType)

Return type:

None

class pysatl_cpd.algorithms.online.bayesian.algorithm.abstract_bayesian.BayesianOnlineCPDState(*, is_in_learning_period=False, t=0, run_length_log_posterior=<factory>)[source]

Bases: OnlineAlgorithmState

Base state for Bayesian online CPD algorithms.

Variables:
  • t – Current time step.

  • run_length_log_posterior – Log-posterior distribution over run lengths.

Parameters:
  • is_in_learning_period (bool)

  • t (int)

  • run_length_log_posterior (Any)

t: int = 0
run_length_log_posterior: Any
__init__(*, is_in_learning_period=False, t=0, run_length_log_posterior=<factory>)
Parameters:
  • is_in_learning_period (bool)

  • t (int)

  • run_length_log_posterior (Any)

Return type:

None

class pysatl_cpd.algorithms.online.bayesian.algorithm.abstract_bayesian.AbstractBayesian(configuration, hazard, likelihood, cpf)[source]

Bases: OnlineAlgorithm[float, BayesianOnlineCPDConfiguration, BayesianOnlineCPDState], ABC

Base class for configurable online Bayesian detectors.

Implements the Bayesian online change-point detection (BOCPD) message-passing loop. Subclasses must provide the name property and wire up the concrete hazard, likelihood, and cpf components.

Parameters:
__init__(configuration, hazard, likelihood, cpf)[source]
Parameters:
Return type:

None

abstract property name: str

Human-readable algorithm name.

property configuration: BayesianOnlineCPDConfiguration

Return the current algorithm configuration.

Return type:

BayesianOnlineCPDConfiguration

property state: BayesianOnlineCPDState

Materialise an immutable snapshot of the current state.

Return type:

BayesianOnlineCPDState

process(observation)[source]

Ingest one observation and return the change-point score.

Implements the BOCPD message-passing update:
  1. Predictive probabilities from the likelihood model.

  2. Hazard-based growth / change-point probabilities.

  3. Normalise and optionally truncate to window.

  4. Return CPF score (or 0 during learning period).

Parameters:

observation (float) – New data point.

Returns:

Change-point score (0.0 during learning period).

Return type:

double | int | float

reset()[source]

Reset the algorithm to its initial state.

Clears step counter, run-length posterior, likelihood, and CPF.

Return type:

None

recreate()[source]

Create a fresh independent copy with identical configuration.

Return type:

Self