KCPD#

KCPD – Kernel Change Point Detection.

Warning

Deprecated. KCPDDetector is not a method of its own: it runs the solvers of PELT (with pen) and DynP (with n_cps) on a kernel cost, and will be removed in a future release. Use PeltDetector(model="rbf", penalty=pen, jump=1) or DynpDetector(model="rbf", n_cps=k, jump=1) (model="l2" for the linear kernel). For decimation=k, pass X[::k] and multiply the change points by k; for pen_scale="bic", use a penalty of pen * log(n) * d.

Description#

KCPD operates in a Reproducing Kernel Hilbert Space (RKHS) and detects mean-shifts in the mapped signal. The time series is implicitly mapped by a kernel function \(k(\cdot,\cdot)\) and the algorithm minimises:

\[V(t_1,\dots,t_K) = \sum_{k=0}^{K}\sum_{t=t_k}^{t_{k+1}-1} \|\phi(y_t) - \bar\mu_{t_k..t_{k+1}}\|_{\mathcal{H}}^2\]

When the number of changes K is known, the exact minimum is found by dynamic programming; otherwise a penalised formulation (PELT) is used.

Available kernels: "linear" (L2 cost), "rbf" (Gaussian), "cosine".

Type: change point detection
Supervision: unsupervised or semi-supervised
Scope: univariate and multivariate
Complexity: that of PELT (pen) or DynP (n_cps) with a kernel cost

Parameters#

Name

Type

Default

Description

n_cps

int / None

None

Number of change points. None = use pen.

pen

float / None

10

Penalty for the penalised optimisation.

kernel

str

"rbf"

Kernel to use ("linear", "rbf", "cosine").

min_size

int

2

Minimum segment length.

jump

int

1

Sub-sampling factor for candidates.

cost_params

dict / None

None

Extra arguments for the kernel cost.

axis

int

0

Time axis.

Usage#

from tsseg.algorithms import KCPDDetector

detector = KCPDDetector(kernel="rbf", n_cps=3)
change_points = detector.fit_predict(X)

# Unknown K – use a penalty
detector = KCPDDetector(kernel="rbf", pen=10)
change_points = detector.fit_predict(X)

Implementation: vendored from ruptures v1.1.8, whose KernelCPD is a C implementation of PELT and DynP for kernel costs. tsseg runs its vendored Python Pelt / Dynp instead, or their numba backend (backend), which for the rbf and cosine kernels transcribes that C code. BSD 2-Clause.

Reference: Celisse, Marot, Pierre-Jean & Rigaill (2018), Computational Statistics and Data Analysis; Arlot, Celisse & Harchaoui (2019), JMLR.

API reference#

Kernel-based change point detector built on the vendored ruptures implementation.

class KCPDDetector(*, n_cps=None, pen=10, kernel='rbf', pen_scale=None, min_size=2, jump=1, decimation=1, cost_params=None, backend='auto', axis=0)[source]#

Bases: BaseSegmenter

Kernel change point detector using dynamic programming or PELT.

Deprecated: KCPDDetector is not a method of its own. It runs the solvers of PeltDetector (with pen) and DynpDetector (with n_cps) on a kernel cost, and will be removed in a future release. Use PeltDetector(model=kernel, penalty=pen, jump=1) or DynpDetector(model=kernel, n_cps=n_cps, jump=1), with model="l2" for the linear kernel. For decimation=k, pass X[::k] and multiply the change points by k; for pen_scale="bic", use a penalty of pen * log(n) * d.

Parameters:
  • n_cps (int | None) – Number of change points: the dynamic programming solver is used. When given, pen is ignored (with a UserWarning, pen being 10 by default). 0 returns no change point.

  • pen (float | None) – Penalty per change point, used with the PELT solver when n_cps is None.

  • kernel (str) – Kernel of the cost.

  • pen_scale (str | None) – None: pen is used as is. "bic": the penalty is pen * log(n) * d, n and d the length and number of channels of the series after decimation.

  • min_size (int) – Minimum segment length, in decimated samples.

  • jump (int) – Sub-sampling factor for candidate breakpoints, in decimated samples.

  • decimation (int) – Keep one sample in decimation before segmenting; the change points are mapped back to the time base of X. Must be at least 1.

  • cost_params (dict | None) – Extra keyword arguments forwarded to the kernel cost (for instance {"gamma": 0.1} for "rbf").

  • backend (str) – Backend of the kernel costs: numba when it is installed under "auto", then without the n x n Gram matrix. Same change points either way.

  • axis (int) – Axis of X that represents time.

Raises:

ValueError – If both n_cps and pen are None, or if decimation is smaller than 1.

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:

KCPDDetector

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:

KCPDDetector