math::changepoint(3tcl)
β¨ math::changepoint β¨
okay bestie, so this is the math::changepoint page from the Tcl Math Library β yes the 3tcl one β and it's genuinely one of my faves because it's literally about catching the exact moment your data decides to switch up on you π
NAME π
math::changepoint β change point detection methods. that's it, that's the whole vibe. finding where the plot twist happens in your numbers π
SYNOPSIS πΈ
first you gotta require the whole squad:
package require Tcl 8.6 9
package require TclOO
package require math::statistics
package require math::changepoint ?0.2?
and then the actual commands, look:
::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 for figuring out whether a series of data contains a shift in the mean or not. heads up though β these methods only tell you if a shift in the mean is probably happening. because data is stochastic (aka chaotic and dramatic by nature), false positives are absolutely possible, so don't come for me if your algorithm gaslights you a little π
The CUSUM method ships in two flavours: an "offline" version and an "online" version, so you can use it either on a complete data series or for detecting changes in data that arrives one by one, drip by drip, like your fave posting stories π
The implementation is mostly based on these websites, no cap:
- https://www.itl.nist.gov/div898/handbook/pmc/section3/pmc323.htm
- https://en.wikipedia.org/wiki/CUSUM
Basically: you accumulate the deviation of the data from a given target value, and when the total deviation gets too large, a change point gets reported. periodt.
A second method, binary segmentation, is only implemented as an "offline" method, because it needs to examine the data series as a whole. it's giving "i need to see the full picture before i judge" energy π
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 of 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 (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). literally just "where did it all go wrong" but for numbers π- double
dataβ Series of data to be examined - list
argsβ Optional list of key-value pairs:-target valueβ The target (or mean) for the time series-tolerance valueβ The tolerated standard deviation-kfactor valueβ The factor by which to multiply the standard deviation (defaults to0.5, typically between0.5and1.0)-hfactor valueβ The factor determining the limits betweem which the "cusum" statistic is accepted (typicaly3.0-5.0, default4.0)
- double
::math::changepoint::cusum-online ?args?β Class to examine data passed in against expected properties. At least the keywords-targetand-tolerancemust be given. mandatory, bestie, don't skip them β- list
argsβ List of key-value pairs:-target valueβ The target (or mean) for the time series-tolerance valueβ The tolerated standard deviation-kfactor valueβ The factor by which to multiply the standard deviation (defaults to0.5, typically between0.5and1.0)-hfactor valueβ The factor determining the limits betweem which the "cusum" statistic is accepted (typicaly3.0-5.0, default4.0)
- list
$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. so it's basically a vibe check that answers in binary π- double
valueβ The new value
- double
$cusumObj resetβ Reset the cumulative sum, so that the examination can start afresh. the "we don't talk about what happened before" button π«Ά::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. it's giving detective energy π- list
dataβ Data to be examined - list
argsβ Optional key-value pairs:-minlength numberβ Minimum number of points in each segment (default:5)-threshold valueβ Factor applied to the standard deviation functioning as a threshold for accepting the change in cost function as an improvement (default:1.0)
- list
KEYWORDS π
control, statistics
CATEGORY π§
Mathematics
COPYRIGHT πΈ
Copyright (c) 2020 by Arjen Markus
and that's the whole page, bestie β every flag, every default, every link, all of it, no cap π
okay so fun lil sign-off: this came out of tcllib, version 0.2, and it's the math::changepoint(3tcl) page. slay, go detect some change points, you've got this πβ¨π¦
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- 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