Changepoint detection with Pruned Exact Linear Time.
from pelt import predict
predict(signal, penalty=20, segment_cost_function="l1", jump=10, minimum_segment_length=2)use std::num::NonZero;
use pelt::{Pelt, SegmentCostFunction};
// Setup the structure for calculating changepoints
let pelt = Pelt::new()
.with_jump(NonZero::new(5).expect("Invalid number"))
.with_minimum_segment_length(NonZero::new(2).expect("Invalid number"))
.with_segment_cost_function(SegmentCostFunction::L1);
// Do the calculation on a data set
let penalty = 10.0;
let result = pelt.predict(&signal[..], penalty)?;# Install maturin inside a Python environment
python3 -m venv .env
source .env/bin/activate
pip install maturin numpy
# Create a Python package from the Rust code
maturin develop
# Open an interpreter
python
>>> from pelt import predict
>>> import numpy as np
>>> signal = np.array([np.sin(np.arange(0, 1000, 10))]).transpose()
>>> predict(signal, penalty=20)Warning
Like all benchmarks, take these with a grain of salt.
Comparison with ruptures:
| Cost Function | Data Points | Data Dimension | Mean pelt |
Mean ruptures |
Times Faster |
|---|---|---|---|---|---|
| L2 | 100 | 1D | 2.065 μs | 2.820 ms | 1365.7x |
| L2 | 100 | 2D | 2.294 μs | 2.817 ms | 1228.1x |
| L2 | 1000 | 1D | 107.256 μs | 171.377 ms | 1597.8x |
| L2 | 1000 | 2D | 51.096 μs | 90.582 ms | 1772.8x |
| L2 | 10000 | 1D | 20.038 ms | 11.454 s | 571.6x |
| L2 | 10000 | 2D | 2.751 ms | 1.672 s | 607.7x |
| L1 | 100 | 1D | 9.148 μs | 4.312 ms | 471.3x |
| L1 | 100 | 2D | 19.886 μs | 4.774 ms | 240.1x |
| L1 | 1000 | 1D | 173.917 μs | 162.959 ms | 937.0x |
| L1 | 1000 | 2D | 2.269 ms | 588.634 ms | 259.5x |
| L1 | 10000 | 1D | 3.515 ms | 14.674 s | 4174.3x |
| L1 | 10000 | 2D | 104.050 ms | 30.726 s | 295.3x |
Command
maturin develop
python benches/bench_compare.pyCommand
cargo build --example simple --profile profiling \
&& samply record target/profiling/examples/simple tests/signals-large.csv