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.

Type: change point detection
Supervision: fully unsupervised
Scope: univariate and multivariate
Complexity: \(O(C\,n)\) expected, \(O(C\,n^{2})\) worst case

Parameters#

Name

Type

Default

Description

model

str

"l2"

Ruptures cost model.

min_size

int

2

Minimum segment length.

jump

int

5

Grid step for candidate positions.

penalty

float

10.0

Penalty threshold for the PELT stopping criterion.

pen_scale

str / None

None

"bic": penalty is a coefficient on \(\log(n)\,u\), u the cost of one sample of the whole signal: d for "l2" on unit-variance channels (the BIC penalty of one more segment), the mean absolute deviation for "l1", 1 for the kernel costs, \(d(d+3)/2\) for "normal" (its BIC parameter count). One value then applies across lengths, dimensions and costs.

cost_params

dict / None

None

Extra keyword arguments for the cost factory.

backend

str

"auto"

Backend of the "l1", "l2", "rbf" and "cosine" costs: "auto" uses numba when it is installed (the kernel costs then in O(n) memory, without the \(n \times n\) Gram matrix); "numba" and "python" force either. Same segmentation on both paths.

axis

int

0

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: BaseSegmenter

Wrapper around the vendored ruptures Pelt estimator.

PELT minimises the sum of the segment costs plus penalty per change point. The number of change points follows from the penalty; it cannot be set directly (use DynpDetector for 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 of jump are considered.

  • penalty (float) – Penalty added per change point. Must be strictly positive.

  • pen_scale (str | None) – None: penalty is used as is. "bic": penalty is a coefficient on log(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 costs l1, l2, rbf and cosine: 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 of X that represents time.

Notes

For a univariate signal with model="l1", upstream ruptures now ships L1Potts, an exact and much faster solver of the same penalised problem with min_size=1 and jump=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 a RuntimeError and an AttributeError.

set_fit_request(*, axis='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the fit method.

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 (see sklearn.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 to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • 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.

Parameters:

axis (Union[bool, None, str]) – Metadata routing for axis parameter in fit.

Returns:

self – The updated object.

Return type:

PeltDetector

set_predict_request(*, axis='$UNCHANGED$')#

Configure whether metadata should be requested to be passed to the predict method.

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 (see sklearn.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 to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • 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.

Parameters:

axis (Union[bool, None, str]) – Metadata routing for axis parameter in predict.

Returns:

self – The updated object.

Return type:

PeltDetector