Skip to main content

Change point / changepoint detection for time series in Python (Singular Spectrum Transformation - SST, IKA-SST, ulSIF, RuLSIF, KLIEP, FLUSS, FLOSS, etc.). Focus on efficient implementation and readable code.

Project description

Python Changepoint Detection (changepoynt)

PyPI version License python downloads

changepoynt is a Python library for change point detection / changepoint detection in time series (offline and online). It includes Singular Spectrum Transformation (SST, IKA-SST, ESST), density-ratio change detection (uLSIF, RuLSIF), and matrix-profile segmentation (FLUSS, FLOSS).

Start using it:

pip install changepoynt

or

uv pip install changepoynt

Table of content:

This is the repository hosting the pip-installable python package changepoynt. It implements several change point detection techniques, while focusing mostly on "localized" algorithms, that could be run in an online fashion.

Current algorithms come from the field of:

  • Subspace Estimation (Extracting the characteristic signals)

  • Statistics (Detection of Change in the statistical properties)

  • Time Series Segmentation (Algorithms focused on comparing time series shape)

The package is aimed at execution performance (using JIT compilation and standing on the shoulders of giants like numpy and scipy) while also keeping code readable and maintainable. This includes comments as well as architectural choices. This might not be perfect, but we are trying!

All of our algorithms are implementations of a base changepoint detection interface and therefore are interchangeable. Currently, we are focused on shifting to the very common and existing sklearn interface of fit and transform. This enables our algorithms to be part of the standard sklearn pipeline for preprocessing.

Quick Start

If you want to start using the package right away, we recommend using one of the singular spectrum transformation algorithms (SST). The first step is to install the package using pip. Then you can use the following example code:

import numpy as np
import matplotlib.pyplot as plt
from changepoynt.algorithms.esst import ESST
from changepoynt.algorithms.sst import SST
from changepoynt.visualization.score_plotting import plot_data_and_score

# create a signal that goes from steady to exponential decline into a sine curve
exp_signal = np.exp(-np.linspace(0, 5, 200))
steady_after = np.exp(-5)*np.ones(150)
steady_before = np.ones(200)
sine_after = 0.2*np.sin(np.linspace(0, 3*np.pi*10, 300))

# make the signal
signal = np.concatenate((steady_before, exp_signal, steady_after, sine_after))
signal += 0.01*np.random.randn(signal.shape[0])

# make change point detection
esst_detector = ESST(40)
esst_detection = esst_detector.transform(signal)

# make change point detection
sst_detector = SST(40, method='rsvd', mitigate_offset=True)
sst_detection = sst_detector.transform(signal)

# make the plot
plot_data_and_score(signal, esst_detection)
plt.gcf().tight_layout()
plot_data_and_score(signal, sst_detection)
plt.gcf().tight_layout()
plt.show()

The result looks like this:

ESST: image SST: image

Examples

