Offline Detectors#
High-level Python classes for batch change-point detection. All follow the fit/predict pattern.
Pelt#
PELT (Pruned Exact Linear Time) detector.
Constructor#
cpd.Pelt(
model: str = "l2",
min_segment_len: int = 2,
jump: int = 1,
max_change_points: int | None = None,
)
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Cost model. Accepts |
|
|
|
Minimum number of samples in each segment |
|
|
|
Stride over candidate split points. Increase to trade precision for speed |
|
|
|
Hard upper bound on the number of change points returned |
Methods#
fit(values) -> Pelt#
Precompute cost cache on the input signal.
values: array-like of
float32orfloat64. Shape(n,)for univariate,(n, d)for multivariate.Returns:
self(for method chaining)Raises:
TypeErrorif input dtype is not float32/float64;RuntimeErrorif input contains NaN
predict(*, pen=None, n_bkps=None) -> OfflineChangePointResult#
Run PELT detection and return results.
pen:
float | str | None– Penalty value. A float for manual penalty,"bic"for BIC,"aic"for AICn_bkps:
int | None– Exact number of change points to detectReturns:
OfflineChangePointResultRaises:
RuntimeErroriffit()was not called first
Note
Exactly one of pen or n_bkps must be provided.
Example#
import numpy as np
import cpd
x = np.concatenate([np.zeros(50), np.full(50, 5.0), np.full(50, -2.0)])
result = cpd.Pelt(model="l2", min_segment_len=2).fit(x).predict(n_bkps=2)
print(result.breakpoints) # [50, 100, 150]
Binseg#
Binary Segmentation detector.
Constructor#
cpd.Binseg(
model: str = "l2",
min_segment_len: int = 2,
jump: int = 1,
max_change_points: int | None = None,
max_depth: int | None = None,
)
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Cost model. Accepts |
|
|
|
Minimum segment length |
|
|
|
Candidate stride |
|
|
|
Hard cap on detected change points |
|
|
|
Maximum recursion depth for the binary split tree |
Methods#
fit(values) -> Binseg#
Same interface as Pelt.fit().
predict(*, pen=None, n_bkps=None) -> OfflineChangePointResult#
Same interface as Pelt.predict().
Example#
result = cpd.Binseg(model="l2").fit(x).predict(n_bkps=3)
Warning
BinSeg may miss closely spaced changes (masking). Check diagnostics warnings. If masking is indicated, prefer WBS via detect_offline(pipeline=...).
Fpop#
Functional Pruning Optimal Partitioning detector. L2 cost only.
Constructor#
cpd.Fpop(
min_segment_len: int = 2,
jump: int = 1,
max_change_points: int | None = None,
)
Parameter |
Type |
Default |
Description |
|---|---|---|---|
|
|
|
Minimum segment length |
|
|
|
Candidate stride |
|
|
|
Hard cap |
Note
FPOP does not accept a model parameter because it is restricted to L2 cost.
Methods#
fit(values) -> Fpop#
Same interface as Pelt.fit().
predict(*, pen=None, n_bkps=None) -> OfflineChangePointResult#
Same interface as Pelt.predict().
Example#
result = cpd.Fpop(min_segment_len=2).fit(x).predict(pen="bic")