Documentation ¶
Overview ¶
Package anomalyzer implements probability-based anomaly detection.
See https://github.com/lytics/anomalyzer#readme for more information.
Example ¶
conf := &AnomalyzerConf{ Sensitivity: 0.1, UpperBound: 5, LowerBound: NA, // ignore the lower bound ActiveSize: 1, NSeasons: 4, Methods: []string{"diff", "fence", "highrank", "lowrank", "magnitude"}, } // initialize with empty data or an actual slice of floats data := []float64{0.1, 2.05, 1.5, 2.5, 2.6, 2.55} anom, _ := NewAnomalyzer(conf, data) // the push method automatically triggers a recalcuation of the // anomaly probability. The recalculation can also be triggered // by a call to the Eval method. prob := anom.Push(8.0) fmt.Println("Anomalous Probability:", prob)
Output:
Index ¶
- Constants
- Variables
- func BootstrapKsTest(vector govector.Vector, conf AnomalyzerConf) float64
- func CDFTest(vector govector.Vector, conf AnomalyzerConf) float64
- func DiffTest(vector govector.Vector, conf AnomalyzerConf) float64
- func FenceTest(vector govector.Vector, conf AnomalyzerConf) float64
- func KsStat(vector govector.Vector, conf AnomalyzerConf) float64
- func MagnitudeTest(vector govector.Vector, conf AnomalyzerConf) float64
- func RankTest(vector govector.Vector, conf AnomalyzerConf) float64
- func ReverseRankTest(vector govector.Vector, conf AnomalyzerConf) float64
- type Algorithm
- type Anomalyzer
- type AnomalyzerConf
Examples ¶
Constants ¶
const (
NA = math.SmallestNonzeroFloat64
)
Variables ¶
var ( Algorithms = map[string]Algorithm{ "magnitude": MagnitudeTest, "diff": DiffTest, "highrank": RankTest, "lowrank": ReverseRankTest, "cdf": CDFTest, "fence": FenceTest, "ks": BootstrapKsTest, } )
Functions ¶
func BootstrapKsTest ¶
func BootstrapKsTest(vector govector.Vector, conf AnomalyzerConf) float64
func CDFTest ¶
func CDFTest(vector govector.Vector, conf AnomalyzerConf) float64
Generates the cumulative distribution function using the difference in the means for the data.
func DiffTest ¶
func DiffTest(vector govector.Vector, conf AnomalyzerConf) float64
Generates permutations of reference and active window values to determine whether or not data is anomalous. The number of permutations desired has been set to 500 but can be increased for more precision.
func FenceTest ¶
func FenceTest(vector govector.Vector, conf AnomalyzerConf) float64
This function can be used to test whether or not data is getting close to a specified upper or lower bound.
func KsStat ¶
func KsStat(vector govector.Vector, conf AnomalyzerConf) float64
Calculate a Kolmogorov-Smirnov test statistic.
func MagnitudeTest ¶
func MagnitudeTest(vector govector.Vector, conf AnomalyzerConf) float64
Generates the percent difference between the means of the reference and active data. Returns a value scaled such that it lies between 0 and 1.
func ReverseRankTest ¶
func ReverseRankTest(vector govector.Vector, conf AnomalyzerConf) float64
Types ¶
type Anomalyzer ¶
type Anomalyzer struct { Conf *AnomalyzerConf Data govector.Vector }
func NewAnomalyzer ¶
func NewAnomalyzer(conf *AnomalyzerConf, data []float64) (Anomalyzer, error)
func (Anomalyzer) Eval ¶
func (a Anomalyzer) Eval() float64
Return the weighted average of all statistical tests for anomaly detection, which yields the probability that the currently observed behavior is anomalous.
func (Anomalyzer) EvalByTest ¶
func (a Anomalyzer) EvalByTest() (map[string]float64, map[string]float64)
Get the results and weights of each test. Useful for debugging
func (*Anomalyzer) Push ¶
func (a *Anomalyzer) Push(x float64) float64
func (*Anomalyzer) Update ¶
func (a *Anomalyzer) Update(x []float64)