ChangeFinder online#

ChangeFinder online – alarms on the two-stage outlier score of ChangeFinder, raised as the stream arrives.

Description#

ChangeFinder reduces change point detection to outlier detection with two sequentially discounting autoregressive (SDAR) models. The first scores each point by its prediction loss; these scores are averaged over the last T points; the second model scores that averaged series, and the average of its losses over the last T points is the change point score. Every value depends on past points only, so the score is computed as the stream arrives.

The online detector raises an alarm when the score goes above a threshold, and ignores alarms that come less than min_distance points after the previous one (the paper’s alarm policy). Each alarm is emitted once, as an event whose detection time is the point that raised it. ChangeFinder does not say where a change starts: the position of an event is the point of largest first-stage score among the last T points, since a change raises the prediction losses of its first points, which the moving averages then delay.

By default, the threshold is the mean plus threshold_factor (2) standard deviations of the positive scores seen so far, the current one included: the data-driven threshold of ChangeFinder, which uses the whole series. A fixed threshold replaces it.

See Online detectors for the update API and the events it returns.

Type: change point detection, online
Supervision: unsupervised
Scope: univariate and multivariate (L2 norm of the channels)
Complexity: \(O(d + k^{3})\) time per point, where k is the AR order; memory \(O(k^{2} + T)\)

Parameters#

Name

Type

Default

Description

order

int

5

AR order k of both SDAR models.

discount

float

0.005

Discounting rate r in (0, 1); larger values forget the past faster.

smooth_window

int

7

Length T of both moving averages and of the look-back window that places a change point.

score

str

"logarithmic"

Loss of both stages: "logarithmic" (Gaussian negative log-likelihood) or "quadratic" (squared prediction error).

threshold

float / None

None

Alarm threshold; None = mean + threshold_factor × std of the positive scores seen so far.

threshold_factor

float

2.0

Standard deviations of the data-driven threshold.

min_distance

int

20

Refractory period: alarms less than min_distance points after the previous one are ignored.

axis

int

0

Time axis of the input.

order, discount, smooth_window and score take the defaults of ChangeFinder, so that both compute the same score by default. The paper’s simulations use an AR order of 2 at the first stage and 3 at the second, \(r = 0.02\), \(T = 5\), the logarithmic loss at the first stage and the quadratic loss at the second (Section 5.1); one order and one loss for both stages cannot express them. min_distance=20 is the paper’s alarm policy (Section 5.2).

Usage#

import numpy as np
from tsseg.algorithms import ChangeFinderOnlineDetector

rng = np.random.default_rng(0)
X = np.concatenate([rng.normal(0, 1, 500), rng.normal(5, 1, 500)])

det = ChangeFinderOnlineDetector()
for start in range(0, X.size, 100):          # a stream, 100 points at a time
    for event in det.update(X[start : start + 100]):
        print(event["position"], event["detection_time"], event["score"])

ChangeFinderOnlineDetector().fit_predict(X)  # batch use: replay of the stream

The score is zero on the first 2 * max(2 * order, 30) + smooth_window points (67 by default), which initialise the two models, and alarms start smooth_window - 1 points later (73 by default): a shorter series gives no change point.

Implementation notes#

  • The score is computed by the SDAR code of ChangeFinderDetector; tests check that both give the same value at every point (bit for bit) on any series long enough for the second stage to start.

  • Departures of that shared score from the paper: the logarithmic loss of a point uses the residual variance already updated with that point, where the paper scores it under the model learned up to the previous point (equation (1)); the models are initialised by Yule-Walker estimates on max(2 * order, 30) points, where the paper learns online from the start with dummy scores for the first averages (Section 3.1, equation (3)).

  • Alarms: one alarm per upward crossing of the threshold; a crossing within the refractory period is not raised later. The paper raises an alarm at every point above the threshold outside the refractory period, so a score that stays above it raises an alarm every min_distance points; it sets the threshold by hand. ChangeFinderDetector instead keeps, over the whole series, the local maxima above a threshold computed on all the scores.

  • Early in the stream, the data-driven threshold rests on few scores, and false alarms are more likely there. It keeps the positive scores, as the batch class: with the logarithmic loss, most change point scores are negative, and the rule applies to their upper tail.

  • The change point position is not part of the paper, which scores alarms by their detection time. When an alarm comes smooth_window points or more after the change, the position falls after the change.

  • Multivariate series are reduced to the L2 norm of their channels at each point (multivariate_strategy="l2" of ChangeFinderDetector).

  • Reproduction (tests/reproduction/test_changefinder_online_paper.py), on the paper’s simulated data sets, regenerated with ten seeds: with the paper’s settings as far as they can be expressed (order 2, \(r = 0.02\), \(T = 5\)), the averaged benefit is 0.783 at a false alarm rate of 0 and 0.901 at 0.077, against about 0.75 and 0.87 read off Fig. 8. With the defaults (not the paper’s settings) and the data-driven threshold, alarms follow the jumps of mean of size \(10 - x\) for \(x \le 6\) and every increase of the variance but no decrease, the claims of Section 5.1 (Figs. 3 and 7). The second data set (Figs. 4, 5 and 9) is not reproduced. On the first data set (jumps of 5), the median delay is 2 points and 93% of the positions are within 2 points of the change; the scores of the changes raise the data-driven threshold, and all 17 false alarms of the ten series come before the first change. On a change-free AR(2) stream, the default threshold raises about 12 false alarms per 10,000 points (about 5 with threshold_factor=3): set threshold or threshold_factor for the false alarm rate the application tolerates.

Reference#

Takeuchi, J. and Yamanishi, K. (2006). A unifying framework for detecting outliers and change points from time series. IEEE Transactions on Knowledge and Data Engineering, 18(4), 482–492. https://doi.org/10.1109/TKDE.2006.1599387