Cachalot#

Cachalot (CAtching CHAnge-points with LassO) detects changes in the level of a piecewise-constant signal. It first selects candidate change points along a Lasso path, then refines the segmentation with dynamic programming restricted to those candidates. The number of change points is chosen by the relative reduction in residual sum of squares. The total-variation Lasso supplies the candidates; Cachalot names the complete three-stage procedure in the 2007 paper.

Type: change point detection
Supervision: fully unsupervised
Scope: univariate method; multivariate input is processed independently by channel
Complexity: \(O(n K + K^3)\) time and \(O(n + K^2)\) auxiliary memory per channel

Here n is the series length and K = min(max_candidates, n - 1) for n >= 2. Channels are processed sequentially; per-channel processing costs \(O(d (n K + K^3))\) for d channels. Sorting the final union adds an \(O(d K \log(d K))\) bound. Total auxiliary memory, including stored per-channel results and excluding the input array, is \(O(n + d K^2)\) (objective arrays retain their dynamic-programming tables).

Parameters#

Name

Type

Default

Description

max_candidates

int

50

Maximum number of Lasso-path candidate change points per channel, capped at n_timepoints - 1.

nu

float

0.01

Relative-improvement threshold. Select the first k such that J(k + 1) / J(k) >= 1 - nu.

axis

int

0

Axis of X that represents time.

Usage#

from tsseg.algorithms import CachalotDetector

detector = CachalotDetector(max_candidates=50, nu=0.01)
change_points = detector.fit_predict(X)

Implementation: independent reimplementation of Section 3 of the 2007 paper, under AGPL-3.0-only. Centered, unstandardized step columns leave the signal level unpenalized, following Eq. (4). The structured Lasso path uses \(O(n K)\) time per channel; prefix sums and reduced dynamic programming use \(O(n + K^3)\) time. Defaults follow Section 5.1.

Selection includes zero changes. A zero residual stops selection; if no successive residual ratio reaches 1 - nu, all candidates are retained. For multivariate input, each channel has its own path and model selection; the result is the sorted union of the selected change points. Nearby detections from different channels are kept separately, so the union has up to min(n - 1, d * K) points.

References: Harchaoui, Z. and Lévy-Leduc, C., Catching Change-points with Lasso, Advances in Neural Information Processing Systems 20, 2007 (algorithm source); Multiple Change-Point Estimation With a Total Variation Penalty, Journal of the American Statistical Association 105(492):1480-1493, 2010 (related journal article).

API reference#

Cachalot change point detector.

class CachalotDetector(*, max_candidates=50, nu=0.01, axis=0)[source]#

Bases: BaseSegmenter

Catch level changes with Lasso candidates and reduced dynamic programming.

Cachalot writes a piecewise-constant signal as an intercept plus step functions at every possible change point. The L1 penalty is applied to the step coefficients. Cachalot (Harchaoui and Lévy-Leduc) takes the first max_candidates variables on the Lasso path, finds the best piecewise-constant fit over subsets of those candidates by dynamic programming, and selects the number of changes from the relative improvement of the residual sum of squares.

The published method is univariate. For multivariate input, each channel is processed independently and the returned change points are the union of the per-channel estimates. This channel-wise extension is not a shared-change-point multivariate model such as group LARS.

Parameters:
  • max_candidates (int) – Maximum number of Lasso-path change-point candidates per channel. The actual limit is capped at n_timepoints - 1.

  • nu (float) – Relative-improvement threshold in the model-selection rule. The selected count is the first k for which J(k + 1) / J(k) >= 1 - nu.

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

change_points_#

Sorted union of the selected change points across channels.

Type:

np.ndarray

candidate_points_#

Lasso-path candidates for each channel.

Type:

tuple of np.ndarray

objective_paths_#

Minimum residual sums of squares for zero through the maximum candidate-supported number of change points, per channel.

Type:

tuple of np.ndarray

Notes

The step-function columns are centered to leave the signal level unpenalized, matching the total-variation formulation in the paper. Their active-set direction is obtained by linear interpolation between active step positions, so the Lasso path costs O(n K) time and O(n + K) working memory without a dense design or Gram matrix. The reduced dynamic program, including prefix sums, costs O(n + K^3) time and O(n + K^2) memory, where K = min(max_candidates, n - 1) for n >= 2. Costs are per channel; channels are processed sequentially. For d channels, objective arrays retain their dynamic-programming tables, giving O(n + d K^2) total auxiliary memory, excluding the input array. Sorting the final union adds an O(d K log(d K)) time bound.

References

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:

CachalotDetector

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:

CachalotDetector