You can find example code within the examples folder of this repository. We also wanted to tease the functionality using two different signals in order to show the capabilities of one of our recommended algorithms ESST or SST. If you want to use the algorithms on the contents of a CSV directly, there is a frontend demonstrator currently hosted here (the adress is https://demo.changepoynt.de/, the code for the demonstrator is here).

The first application is a simulated temperature of a component in a power plant during shutdown. We artificially added a disturbance at the end of the shutdown, to show the capability of the algorithm to detect a change even in case of another major change.

image

The other application is for anomaly detection within periodic signals. The example is time series 34 from the Hexagon ML/UCR Time Series Anomaly Detection dataset, where we set the window size for the ESST to three times the estimated period in samples (estimated using maximum of FFT).

image

Both plots have been created using changepoynt.algorithms.esst and the plot function from changepoynt.visualization.score_plotting.

Installation

You can install changepoynt from the common package index PyPi using the following line with pip:

pip install changepoynt

Please be aware that we are currently in an alpha development phase, as this is part of a research project at the FAU Erlangen together with SIEMENS Energy developed by me. Nevertheless, we aim to be open-source and try our best to guarantee that all the code we use has very permissive licenses.

You can also install the code from source using the following line

pip install git+https://github.com/Lucew/changepoynt.git

Frequently Asked Questions (FAQ)

Find the FAQs in the related Markdown document.

Algorithms

We are actively working on the package. Therefore, some algorithms are already available, while others are currently under development. An overview with sources can be seen here:

Algorithm Source Status
SST Idé Stable :heavy_check_mark:
Fast SST Weber et al. Stable :heavy_check_mark:
IKA-SST Idé Stable :heavy_check_mark:
Fast IKA-SST Weber et al. Stable :heavy_check_mark:
ESST Boelter & Weber et al. Stable :heavy_check_mark:
RuLSIF Liu et al. Stable :heavy_check_mark:
uLSIF Liu et al. Stable :heavy_check_mark:
KLIEP Liu et al. Planned
ClaSP Ermshaus et al. Deactivated :x:
FLUSS Gharghabi et al. Stable :heavy_check_mark:
FLOSS Gharghabi et al. Stable :heavy_check_mark:
BOCPD Adams et al. Experimental (mean change)
Baseline Weber Stable :heavy_check_mark:

Contributing

The main way of contributing to this package is by opening an issue or a pull request. We are happy to answer answer any questions you might have in an issue.

We always love to get feedback or new ideas. If you have any of those, feel free to open an issue. We try to get back to you as soon as we can.

If you are an author of a paper in the field or have another algorithmic idea: Feel free to open a pull request.

Known Issues

Division by Zero for SST with IKA

Some of the methods like SST (with method='ika') and (R)uLSIF have issues when running for trivial sections of time series. This includes steady series (e.g., only zero values, just lines with some slope). Intuitively, these methods aim to extract multiple characteristics in these sections but there are none, so they run into issues. Errors you will encounter are: "Matrix is singular" or "division by zero". Unfortunately, the math behind these errors is more complicated and I have not yet found a good way to circumvent these errors.

Fortunately, there is an easy workaround. Just add a small white noise to your signal, e.g. by adding signal += np.random.normal(0, 1e-4, size=signal.shape[0]). With noise much smaller than you signal you will not introduce large additional change points and the methods will not fail.

Outlook

We are actively working on the package, and currently have the following steps planned:

  • Researching intuitive explanations for SST parametrization
  • Setting up a documentation
  • Guideline for online deployment of the methods

If you have further ideas, do not hesitate to open a ticket or a pull request!

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

changepoynt-0.1.2.tar.gz (55.3 kB view details)

Uploaded Source

Built Distribution

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

changepoynt-0.1.2-py3-none-any.whl (59.1 kB view details)

Uploaded Python 3

File details

Details for the file changepoynt-0.1.2.tar.gz.

File metadata

  • Download URL: changepoynt-0.1.2.tar.gz
  • Upload date:
  • Size: 55.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for changepoynt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 009e8a67af3e2577d4c72f1a8681646e2a8a25305d489a0138f627d9c9e6e890
MD5 9307428f4a002945c8d0467fddbd67b6
BLAKE2b-256 60cd651a8f8e26e101df17167a72a484467b5a91145984527c585ccfae176273

See more details on using hashes here.

Provenance

The following attestation bundles were made for changepoynt-0.1.2.tar.gz:

Publisher: test_pypi.yml on Lucew/changepoynt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file changepoynt-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: changepoynt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 59.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for changepoynt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2a638720780d2658f6373424756a7190a2037fcd218f5794a19e8d9de12f604c
MD5 c0a5c438e168ca4e4bcbaaa2ba60ebad
BLAKE2b-256 eb708317be0de1423051278a661f11fdd5dd7e2e21548a6e12f16627bb9829be

See more details on using hashes here.

Provenance

The following attestation bundles were made for changepoynt-0.1.2-py3-none-any.whl:

Publisher: test_pypi.yml on Lucew/changepoynt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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