Skip to main content

Changepoint detection with Pruned Exact Linear Time

Project description

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 2.197 μs 3.125 ms 1422.4x
L2 100 2D 2.478 μs 3.160 ms 1275.0x
L2 1000 1D 126.394 μs 195.964 ms 1550.4x
L2 1000 2D 57.435 μs 95.860 ms 1669.0x
L2 10000 1D 21.401 ms 12.571 s 587.4x
L2 10000 2D 2.397 ms 1.699 s 708.8x
L1 100 1D 10.613 μs 4.804 ms 452.7x
L1 100 2D 21.625 μs 5.105 ms 236.1x
L1 1000 1D 321.511 μs 184.912 ms 575.1x
L1 1000 2D 2.152 ms 636.542 ms 295.9x
L1 10000 1D 13.598 ms 15.572 s 1145.2x
L1 10000 2D 85.147 ms 30.706 s 360.6x
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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelt-0.3.1.tar.gz (96.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pelt-0.3.1-cp314-cp314-macosx_11_0_arm64.whl (237.0 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pelt-0.3.1-cp312-cp312-win_amd64.whl (174.1 kB view details)

Uploaded CPython 3.12Windows x86-64

pelt-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (276.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file pelt-0.3.1.tar.gz.

File metadata

  • Download URL: pelt-0.3.1.tar.gz
  • Upload date:
  • Size: 96.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.4

File hashes

Hashes for pelt-0.3.1.tar.gz
Algorithm Hash digest
SHA256 d39d69e7d5f8fd3e756c367c81e2b67bc1dd560fcc6fe55a2336153620e44872
MD5 1781d618814b41edc6650b8f5feb26ad
BLAKE2b-256 1a2f4fd3f1d6c0ef0f3326f590ac18acb75ad9485ba4a477388f01e482ef7e29

See more details on using hashes here.

File details

Details for the file pelt-0.3.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pelt-0.3.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c85840098d1cd2ed194d5870b384ffc0efaf9a17a5bd99110fc5d16d176de080
MD5 292d10cc49398a5253c6a03314af6551
BLAKE2b-256 f7f8278bc15a2b64e775400595c29906ff5917dcb1e342d7355cf023d8533d68

See more details on using hashes here.

File details

Details for the file pelt-0.3.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pelt-0.3.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 174.1 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.4

File hashes

Hashes for pelt-0.3.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 58ba247c231deff1e69ccca44123246dbef951a84ad87141165e98b54e4c7e69
MD5 93f39d44f14fcc1ae13d9cd55558b011
BLAKE2b-256 9d89b4d8fb6e9eb1bd30b6326aaa6c21007c94e2afb20f1f513217abaa248c69

See more details on using hashes here.

File details

Details for the file pelt-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pelt-0.3.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 863ebafdba768d69f80f62593b12261b011514ed84ed1006d4755b2b4adf6d96
MD5 e5219c5cded36f55bb117fd1f8c11804
BLAKE2b-256 5cca8ba063621dc3094703f445edee5844d0deedcd771ff336fbd20987072b48

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page