Changepoint detection with Pruned Exact Linear Time
Project description
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, keep_initial_zero=False)
Rust
use pelt::{Pelt, SegmentCostFunction, Kahan};
// 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;
// Use more accurate Kahan summation for all math
let result = pelt.predict::<Kahan<_>, _>(&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
Like all benchmarks, take these with a grain of salt.
Python
Comparison with ruptures:
| Benchmark | Min (+) | Max (+) | Mean (+) |
|---|---|---|---|
| ruptures L1 vs pelt L1 | -102.1x | -101.4x | -101.6x |
| ruptures L2 vs pelt L2 | -1578.8x | -1587.7x | -1591.1x |
Command
richbench benches/
Rust
Timer precision: 20 ns
bench fastest │ slowest │ median │ mean │ samples │ iters
├─ large │ │ │ │ │
│ ├─ Kahan<f64> │ │ │ │ │
│ │ ├─ L1 161.2 ms │ 202.3 ms │ 162.3 ms │ 165.3 ms │ 100 │ 100
│ │ ╰─ L2 4.832 ms │ 4.923 ms │ 4.845 ms │ 4.852 ms │ 100 │ 100
│ ╰─ Naive<f64> │ │ │ │ │
│ ├─ L1 126.6 ms │ 159.2 ms │ 127.7 ms │ 131.5 ms │ 100 │ 100
│ ╰─ L2 1.436 ms │ 1.591 ms │ 1.45 ms │ 1.455 ms │ 100 │ 100
╰─ small │ │ │ │ │
├─ Kahan<f64> │ │ │ │ │
│ ├─ L1 247.4 µs │ 295.3 µs │ 252.7 µs │ 254 µs │ 100 │ 100
│ ╰─ L2 65.22 µs │ 73.42 µs │ 66.02 µs │ 66.31 µs │ 100 │ 100
╰─ Naive<f64> │ │ │ │ │
├─ L1 189.7 µs │ 254.7 µs │ 196.3 µs │ 197.5 µs │ 100 │ 100
╰─ L2 27.19 µs │ 38.14 µs │ 28.05 µs │ 28.45 µs │ 100 │ 100
Command
cargo bench --profile release
Profile
Command
cargo build --example simple --profile profiling \
&& samply record target/profiling/examples/simple tests/signals-large.txt
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
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pelt-0.2.0.tar.gz.
File metadata
- Download URL: pelt-0.2.0.tar.gz
- Upload date:
- Size: 70.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc3957512e8d01a54636279da35e3ec9ce551399b7c5bc690189c325698beb9c
|
|
| MD5 |
2f9908a0893cddc454b02dd045ff30a6
|
|
| BLAKE2b-256 |
6c54e3e52a8618d8397ed520084f517f4fc5460e6c022f46e16b290be667367b
|
File details
Details for the file pelt-0.2.0-cp314-cp314-macosx_11_0_arm64.whl.
File metadata
- Download URL: pelt-0.2.0-cp314-cp314-macosx_11_0_arm64.whl
- Upload date:
- Size: 205.8 kB
- Tags: CPython 3.14, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7de9864dfe44a47399d26155d8a1b744c37e580d7dae1077a1e4322988e962a
|
|
| MD5 |
08f78a58476d58814d385f0e6e7d39f4
|
|
| BLAKE2b-256 |
508b4e11317d751d6a85fed6cef167f4e160a89e6bd7fc67a49a18c5ab73a6c1
|
File details
Details for the file pelt-0.2.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: pelt-0.2.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 131.4 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71064e7f2b07dd35a8da0dd0c9987e6007ac4b458db0d984dfdbee04a54aef4b
|
|
| MD5 |
5dff9a6c4a7506a134117f27549f1549
|
|
| BLAKE2b-256 |
2f578a91dc8cf4e339412d810412e0def55bdf2b8657e76978bab1d4bab52a83
|
File details
Details for the file pelt-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: pelt-0.2.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 231.5 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec8fc2810aa3b9d28d956005159dda175fb59e9eb2845f891a2d174738d15b8e
|
|
| MD5 |
47514789f8d23651fe69800d3434e04e
|
|
| BLAKE2b-256 |
5ee18692d5e30ba618ac978ef9c89ab1b4f653931816bf548b13c7956597ec87
|