Skip to main content

scan-cpd: Sequentially Detecting Change-points via Adaptive Nonparametric Inference

PyPI Python versions Downloads GPL-3.0 License

Tests Linux Windows macOS

scan-cpd provides tools for detecting change points general distributional shifts in long univariate time series using Integral Probability Metrics (IPMs). It is aimed at research workflows where users need to simulate time series, detect changes across multiple window sizes, localize change-point positions, evaluate accuracy, and visualize diagnostics. The Python interface is backed by a Rust/PyO3 computation core.

Installation

SCAN Py can be installed from PyPI using pip:

pip install scan-cpd

For local development, clone the repository and build the package in an isolated virtual environment:

python -m venv .venv
.venv\Scripts\activate
python -m pip install -U pip maturin
maturin develop --release

Change-point detection

The main function provided by SCAN Py is scan_cpd, which provides a unified interface for running the SCAN change-point detection framework. It detects change points in a one-dimensional time series by scanning the data with multiple local window sizes. The type of change to detect is controlled by the change_type argument.

Supported change types include:

change_type Explanation
"mean" Detects changes mainly in the location or average level of the series.
"var" Detects changes mainly in the variability or scale of the series.
"distribution" Detects broader distributional changes, not restricted to only mean or variance shifts (includes both mean and variance together).

Example usage

The following example simulates a univariate time series with multiple mean changes and applies scan_cpd using several window sizes.

T = 200_000 # Length of the time series
K = 100 # Number of change-points
min_seg_len = 1000 # Minimum distance between two change-points
seed = 2000 # Seed for reproducibility

x, true_cps, _, _ = simulate_time_series(
    n=T,
    n_cps=K,
    min_seg_len=min_seg_len,
    change_type="mean",
    seed=seed,
)

select window sizes required for the ensemble model. This can be done using the choose_window_sizes function. With

from scan import choose_window_sizes

window_sizes = choose_window_sizes(
    series_length=200_000,
    n_windows=7,
    seed=500,
)

Output:

print(window_sizes)

[134, 225, 241, 294, 323, 325, 394]

Detecting change-points

Standerdize the series and then detect change-points using the scan_cpd function:

x_std = (x - np.mean(x)) / np.std(x)

result = scan_cpd(
    x_std,
    window_sizes=window_sizes,
    n_boot=400,
    alpha=5, # significance level
    vote_threshold=0.5,
    random_state=1000, # for reproducibility of the tapred block bootstrap
    n_jobs=-1,  # use all available CPU threads
)

The function returns a results object, change points can be accessed with the

Output:

print(result.change_points)

Visualizing

Visualizing the detected change-points The detected change points can also be visualized using plot_change_points. The function returns a plotnine plot object showing the time series as a dark blue line and the detected change points as vertical dashed orange lines.

plot_change_points(x, result)

Detected change points To save the plot as an image:

plot = plot_change_points(x, result)
plot.save("plots/change_points.png", width=12, height=4.5, dpi=300)

Determine vote threshold using the scree plot

The voting scree plot helps inspect how many candidate change points are retained as the ensemble voting threshold changes. It is useful for choosing a sensible vote_threshold before finalizing the detected change points.

from scan import plot_vote_scree
plot_vote_scree(result)

The x-axis shows the voting threshold, denoted by ν, and the y-axis shows the number of retained change points at each threshold. A lower threshold keeps more candidate change points, while a higher threshold keeps only candidates supported by more window sizes. In practice, choose a value near the point where the curve begins to flatten. This avoids keeping many weak detections while preserving stable change points that are supported across multiple window sizes.

Majority voting scree plot

SWAL Statistic

The swal_statistic function is a single change-point detection tool for univariate time series. It is useful after a suspicious local region has been identified and you want to estimate the most likely split point inside that region. Additionally, this can be used as a custom cost function with other change-point detction methods such as bianr segmentation, PELT.

It can be used for changes in:

See the following usage examples for changes in mean and general distributional shifts.

Change in mean

import numpy as np
from scan import swal_statistic

rng = np.random.default_rng(123)

