Ruptures
ruptures is a Python library for off-line change point detection. This package provides methods for the analysis and segmentation of non-stationary signals. It is actively maintained with regular minor releases, and the current stable version is 1.1.10.
Warnings
- gotcha Prior to v1.1.8 (for `CostRbf`) and v1.1.7 (for `CostL2`, `Binseg`), the `min_size` parameter in certain cost functions and search methods might have been incorrectly handled. This could lead to errors or unexpected segmentations when `min_size` was set to 1.
- gotcha Versions prior to v1.1.6 had a bug affecting the random behavior of `KernelCPD` (particularly with the Pelt method), which could lead to non-reproducible results when using random states.
- gotcha A memory leak was identified and fixed in `KernelCPD` in versions prior to v1.1.2, which could cause performance degradation or crashes during long-running tasks or with large datasets.
- gotcha Before v1.1.4, the `costar` function did not always enforce `deepcopy` of input data, which could lead to unintended in-place modifications of the original data when using this cost function.
Install
-
pip install ruptures
Imports
- ruptures
import ruptures as rpt
- Pelt
from ruptures.detection import Pelt
- CostL2
from ruptures.costs import CostL2
Quickstart
import ruptures as rpt import numpy as np import matplotlib.pyplot as plt # Generate a signal with change points n_samples, n_dims, sigma = 500, 3, 2 n_bkps = 3 # number of breakpoints signal, bkps = rpt.pw_constant(n_samples, n_dims, n_bkps, noise_std=sigma, seed=42) # Change point detection with Pelt algorithm and L2 cost algo = rpt.Pelt(model="l2", jump=1, min_size=1).fit(signal) result = algo.predict(pen=10) # Display results fig, ax_array = rpt.display(signal, bkps, result) plt.show()