Type: | Package |
Title: | Detect Anomalies Using the Spectral Residual Algorithm |
Version: | 0.1.1 |
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>. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
Imports: | stats, utils |
Suggests: | testthat (≥ 3.0.0) |
Config/testthat/edition: | 3 |
RoxygenNote: | 7.3.2 |
URL: | https://al-obrien.github.io/spectralAnomaly/, https://github.com/al-obrien/spectralAnomaly |
BugReports: | https://github.com/al-obrien/spectralAnomaly/issues |
NeedsCompilation: | no |
Packaged: | 2024-09-12 21:32:26 UTC; allen |
Author: | Allen OBrien [aut, cre, cph] |
Maintainer: | Allen OBrien <allen.g.obrien@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2024-09-15 21:00:02 UTC |
spectralAnomaly: 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.
Author(s)
Maintainer: Allen OBrien allen.g.obrien@gmail.com [copyright holder]
See Also
Useful links:
Report bugs at https://github.com/al-obrien/spectralAnomaly/issues
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 |
threshold |
Numeric value to determine the threshold to flag outliers among the score. |
... |
Additional parameters passed to |
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
Examples
tmp <- ts(rnorm(12*6,10,2), start=c(2009, 1), end=c(2014, 12), frequency=12)
saliency_map(tmp)