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.3.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.3-cp313-cp313-win_amd64.whl (208.4 kB view details)

Uploaded CPython 3.13Windows x86-64

scan_cpd-0.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (341.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

scan_cpd-0.2.3-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.3-cp312-cp312-macosx_11_0_arm64.whl (293.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

scan_cpd-0.2.3-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.3-cp311-cp311-macosx_11_0_arm64.whl (293.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

scan_cpd-0.2.3-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.3-cp310-cp310-macosx_11_0_arm64.whl (293.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

scan_cpd-0.2.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: scan_cpd-0.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 c46d71553fb39f1c155b326d1c589d8ac231e8eeb8c3248f619c355b82632193
MD5 cf1f5de07a1702fec3a5bef6430ba43c
BLAKE2b-256 09f3c10b409c59ebbfc7993e762934e32cb70340bfdca7df63697c26cf3d4dec

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3.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.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.3-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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0a7f6495d514983705160c93f90a55662047d3ea8f50304ed5b8baa5e0249665
MD5 f198b2bc6206c4e1436b31b0de29d56a
BLAKE2b-256 b90625a9259bd394ff5c991a46305b079b4613836665d8edefc657197ebe317d

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2a5961a9532d47c98cafaa5c2086851803f0ec100010dec0819fd9569b3ab0dd
MD5 e588b397bb82291c2d0e315588251d91
BLAKE2b-256 fca1eb729d46253195f50eeed3e2f5a3386a6c1ac9413cb04efb6b748bb63209

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 668ceb631872247d80fb5f24da19ab9a4802f91d8c07b86730920c7106aa7ba1
MD5 8f9f7436e2ac2b62fc87c8e716467f5f
BLAKE2b-256 d0e070a4c0cb8005b24b89168f4ebda861af05bb319dacbc8dab4f621a424b97

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.3-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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7a7332412ee0b221243fa283326f966703cb692fde6d4401bc6905e40ea07259
MD5 a2c3523688622009398be8e9e32db92c
BLAKE2b-256 e012ee2edb2636b13b96607342890987ed95d2b2da6f85866857d952f74d0f8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aa6a11e0b36a389fb4d1dc57c956edce8b8eb9bf39185524f7f9dd4fab5ae172
MD5 1a16a330b6124cfa46e99fa4be2808ef
BLAKE2b-256 937cd8ae17f259f5263e9434ab9c4dfbe7ba591f3362de21aaf9b6495f16c5e7

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f7fb57a06c8b478a46a98045837ca0247a08e6c90697b20f6b66bb57cfbf2002
MD5 866263aee0b120e724d22fafa082292d
BLAKE2b-256 5c991596cb7e4d58e0762511920e9e67d86b9b3961c121af4184df5424fc07ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.3-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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 adbc00428266dbc757096aceb058b419551ed7525023ebfa6f2bfff1b0d26658
MD5 920d64126d3ace4f9c096493cc9ca4ea
BLAKE2b-256 20c1ea6df091b3ab681dbc7e8e58752b77289155d4fffc8e2f15ede407a7c6ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a1e0c3d95bd0aa41ca62d4e5aee156de019dac02035348646f1d8b1617405b2b
MD5 f36ae6fd634a9753fe89030e60187b53
BLAKE2b-256 c400896261ca7d483e42320bbc96ff4ce1f95f96f2d48741873492bb4da26bec

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3b8aca5326a6e6ff6157ed9f50a708486299053e63f56e23e3249f599f5a6172
MD5 c7b8586d5f1f323098927bde46a48e35
BLAKE2b-256 d15ed8a96e44b704c88f65cc54d5c0c6f398133a4ff57754a8e4f9ca3c0ee011

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.3-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.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 197d9289f86c73f2d697ff03358801deaacb1f8be433646deb74e4ea19d675ed
MD5 5769740b14100da5f08e7d4d383184e2
BLAKE2b-256 c27d6e549c9f03f6b2c2ee77c5bc5bcbc2c25c4ab9d5351b250a5de10b833b91

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8f2f48a7adb6cee00abca67ed37dcb40eac15026ef08b6ad68e75faa1ef1e4d
MD5 6032e00374418a3f0994b58837253340
BLAKE2b-256 a4cd960b517340658032ab71a7a32c61027f434e0dc64e93b1ea1f56108e5310

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b5d600d17db60eab1ae14a8054a20350637055f0c0ee553b35a2306d1152f3de
MD5 da75c7fe12e7f50407b12ad9b2d691da
BLAKE2b-256 edcb0e33635cde73fb7c89c5f097bc7e17d88e59d7eeed842823879ec7ac77f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: scan_cpd-0.2.3-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.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 66e4f51a66aa9beedf139589b172bae9b50447c0b7a9748595e72245eb849fb8
MD5 3348432582fa71a8b8a0b3e3706d6f27
BLAKE2b-256 9d86a11b7c0d8fd0cc244aec712ee770bca10b805e3eb68d1195e3c9af35ef48

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffbec8a77769ecd00c1b2b6cfa661114c27ede2a5d8de81495d96e5498d4be04
MD5 25d49862248e3d918a127eac48cda018
BLAKE2b-256 8ae6d56dee55d6c3f7c3bb9ca5e6753dbe2c14388827203fb1ebf11b0f465415

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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.3-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for scan_cpd-0.2.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7a868541e4c7640ebcc46692d8287e25ea8c12796e50955b46b77538ec3b3021
MD5 6077ea87ca856b1970b03cb9f1d1d186
BLAKE2b-256 14d9058c62a54837220fc4d26ae38bd0a5cffe170b9615dfa52cd344ca3153c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for scan_cpd-0.2.3-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

This release

0.2.3 This release

16 files

0.2.2

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