BottomUp#
Bottom-Up segmentation – agglomerative merging of segments.
Description#
Contrary to binary segmentation (top-down), bottom-up segmentation starts with a fine initial partition along a regular grid and successively merges the two most similar contiguous segments until a stopping criterion is met. The procedure is generous: it begins with many change points and removes the least significant ones.
Complexity is \(O(n\log n)\) where n is the number of samples, and the algorithm supports any cost function available in the vendored ruptures library.
Parameters#
Name |
Type |
Default |
Description |
|---|---|---|---|
|
int / None |
|
Number of change points. When |
|
str |
|
Ruptures cost model ( |
|
int |
|
Minimum segment length. |
|
int |
|
Grid step for candidate change points. |
|
float / None |
|
Penalty value. Mutually exclusive with |
|
str / None |
|
|
|
float / None |
|
Reconstruction budget. Mutually exclusive with |
|
dict / None |
|
Extra parameters passed to the cost function. |
|
str |
|
Backend of the |
|
int |
|
Time axis. |
Usage#
from tsseg.algorithms import BottomUpDetector
detector = BottomUpDetector(model="l2", n_cps=3)
change_points = detector.fit_predict(X)
# Penalty-based stopping
detector = BottomUpDetector(model="l2", penalty=10)
change_points = detector.fit_predict(X)
Implementation: Vendored from ruptures v1.1.8, with the speed-up of
v1.1.9 (PR #309: a heap
of segments grows the initial partition; the change points are unchanged).
BSD 2-Clause. With the "l1", "l2", "rbf" or "cosine" cost and numba installed, the
segment costs are computed in numba: the kernel costs without the
\(n \times n\) Gram matrix, "l1" and "l2" bit for bit as numpy
computes them. Merge gains closer than \(10^{-9}\) of the segments’ costs
are tied, and the leftmost merge is done first, on both backends.
Reference: Keogh, Chu, Hart & Pazzani (2001), ICDM; Fryzlewicz (2007), JASA.
API reference#
Bottom-up detector built on the vendored ruptures implementation.
- class BottomUpDetector(*, n_cps=None, model='l2', min_size=2, jump=5, penalty=None, pen_scale=None, epsilon=None, cost_params=None, backend='auto', axis=0)[source]#
Bases:
BaseSegmenterBottom-up change point detector using the vendored ruptures implementation.
The series is first cut into the finest partition that
min_sizeandjumpallow; adjacent segments are then merged greedily, the merge that increases the cost least first, until the stopping criterion is met.- Parameters:
n_cps (
int|None) – Number of change points to return. When given,penaltyandepsilonare ignored, with aUserWarningfor each one that is also given.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|None) – Penalty per change point, used whenn_cpsisNone: merging continues while the cheapest merge increases the cost by less thanpenalty. Must be strictly positive.Nonemeans 10 when neithern_cpsnorepsilonis given, and no penalty otherwise. At most one ofpenaltyandepsilonmay be set.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").epsilon (
float|None) – Reconstruction budget, used whenn_cpsandpenaltyareNone: merging continues while the total cost of the segmentation is belowepsilon. Must be strictly positive.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.
- Raises:
ValueError – If both
penaltyandepsilonare set withoutn_cps, or ifpenaltyorepsilonis not strictly positive.
- 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.