# Simulate a time seires with a single change in mean
x_region = np.r_[
    rng.normal(0.0, 1.0, 80),
    rng.normal(2.0, 1.0, 80),
]

local_cp = swal_statistic(x_region)

print(local_cp)
time_series_plot = plot_time_series(
    x_region,
    y_label="Value",
    title="Local time series",
)

swal_curve_plot = plot_swal_curve(x_region)

Change in distribution

import numpy as np
from scan import swal_statistic, plot_time_series, plot_swal_curve

rng = np.random.default_rng(123)

# Distributional change:
# first segment is standard normal,
# second segment is centered exponential.
x_region = np.r_[
    rng.normal(0.0, 1.0, 100),
    rng.exponential(scale=1.0, size=100) - 1.0,
]

local_cp = swal_statistic(
    x_region,
)

print(local_cp)

Documentation

More detailed documentation is available here: scan-cpd documentation

Citation

Include the citation to the paper here

Download files

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

Source Distribution

scan_cpd-0.2.2.tar.gz (10.2 MB view details)

Uploaded Source

Built Distributions

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

scan_cpd-0.2.2-cp313-cp313-win_amd64.whl (208.4 kB view details)

Uploaded CPython 3.13Windows x86-64

scan_cpd-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (340.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

scan_cpd-0.2.2-cp313-cp313-macosx_11_0_arm64.whl (292.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

scan_cpd-0.2.2-cp312-cp312-win_amd64.whl (208.9 kB view details)

Uploaded CPython 3.12Windows x86-64

scan_cpd-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (341.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

scan_cpd-0.2.2-cp312-cp312-macosx_11_0_arm64.whl (293.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

scan_cpd-0.2.2-cp311-cp311-win_amd64.whl (209.6 kB view details)

Uploaded CPython 3.11Windows x86-64

scan_cpd-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (342.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

scan_cpd-0.2.2-cp311-cp311-macosx_11_0_arm64.whl (293.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

scan_cpd-0.2.2-cp310-cp310-win_amd64.whl (210.0 kB view details)

Uploaded CPython 3.10Windows x86-64

scan_cpd-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (342.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

scan_cpd-0.2.2-cp310-cp310-macosx_11_0_arm64.whl (293.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

scan_cpd-0.2.2-cp39-cp39-win_amd64.whl (210.0 kB view details)

Uploaded CPython 3.9Windows x86-64

scan_cpd-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (342.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

scan_cpd-0.2.2-cp39-cp39-macosx_11_0_arm64.whl (293.8 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file scan_cpd-0.2.2.tar.gz.

File metadata

  • Download URL: scan_cpd-0.2.2.tar.gz
  • Upload date:
  • Size: 10.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for scan_cpd-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4cb81c0cc7058c7193031d1d05f338486680819916785f5f47ed9617b3f0a61c
MD5 fde14e2a433776326520798371d20178
BLAKE2b-256 8166245e1bf45f2c92447c26761e33caaed221704ab30011208f393e420b69d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2.tar.gz:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 208.4 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for scan_cpd-0.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0c23fd8a5e15e643de791f9328ef95612219d71eee853f203259080e4ebef99c
MD5 bd1b7179d109f4f7b4d9814bc4e90666
BLAKE2b-256 606cb48c3655fea1089b48270feac247f297b975c7d2a5804b2a131f93412220

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp313-cp313-win_amd64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 063722337c06f2a051c7ae5da608db811453386d809013f3e4dc737afefff0a3
MD5 55dad5d2323747f8dd907653b414f455
BLAKE2b-256 703d37148a1665c565aaeb6710975bcd425f9fe2daf4a5f479f2a6448aadd357

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b1401c0b35e591aa90be43d5576e13b2d6382e3fb8cbaf6c64f8c91edaa351d
MD5 113da16f20c607efbcf42d8a5e71f49d
BLAKE2b-256 2abd7d180162602f8f56583ccd5b0ad3183ec4fb0e92270d704564b82d1cf73b

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 208.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for scan_cpd-0.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9591a87c0c8707b7c30a44c2c8827f7c8c0173f17e8790af824c0518f99d2a30
MD5 982f5ee786b685aef2a9e0bcacbe5777
BLAKE2b-256 2dda0afc67a90f50f68549959d3febe465f32d2fce1f35215f03250ab7f054cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp312-cp312-win_amd64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6287176dbf5063a7fccb6229c9ee9d25eb843141fa559cbcb85b481282f555de
MD5 c8aae9e27f2cdd8d3a7b5ad9ed5968a1
BLAKE2b-256 03987246ad6b8318ba3a618266935fccd5847b052e51884afd8ab9ab887d2b7e

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7b0dae019c5c7ba3d994c25fdf5aa4da685d79fcc609723d56079575e798fe63
MD5 8d3c65f0cf302c6e387bdeb7d1c3551a
BLAKE2b-256 c485e4847de83ac75f8b03c37490f2b41c77d2cd0f09a5b593570515cf904d17

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 209.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for scan_cpd-0.2.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 da801925b982fec728ee668e90888eda4616ac8d5703bb8aedd628e9a12ba6d5
MD5 821866c7494b9fddc8c37cae1e2a8895
BLAKE2b-256 07a1e0fca323b87d7397c3e9749abebeae9ae1968951f80048f1ec50e73f0c98

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp311-cp311-win_amd64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bc230bb12a46a1f53082a0bd53fd81140d08c91469d47fbd327f56e9741d90ba
MD5 5868998e473fe4171ff5e443850caf4f
BLAKE2b-256 d61f00f5b882d6676088d22fb5f0f2868cd1c2b736919beefcd9a7f9c5cff76d

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be7b643d52e6123e672f0b834a756ee7a9ef4fcd8d19aee7e841666c5acb4078
MD5 38709a7b4778dfed7994d1d66885b6ac
BLAKE2b-256 d40cac14206f628871f995ca7d1937b2f4910e74174296914a196f2cec5e2cd3

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 210.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for scan_cpd-0.2.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 33a34f64d275ea306450c0686081a2bc774f2695fe1772cdd2ba67c00abf9304
MD5 923dbb90a0c450267850ab694a0a3635
BLAKE2b-256 e2f7193ee2d5cbb524ac03d2b48f2fd000611e9b7fe6b871e92187faa852e4c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp310-cp310-win_amd64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6346d4c5daf49f3e967175e592e0d7f3e38161ddece52cb5f578678d90554827
MD5 98eaf02e7628af427501b361106f2ce9
BLAKE2b-256 5ca951925a839264a0dfdb002bdd328191f1324d8be25de483784568cda03f82

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 59975612692e87e5a46d952ab3d5b66f1fc5a092e82eba069b90615ec5e45430
MD5 a55b3f1daa702b8527bf231c2b6ac270
BLAKE2b-256 379363f54c9fac686ef24e1c6f3c9e925e62ce4b609689297e9c22b2aee9334d

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 210.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for scan_cpd-0.2.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fb89b92e5467fcbb488733a1a25b219c1b783d1f5efa8a166d4af20d5be9276f
MD5 005d28da02bb8a3faa519157d88ca438
BLAKE2b-256 7aa4845dcc76095527c7abfcefa891e035ca57574a9df8120f5e101a835a98b5

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp39-cp39-win_amd64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 278b4fc163f7294e38cf5a53eca5f1504bfe12fe719a216a0043585056318499
MD5 42560f87a40b4bc7a1049fa239888e34
BLAKE2b-256 d443f027857621df8619e1acf21850da679698b2e2e20ad6c1dd8d12b6663c28

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

File details

Details for the file scan_cpd-0.2.2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 648884ebb47dee5c2b5feba1ea989a3d638df97a331f71cf669a95a016d4b8fd
MD5 f4165456b2c053dbf2c007621bc40613
BLAKE2b-256 db94b59ba7ba6fbee7dc591fd46fe149dda5abc45ddd51b13310cba4e0cb5f85

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.2-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: release.yml on Prabashoka/scan-py

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

Release history Release notifications | RSS feed

0.2.3

16 files

This release

0.2.2 This release

16 files

0.2.1

16 files

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