PELT#
PELT – Pruned Exact Linear Time change point detection.
Description#
PELT solves the penalised change point optimisation problem exactly by
pruning the search space with a dynamic-programming rule. When the number of
change points grows linearly with the number of samples n (Killick et al.,
2012), the expected complexity is \(O(C\,n)\) – linear in n and
independent of the number of change points – where C is the cost function
complexity; with few change points, little is pruned and the worst case is
\(O(C\,n^{2})\). In practice, "l2"
cost models are significantly faster than linear or autoregressive ones.
Key tuning levers:
penalty– higher values produce fewer change points.min_size– minimum distance between change points.jump– grid step for admissible positions.
Parameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
str |
|
Ruptures cost model. |
|
int |
|
Minimum segment length. |
|
int |
|
Grid step for candidate positions. |
|
float |
|
Penalty threshold for the PELT stopping criterion. |
|
str / None |
|
|
|
dict / None |
|
Extra keyword arguments for the cost factory. |
|
str |
|
Backend of the |
|
int |
|
Time axis. |
Usage#
from tsseg.algorithms import PeltDetector
detector = PeltDetector(model="l2", penalty=10)
change_points = detector.fit_predict(X)
Implementation: Vendored from ruptures v1.1.8. BSD 2-Clause. With the
"l1", "l2", "rbf" or "cosine" cost and numba installed, the
search runs in numba. For the kernel costs (kernel change point detection,
ruptures’ KernelCPD) it transcribes ruptures’ C code, which updates the
kernel sums sample by sample instead of storing the \(n \times n\) Gram
matrix. Candidates closer than \(10^{-9}\) of the costs involved are tied,
and the earliest change point wins, on both backends.
Reference: Killick, Fearnhead & Eckley (2012), Optimal detection of changepoints with a linear computational cost, JASA.
API reference#
PELT change point detector using the vendored ruptures implementation.
- class PeltDetector(*, model='l2', min_size=2, jump=5, penalty=10.0, pen_scale=None, cost_params=None, backend='auto', axis=0)[source]#
Bases:
BaseSegmenterWrapper around the vendored ruptures
Peltestimator.PELT minimises the sum of the segment costs plus
penaltyper change point. The number of change points follows from the penalty; it cannot be set directly (useDynpDetectorfor that).- Parameters:
model (
str) – Cost model: least squares ("l2"), least absolute deviation ("l1"), Gaussian kernel ("rbf"), linear regression ("linear"), Gaussian likelihood ("normal") or cosine kernel ("cosine").min_size (
int) – Minimum segment length. Must not exceed half the series length.jump (
int) – Sub-sampling factor for candidate breakpoints: only multiples ofjumpare considered.penalty (
float) – Penalty added per change point. Must be strictly positive.pen_scale (
str|None) –None:penaltyis used as is."bic":penaltyis a coefficient onlog(n) * u, u the cost of one sample of the whole signal (d for"l2"on unit-variance channels, where it is the BIC penalty; 1 for the kernel costs; d(d+3)/2, the BIC parameter count, for"normal").cost_params (
dict|None) – Extra keyword arguments forwarded to the cost (for instance{"gamma": 0.1}for"rbf").backend (
str) – Backend of the costsl1,l2,rbfandcosine: numba when it is installed under"auto", the kernel costs then without the n x n Gram matrix. Same change points either way.axis (
int) – Axis ofXthat represents time.
Notes
For a univariate signal with
model="l1", upstream ruptures now shipsL1Potts, an exact and much faster solver of the same penalised problem withmin_size=1andjump=1; it is not vendored here. See deepcharles/ruptures- property change_points_: ndarray#
Change points returned by the last call to
predict(a copy).Not set before
predict: reading it then raises an error that is both aRuntimeErrorand anAttributeError.
- set_fit_request(*, axis='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
fitmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed tofitif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it tofit.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
- set_predict_request(*, axis='$UNCHANGED$')#
Configure whether metadata should be requested to be passed to the
predictmethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed topredictif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it topredict.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.