cusum

Different flavours of CUSUM for change point detection

https://github.com/giobbu/cusum

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.5%) to scientific vocabulary

Keywords

adaptive-learning change-detection cumulative-sum data-streaming recursive-least-squares sequential-monitoring time-series
Last synced: 6 months ago · JSON representation ·

Repository

Different flavours of CUSUM for change point detection

Basic Info
  • Host: GitHub
  • Owner: giobbu
  • License: mit
  • Language: Jupyter Notebook
  • Default Branch: main
  • Homepage:
  • Size: 26.8 MB
Statistics
  • Stars: 3
  • Watchers: 1
  • Forks: 1
  • Open Issues: 0
  • Releases: 1
Topics
adaptive-learning change-detection cumulative-sum data-streaming recursive-least-squares sequential-monitoring time-series
Created about 2 years ago · Last pushed about 1 year ago
Metadata Files
Readme License Citation

README.md

Python Tests on macOS Status DOI

Change Point Detection

Change point refers to the phenomenon where the statistical properties of a target variable or data distribution change over time. Detecting change point is crucial in various domains such as financial markets, healthcare, and online advertising to adapt models and decision-making processes to changing environments.

Example: Monitoring learning model performance

Model drift refers to the degradation of machine learning model performance due to changes in data or in the relationships between input and output variables.

Generate date

Apply data generator to create time-series data with abrupt mean-shift

Image Alt Text

Simulating streaming data

Simulate a streaming data scenario by iterating over a sequence of observations. During each iteration: 1. Make prediction with recursive-least-squares model 2. Retrieve the true value 3. Update model's parameters 4. Compute residual 5. Use the CUSUM detector on the residuals

Model Predictions Animation

Change Point Detectors

Change point detectors are algorithms designed to detect change points in streaming data or sequential observations. These detectors analyze the data stream and identify points where the underlying data distribution has changed significantly.

Generate Data with Mean Shift

```python import numpy as np from source.generator.changepointgenerator import ChangePointGenerator from source.detector.cusum import CUSUMDetector, ProbCUSUMDetector, ChartCUSUM_Detector

set seed

np.random.seed(12)

Generate time series data with change points

generator = ChangePointGenerator(numsegments=3, segmentlength=1000, changepointtype='suddenshift') generator.generatedata()

Plot the generated data

generator.plot_data() ```

Three commonly used drift detectors are:

1. CUSUM Detector (The PageHinkley Algorithm)

The CUSUM detector monitors the cumulative sum of deviations between observed data points and a reference value. When the cumulative sum exceeds a predefined threshold, it signals the presence of a change point.

```python

Detect change points using CUSUM Detector

cusumdetector = CUSUMDetector(warmupperiod=500, delta=3, threshold=10) cusumposchanges, cusumnegchanges, cusumchangepoints = cusumdetector.detectchangepoints(np.array(generator.data))

Plot the detected change points using CUSUM Detector

cusumdetector.plotchangepoints(generator.data, cusumchangepoints, cusumposchanges, cusumneg_changes) ```

Image Alt Text

2. Probabilistic CUSUM Detector

The Probabilistic CUSUM detector extends the CUSUM method by incorporating statistical probability measures. It evaluates the probability of observing deviations between data points, making it more robust to variations in data distribution.

```python

Detect change points using Probabilistic CUSUM Detector

probcusumdetector = ProbCUSUMDetector(warmupperiod=500, thresholdprobability=0.01) probprobabilities, probchangepoints = probcusumdetector.detectchangepoints(np.array(generator.data))

Plot the detected change points using Probabilistic CUSUM Detector

probcusumdetector.plotchangepoints(generator.data, probchangepoints, prob_probabilities) ```

Image Alt Text

3. CUSUM Control Chart Detector

The Control Chart CUSUM detector is a specialized form of CUSUM change point detection algorithm commonly used in quality control and process monitoring applications.

3.1 CUSUM of Deviations

```python

Detect change points using Control Chart CUSUM Detector

chartcusumdetector = ChartCUSUMDetector(warmupperiod=500, level=3, deviationtype='dev') upperlimits, lowerlimits, cusums, changepoints = chartcusumdetector.detectchangepoints(np.array(generator.data))

Plot the detected change points using Control Chart CUSUM Detector

chartcusumdetector.plotchangepoints(np.array(generator.data), changepoints, cusums, upperlimits, lower_limits) ```

Image Alt Text

3.2 CUSUM of Squares

```python

Detect change points using Control Chart CUSUM Detector

chartcusumdetector = ChartCUSUMDetector(warmupperiod=500, level=3, deviationtype='sqr-dev') upperlimits, lowerlimits, cusums, changepoints = chartcusumdetector.detectchangepoints(np.array(generator.data))

Plot the detected change points using Control Chart CUSUM Detector

chartcusumdetector.plotchangepoints(np.array(generator.data), changepoints, cusums, upperlimits, lower_limits) ```

Image Alt Text

Extensions: KS-CUM Detector (Kolmogorov-Smirnov Test)

```python

import numpy as np from source.generator.changepointgenerator import ChangePointGenerator from source.detector.cusum import KSCUMDetector

Set seed

np.random.seed(11)

Generate time series data with change points

generator = ChangePointGenerator(numsegments=3, segmentlength=1000, changepointtype='suddenshift') generator.generatedata()

Plot the generated data

generator.plot_data()

Kolmogorov-Smirnov Test

ksdetector = KSCUMDetector(windowpre=600, windowpost=300, alpha=0.001) ksstatistics , pvalues, changepoints = ksdetector.detectchangepoints(np.array(generator.data)) ksdetector.plotchangepoints(generator.data, changepoints, pvalues) ```

Image Alt Text

Owner

  • Name: Giovanni Buroni
  • Login: giobbu
  • Kind: user
  • Location: Lisbon, Portugal

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software in your research, please cite it as follows:"
authors:
  - name: "Giovanni Buroni"
    orcid: "https://orcid.org/0000-0002-1825-0097"
    affiliation: "INESC TEC - Institute for Systems and Computer Engineering, Technology and Science"
title: "CUSUM"
version: "v0.1.0-alpha"
doi: "https://doi.org/10.5281/zenodo.14052654"  # If available
url: "https://github.com/giobbu/CUSUM"
date-released: "2024-11-07"  # Date of the release
license: "MIT"  # Or any other license you're using
repository: "https://github.com/giobbu/CUSUM"

GitHub Events

Total
  • Release event: 1
  • Watch event: 4
  • Push event: 31
  • Create event: 1
Last Year
  • Release event: 1
  • Watch event: 4
  • Push event: 31
  • Create event: 1