Skip to content

ankane/AnomalyDetection.cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AnomalyDetection.cpp

Time series AnomalyDetection for C++

Learn how it works

Build Status

Installation

Add the headers to your project and use

#include "anomaly_detection.hpp"

Getting Started

Detect anomalies in a time series

std::vector<float> series = {
    5.0, 9.0, 2.0, 9.0, 0.0, 6.0, 3.0, 8.0, 5.0, 18.0,
    7.0, 8.0, 8.0, 0.0, 2.0, 15.0, 0.0, 5.0, 6.0, 7.0,
    3.0, 6.0, 1.0, 4.0, 4.0, 4.0, 30.0, 7.0, 5.0, 8.0
};
size_t period = 7; // number of observations in a single period

auto res = anomaly_detection::params().fit(series, period);

Get anomalies

res.anomalies;

Parameters

Set parameters

anomaly_detection::params()
    .alpha(0.05)                    // level of statistical significance
    .max_anoms(0.1)                 // maximum number of anomalies as percent of data
    .direction(Direction::Both)     // Positive, Negative, or Both
    .verbose(false);                // show progress

Credits

This library was ported from the AnomalyDetection R package and is available under the same license. It uses stl-cpp for seasonal-trend decomposition and dist.h for the quantile function.

References

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

To get started with development:

git clone https://github.com/ankane/AnomalyDetection.cpp.git
cd AnomalyDetection.cpp
g++ -std=c++17 -Wall -Wextra -Werror -o test/main test/main.cpp
test/main

About

Time series anomaly detection for C++

Resources

License

Stars

Watchers

Forks

Packages

No packages published