Skip to content

cemsbv/pelt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crates.io pypi MPL-2.0 docs.rs ci

Changepoint detection with Pruned Exact Linear Time.

Usage

Python

from pelt import predict

predict(signal, penalty=20, segment_cost_function="l1", jump=10, minimum_segment_length=2)

Rust

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)?;

Run locally

# 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 --features python

# 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)

Benchmarks

Warning

Like all benchmarks, take these with a grain of salt.

Python

Comparison with ruptures:

Cost Function Data Points Data Dimension Mean pelt Mean ruptures Times Faster
L2 100 1D 0.004ms 3.113ms 753.1x
L2 100 2D 0.005ms 3.251ms 608.5x
L2 1000 1D 0.419ms 188.546ms 449.8x
L2 1000 2D 0.572ms 94.201ms 164.7x
L2 10000 1D 95.851ms 12.103s 126.3x
L2 10000 2D 19.871ms 1.778s 89.5x
L1 100 1D 0.010ms 5.101ms 508.8x
L1 100 2D 0.025ms 5.323ms 213.0x
L1 1000 1D 0.641ms 180.250ms 281.3x
L1 1000 2D 3.595ms 638.049ms 177.5x
L1 10000 1D 43.444ms 15.710s 361.6x
L1 10000 2D 364.553ms 30.572s 83.9x
Command
maturin develop --features python --release
python benches/bench_compare.py

Profile

Command
cargo build --example simple --profile profiling \
 && samply record target/profiling/examples/simple tests/signals-large.csv

Credits

About

Changepoint detection with Pruned Exact Linear Time

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •