math::changepoint(n)
math::changepoint πβ¨
okay bestie, so this is the math::changepoint page from the Tcl Math Library, and it's literally the whole vibe of "waitβ¦ did the mean of my data just shift?" π¦
β¨ NAME β¨
math::changepoint β change point detection methods π
πΈ SYNOPSIS πΈ
package require Tcl 8.6 9
package require TclOO
package require math::statistics
package require math::changepoint ?0.2?
::math::changepoint::cusum-detect data ?args?
::math::changepoint::cusum-online ?args?
$cusumObj examine value
$cusumObj reset
::math::changepoint::binary-segmentation data ?args?
π DESCRIPTION π
So the math::changepoint package implements a bunch of well-known methods to figure out if a series of data contains a shift in the mean or not. And no cap, these methods only ever indicate that a shift in the mean is probably there. Because the data you're analysing is stochastic in nature, false positives are possible β that's just the deal, bestie. π
The CUSUM method is implemented in both an "offline" version and an "online" version, so you can use it either on a complete data series or to detect changes in data that comes in one by one. π«Ά
The implementation has mostly been based on these websites:
- https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc323.htm
- https://en.wikipedia.org/wiki/CUSUM
Basically, the deviation of the data from a given target value gets accumulated, and when that total deviation becomes too large, a change point is reported. β
A second method, binary segmentation, is implemented only as an "offline" method, because it literally needs to examine the data series as a whole. π§
In the variant contained here, the following ideas have been used:
- The segments in which the data series may be separated should not be too short, otherwise the ultimate result could be segments that are only one data point long. So a minimum length is used.
- To make the segmentation worthwhile there should be a minimum gain in reducing the cost function (that's the sum of the squared deviations from the mean for each segment).
This may not be in agreement with the descriptions of the method found in various publications, but it is simple to understand and intuitive, and honestly? we love that for it. π
One publication that provides more information on the method in general is "Selective review of offline change point detection methods" by Truong et al. β https://arxiv.org/abs/1801.00718
π PROCEDURES π
The package defines the following public procedures:
π₯ ::math::changepoint::cusum-detect data ?args?
Examine a given data series and return the location of the first change (if any). π
double dataβ Series of data to be examinedlist argsβ Optional list of key-value pairs:-targetvalue β The target (or mean) for the time series-tolerancevalue β The tolerated standard deviation-kfactorvalue β The factor by which to multiply the standard deviation (defaults to0.5, typically between0.5and1.0)-hfactorvalue β The factor determining the limits between which the "cusum" statistic is accepted (typically3.0β5.0, default4.0)
π¦ ::math::changepoint::cusum-online ?args?
Class to examine data passed in against expected properties. At least the keywords -target and -tolerance must be given. π¨
list argsβ List of key-value pairs:-targetvalue β The target (or mean) for the time series-tolerancevalue β The tolerated standard deviation-kfactorvalue β The factor by which to multiply the standard deviation (defaults to0.5, typically between0.5and1.0)-hfactorvalue β The factor determining the limits between which the "cusum" statistic is accepted (typically3.0β5.0, default4.0)
β¨ $cusumObj examine value
Pass a value to the cusum-online object and examine it. If, with this new value, the cumulative sum remains within the bounds, zero (0) is returned β otherwise one (1) is returned. it's giving pass/fail energy fr fr π
double valueβ The new value
π $cusumObj reset
Reset the cumulative sum, so that the examination can start afresh. fresh start, main character energy. π
π ::math::changepoint::binary-segmentation data ?args?
Apply the binary segmentation method recursively to find change points. Returns a list of indices of potential change points.
list dataβ Data to be examinedlist argsβ Optional key-value pairs:-minlengthnumber β Minimum number of points in each segment (default:5)-thresholdvalue β Factor applied to the standard deviation functioning as a threshold for accepting the change in cost function as an improvement (default:1.0)
π KEYWORDS π
control, statistics
π CATEGORY π
Mathematics
π COPYRIGHT π
Copyright (c) 2020 by Arjen Markus
ngl bestie, if you're out here detecting change points, remember: false positives are possible and that is NOT your fault. π
tcllib version 0.2 of math::changepoint(n) β that's the whole manual, slayed, no cap. πβ¨π¦ go forth and segment, you absolute icon π
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- Copyright (c) 2020 by Arjen Markus
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms