Package 'spectralAnomaly'

Title: Detect Anomalies Using the 'Spectral Residual' Algorithm
Description: Apply the spectral residual algorithm to data, such as a time series, to detect anomalies. Anomaly scores can be used to determine outliers based upon a threshold or fed into more sophisticated prediction models. Methods are based upon "Time-Series Anomaly Detection Service at Microsoft", Ren, H., Xu, B., Wang, Y., et al., (2019) <doi:10.48550/arXiv.1906.03821>.
Authors: Allen OBrien [aut, cre, cph]
Maintainer: Allen OBrien <[email protected]>
License: MIT + file LICENSE
Version: 0.1.1
Built: 2025-02-13 03:41:39 UTC
Source: https://github.com/al-obrien/spectralanomaly

Help Index


Create anomaly score from input data

Description

Convert an input of numeric data, typically a time series, into a score for anomaly detection. The data is first extended to improve the detection latency, followed by saliency map creation. The score is calculated using the sliding window average for each point in the saliency map.

Usage

anomaly_score(x, score_window, spec_window = 3, m = 5)

Arguments

x

Numeric vector.

score_window

Integer value for the window width for scoring.

spec_window

Positive integer value for the window to calculate the averaged log spectrum.

m

Integer value representing the number of preceding points for the estimation.

Value

A numeric vector of anomaly scores.

Examples

tmp <- ts(rnorm(12*6,10,2), start=c(2009, 1), end=c(2014, 12), frequency=12)
anomaly_score(tmp, score_window = 25)

Apply threshold to anomaly score

Description

A helper function that wraps around quantile to apply a threshold to anomaly scores.

Usage

anomaly_thresh(x, threshold = 0.99, ...)

Arguments

x

Numeric vector of anomaly scores (e.g. created by anomaly_score).

threshold

Numeric value to determine the threshold to flag outliers among the score.

...

Additional parameters passed to quantile.

Value

Logical vector referencing which, if any, of the provided values are outliers.

Examples

test_data <- c(1,2,3,4,5,100,5,4,3,2,1)
anomaly_thresh(test_data, 0.99)

Create saliency map

Description

Using the provided numeric input, typically a time series, calculate the spectral residual and output the saliency map for use in anomaly detection.

Usage

saliency_map(x, window = 3)

Arguments

x

Numeric vector.

window

Positive integer value.

Value

Numeric vector representing the saliency map values.

See Also

anomaly_score

Examples

tmp <- ts(rnorm(12*6,10,2), start=c(2009, 1), end=c(2014, 12), frequency=12)
saliency_map(tmp)