Online Detectors#
Streaming change-point detectors that process one observation at a time.
Bocpd#
Bayesian Online Changepoint Detection.
Constructor#
cpd.Bocpd(
model: str = "gaussian_nig",
hazard: float | dict[str, Any] | None = None,
max_run_length: int = 2000,
alert_policy: dict[str, Any] | None = None,
late_data_policy: str | dict[str, Any] | None = None,
)
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Conjugate observation model family |
|
|
|
Constant hazard rate (1/expected_run_length) or custom config |
|
|
|
Truncation limit for the run-length posterior |
|
|
|
Alert firing rules (see below) |
|
|
|
Late-data handling strategy |
Alert policy shape:
{
"threshold": 0.35, # p_change must exceed this to fire
"cooldown": 5, # minimum steps between consecutive alerts
"min_run_length": 10, # suppress alerts during initial transient
}
Methods#
update(x_t, t_ns=None) -> OnlineStepResult#
Process a single scalar observation.
x_t:
float– Observation valuet_ns:
int | None– Optional nanosecond timestampReturns:
OnlineStepResult
update_many(x_batch) -> list[OnlineStepResult]#
Process a batch of observations. Uses GIL-release optimization for batches >= 16 elements.
x_batch: array-like of
float64Returns: List of
OnlineStepResult
reset() -> None#
Clear internal state and start fresh.
save_state(*, format="bytes", path=None) -> bytes | dict | None#
Checkpoint the detector state.
format:
str–"bytes"(compact binary) or"dict"(Python dict)path:
str | Path | None– If provided, writes state to this file path and returnsNoneReturns: State in the requested format, or
Noneifpathis provided
load_state(state=None, *, format=None, path=None) -> None#
Restore detector state from a checkpoint.
state:
bytes | dict | _BocpdState | None– State object to loadformat:
str | None– Required when loading fromstatebytes/dictpath:
str | Path | None– Load from file instead ofstateparameter
Cusum#
Cumulative Sum detector for mean-shift monitoring.
Constructor#
cpd.Cusum(
drift: float = 0.0,
threshold: float = 8.0,
target_mean: float = 0.0,
alert_policy: dict[str, Any] | None = None,
late_data_policy: str | dict[str, Any] | None = None,
)
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Allowance parameter (slack before accumulation) |
|
|
|
Decision threshold for cumulative sum |
|
|
|
Expected mean under null hypothesis |
|
|
|
Alert policy (same shape as BOCPD) |
|
|
|
Late-data handling |
Methods#
Same interface as Bocpd: update(), update_many(), reset(), save_state(), load_state().
PageHinkley#
Page-Hinkley drift/change monitor.
Constructor#
cpd.PageHinkley(
delta: float = 0.01,
threshold: float = 8.0,
initial_mean: float = 0.0,
alert_policy: dict[str, Any] | None = None,
late_data_policy: str | dict[str, Any] | None = None,
)
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Magnitude tolerance parameter |
|
|
|
Decision threshold |
|
|
|
Initial mean estimate |
|
|
|
Alert policy (same shape as BOCPD) |
|
|
|
Late-data handling |
Methods#
Same interface as Bocpd: update(), update_many(), reset(), save_state(), load_state().