Skip to main content

changepoint_cython

A cython version of the changepoint and changepoint.np R package, see https://github.com/cran/changepoint and https://github.com/cran/changepoint.np.

Implemented algorithms:

  • Binary Segmentation, PELT, and Segmentation Neigborhood: monovariate and multivariate time series.
  • Non parametric PELT: monovariate variate.

Model implemented for the monovariate case :

  • Normal (mean, variance, or mean and variance).
  • Poisson (mean and variance).
  • Exponential (mean and variance).

Model implemented for the multivariate case :

  • Normal (mean).

Working on Windows/Linux and python3.x

Install

PyPI

Source available on https://pypi.org/project/changepoint-cython/

pip install changepoint-cython

From source

Download and run:

pip3 install -r requirements.txt
pip3 install .

Tests

Synthetic examples

python3 test_segmentation.py

python3 test_segmentation_multiple.py

Test on well bore data

See notebook "segmentation example on well log data.ipynb"

import pandas as pd
import numpy as np
import lasio
from pychangepoints import cython_pelt, algo_changepoints

Loading and cleaning data

well_log_las = lasio.read('./data/2120913D.las')
well_log_df = well_log_las.df()

list_var=['GR','NPOR','RHOZ','PEFZ']
well_log_data = well_log_df[list_var]

well_log_data = well_log_data[well_log_data>-1]
well_log_data.dropna(inplace=True)
well_log_data = well_log_data[well_log_data.index>6542]

Segmentation with PELT for multivariate time series.

penalty_value = 5
min_segment_size = 20
model = 'mbic_mean'
list_cpts, nb_cpts = algo_changepoints.pelt_multiple(well_log_data,penalty_value, min_segment_size, model)

Results of the segmentation

Documentation

PELT

Inputs:

  • data: data as pandas dataframe,
  • penalty_value: double, penalty value, (BIC penalty),
  • min_segment_size: int, minimum segment size,
  • model: str, statistical model (see cost_function.pxd).

Outputs:

  • list_cpts: array of the postion of the change-points,
  • nb_cpts: number of chnagepoint.

Usage:

from pychangepoints import algo_changepoints

penalty_value = 5
min_segment_size = 20
model = 'mbic_mean'
list_cpts, nb_cpts = algo_changepoints.pelt(data, penalty_value, min_segment_size, model)

For the multivariate case, call pelt_multiple:

from pychangepoints import algo_changepoints

penalty_value = 5
min_segment_size = 20
model = 'mbic_mean'
list_cpts, nb_cpts = algo_changepoints.pelt_multiple(data, penalty_value, min_segment_size, model)

NP PELT

Inputs:

  • data: as pandas dataframe,
  • penalty_value: double, penalty value, (BIC penalty),
  • min_segment_size: int, minimum segment size,
  • nquantiles: int, number of quantiles,
  • method: str, cost functioon (optional, only one implemented).

Outputs:

  • list_cpts, array of the postion of the change-points
  • nb_cpts, number of chnagepoint.

Usage:

from pychangepoints import algo_changepoints

penalty_value = 5
min_segment_size = 20
model = 'mbic_nonparametric_ed'
nquantiles = 10
list_cpts, nb_cpts = algo_changepoints.np_pelt(data, penalty_value, min_segment_size, nquantiles, method = model)

Binary Segmentation

Inputs:

  • data: pandas dataframe,
  • Q: int, number of changepoints,
  • min_segment_size: int, minimum segment size,
  • statistical model, str (see cost_function.pxd).

Output:

  • array of the postion of the change-points,

Usage:

from pychangepoints import algo_changepoints
Q = 5
min_segment_size = 20
model = 'mbic_mean'
list_cpts = algo_changepoints.binseg(data, Q, minseg, method)

For the multivariate case, call binseg_multiple:

from pychangepoints import algo_changepoints
Q = 5
min_segment_size = 20
model = 'mbic_mean'
list_cpts = algo_changepoints.binseg_multiple(data, Q, minseg, method)

Segmentation neighborhood

Inputs:

  • data: pandas dataframe,
  • Q: int, number of changepoints,
  • statistical model, str (see cost_function.pxd).

Output:

  • array of the postion of the change-points,

Usage:

from pychangepoints import algo_changepoints
Q = 5
model = 'mbic_mean'
list_cpts = algo_changepoints.segneigh(data, Q, method)

For the multivariate case, call segneigh_multiple:

from pychangepoints import algo_changepoints
Q = 5
model = 'mbic_mean'
list_cpts = algo_changepoints.segneigh_multiple(data, Q, method)

Metadata

Release files for changepoint-cython 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for changepoint-cython 0.1.5
File Size Uploaded Provenance Actions
changepoint_cython-0.1.5.tar.gz 66.1 kB Without provenance Details for changepoint_cython-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for changepoint-cython 0.1.5
File Interpreter ABI Platform Actions
changepoint_cython-0.1.5-cp39-cp39-manylinux_2_35_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.35+ x86-64 Details for changepoint_cython-0.1.5-cp39-cp39-manylinux_2_35_x86_64.whl

Total release size: 1.7 MB

Release files / changepoint_cython-0.1.5.tar.gz

Download URL changepoint_cython-0.1.5.tar.gz
Size 66.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3437c73e04dd8803984082f2702bbaae92a7cd22ba945e20da118148b49af025
BLAKE2b-256 checksum
How to use checksums
67205f8b01bbcd2e79ee87319fe48ad1658e103502d3ee26cbdfd0deb908ff64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.9.16 Linux/5.15.0-1037-azure

Release files / changepoint_cython-0.1.5-cp39-cp39-manylinux_2_35_x86_64.whl

Download URL changepoint_cython-0.1.5-cp39-cp39-manylinux_2_35_x86_64.whl
Size 1.6 MB
Tags CPython 3.9 Linux glibc 2.35+ x86-64
SHA-256 checksum
How to use checksums
6233d2cf6b4d039afa2fd1a386d90067314d5a0776f8e39d65ef2836ed0d741c
BLAKE2b-256 checksum
How to use checksums
4be9f4a5b286181c81d419d39c371bdd8d9c2998ede7275a23be5bbf560acc29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.0 CPython/3.9.16 Linux/5.15.0-1037-azure

Security for changepoint-cython 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page