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

Uploaded CPython 3.13Windows x86-64

scan_cpd-0.2.1-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.1-cp313-cp313-macosx_11_0_arm64.whl (292.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

scan_cpd-0.2.1-cp312-cp312-win_amd64.whl (208.8 kB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

scan_cpd-0.2.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: scan_cpd-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 88e5686e8eab63f004ed522139dccf6cec23f75d40c80e7f8e82f9fb3267748c
MD5 059d5cb55ae413fd88d612d8052e9211
BLAKE2b-256 3888017e96c21401e9c762df1aa43b9090c03e7342b487c2f9431797e348777c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: scan_cpd-0.2.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 21853b2b9157219b9e5250c25fc6e5c9736fee5b94fe6a1d0d1ce4db4b489218
MD5 d8cc4ad000b10ad7a5c9d59cd98df727
BLAKE2b-256 cadb49cf6a4c7945333c1caeced4415095ae4121b6c366a78f8045c318422be4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e92b8ac30e38d7d2353972265a82ec2ffae92797354a2774f056350889528221
MD5 3c9efc25fa79d7341a62d3ab077d3f4b
BLAKE2b-256 a1f7d2a77156c316762021e53a63456a3c1f5a82a54458685fc6b1493b053f46

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66ceb0091c90c5e90055313cac42ef3884ff96de5b7acc42ab7146b8691c4cdc
MD5 7c25178236a1d4ab04b83a2bd035d1d8
BLAKE2b-256 82374176b8a6d594c9219f49f2300589311bebcdb6e219cd4fe8c6e035f4e25e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: scan_cpd-0.2.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 208.8 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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f44351ad0dde0457198cd9d379ec0e0c53f48b48a27c77db6c3f0d1f1bc69c30
MD5 77bbd83cda98361972e1cf606a97b625
BLAKE2b-256 9e86d9da8628eda3db02e971167c88437b59c7e1fb2f1c0f4f4ebe77fa9d8897

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4b217db47a312bdc6ca5f9f9cbf85a55b556b86fdac3ead20228a79e9d228125
MD5 de5c5a2dda37260b605dc29cfd205fdb
BLAKE2b-256 d1859e596226e7eecdfb5440d70474a7806dbacfdb8f379e656b27255524b5a5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 85e2a99a84cb2a4be3f2a14f0a61289341c547c6bdf231b1b44385f43449ea43
MD5 fe2d14dd660e78cc380d5e630f274a5a
BLAKE2b-256 7c83e909d7a16e364e8bd59e165cb9524ef536dc3fb9b6092b31726be5e62a4a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: scan_cpd-0.2.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0bebe0c007e5e8dca8e588a2f2d991f97b949babc08f6fe399d20922b2e0420a
MD5 8780283ea1ca18a3e08b1ea67552c5aa
BLAKE2b-256 e7126cea83153c4b1f70653539270b2e48f6f12658d969663c0040f0f7f7dab4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 70700f8fbab840ab8365b041e6a5cf8f6bc5ef367a06541529a1711f98e9a992
MD5 76a04edb44e201a7483cb3b3689690a8
BLAKE2b-256 a43cc50d68edbd6654f31ec52eea25688e2858f9ca75d4bde628a0172efb6c57

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dd84b2931c11bc31b7eb0dcd579faa74a455d66fdc473aee85d5ca5eafe26d3e
MD5 b54f68e7a8b241b934c6e192edcce467
BLAKE2b-256 801b77fd39ffd5b38824d79f805b5964bc002176ac91dc659854ec046d583b2d

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: scan_cpd-0.2.1-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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1a6e2ac25931745bc2c30bf8046eb07e24cb02005f4f7a9f9d03222a59263e56
MD5 adb3a44320ce5196f5180c25cabc9eb8
BLAKE2b-256 fe85ddb218c3365ad0133f3b87da2d11685d6dd6f68d349c998cea6609e0dd12

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7cce004362808be9528b8419d851fcdd2cce17921ab1ec544e8ef41c82a3e56e
MD5 d0f45e0a59f4828f074d99c8987ea8f0
BLAKE2b-256 2e916808c9ada0c1e7a468b771eaf768eb980dd5f002dd89a5c058458dae266d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 63b32f6dcf469d8d505c055b691c1d02d54ecbae89e8b15ef36c8586d6f982c9
MD5 f9574fea2b289f52c1b8c35b5449c350
BLAKE2b-256 040dd81d9779c6bd800e05ab8251d9062c18750c1fd909ff35b4595e792746dc

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: scan_cpd-0.2.1-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.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 90391b8fa49e27e24aa4ee28f14f80c6d65142727b0bf5b7d1a35b127bf38357
MD5 d35b8dd2ce4ca11ff107b30e9980e064
BLAKE2b-256 46798c4d1e923f0b9fcede3803f2f3fc7fe2dd7b15e574e33edbc36eebf5f80a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae969c060785b8b84cd8b672c8898f5c6a40544c9d139b5a4fac30275650ae14
MD5 b64aa44de8b0dfe63a57dcc698140c97
BLAKE2b-256 b295ddac1e9c7e63fd62840dbc21686f97fe51431be2cb45a6dac66ee5b7d33c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for scan_cpd-0.2.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b20e235c4398d46fb4feecfcb1e08573ba27182288495fb56798fbff7ddefb99
MD5 3766bc0b6180bd0ab87d1b7d06317197
BLAKE2b-256 fec21174f1a6371a9344be21fda17cfda8c6b750a44637c70624d685131309c6

See more details on using hashes here.

Provenance

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

0.2.2

16 files

This release

0.2.1 This release

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