math::changepoint(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

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:

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 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 to 0.5, typically between 0.5 and 1.0)
    • -hfactor value β€” The factor determining the limits between which the "cusum" statistic is accepted (typically 3.0–5.0, default 4.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:
    • -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 to 0.5, typically between 0.5 and 1.0)
    • -hfactor value β€” The factor determining the limits between which the "cusum" statistic is accepted (typically 3.0–5.0, default 4.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 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)

πŸ“ KEYWORDS πŸ“

control, statistics


🌈 CATEGORY 🌈

Mathematics


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