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.
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 |
|---|---|---|---|
|
int |
|
Maximum number of Lasso-path candidate change points per channel,
capped at |
|
float |
|
Relative-improvement threshold. Select the first k such that
|
|
int |
|
Axis of |
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:
BaseSegmenterCatch 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_candidatesvariables 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 atn_timepoints - 1.nu (
float) – Relative-improvement threshold in the model-selection rule. The selected count is the firstkfor whichJ(k + 1) / J(k) >= 1 - nu.axis (
int) – Axis ofXthat represents time.
- change_points_#
Sorted union of the selected change points across channels.
- Type:
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 andO(n + K)working memory without a dense design or Gram matrix. The reduced dynamic program, including prefix sums, costsO(n + K^3)time andO(n + K^2)memory, whereK = min(max_candidates, n - 1)forn >= 2. Costs are per channel; channels are processed sequentially. Fordchannels, objective arrays retain their dynamic-programming tables, givingO(n + d K^2)total auxiliary memory, excluding the input array. Sorting the final union adds anO(d K log(d K))time bound.References
- 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.