Documentation ¶
Index ¶
- func AbsInt(x int) int
- func Average(input []float64) float64
- func Cdf(mean, stdev float64) func(float64) float64
- func Ema(input []float64, smoothingFactor float64) []float64
- func Erf(x float64) float64
- func Float64WithPrecision(num float64, precision int) float64
- func Pdf(mean, stdev float64) func(float64) float64
- func RandomSineValue(rand *rand.Rand, limit int) float64
- func RoundFloat(num float64) int
- func Stdev(input []float64) float64
- func SumFloat64s(input []float64) float64
- func SumInts(input []int) int
- func Variance(input []float64) (variance float64)
- type AbsoluteThreshold
- type Algorithm
- type Anomaly
- type Bitmap
- type BitmapBinary
- type CorrelationAlgorithm
- type CorrelationMethod
- type CorrelationResult
- type Correlator
- type CrossCorrelation
- type Derivative
- type Detector
- type ExponentialMovingAverage
- type Iterator
- type NormalDistribution
- type PearsonCorrelation
- type STL
- func (s *STL) Iterations(n int) *STL
- func (s *STL) LowPassFilterConfig(config *stl.Config) *STL
- func (s *STL) MethodType(method STLMethod) *STL
- func (s *STL) Periodicity(p int) *STL
- func (s *STL) RobustIterations(n int) *STL
- func (s *STL) Run(timeSeries *TimeSeries) *ScoreList
- func (s *STL) SeasonalConfig(config *stl.Config) *STL
- func (s *STL) TrendConfig(config *stl.Config) *STL
- func (s *STL) Width(w int) *STL
- type STLMethod
- type ScoreList
- type SpearmanCorrelation
- type TimePeriod
- type TimeSeries
- func (ts *TimeSeries) AddOffset(offset float64) *TimeSeries
- func (ts *TimeSeries) Align(other *TimeSeries)
- func (ts *TimeSeries) Average() float64
- func (ts *TimeSeries) Crop(start, end float64) *TimeSeries
- func (ts *TimeSeries) EarliestTimestamp() float64
- func (ts *TimeSeries) LastestTimestamp() float64
- func (ts *TimeSeries) Median() float64
- func (ts *TimeSeries) Normalize() *TimeSeries
- func (ts *TimeSeries) NormalizeWithMinMax() *TimeSeries
- func (ts *TimeSeries) Size() int
- func (ts *TimeSeries) Stdev() float64
- func (ts *TimeSeries) String() string
- func (ts *TimeSeries) Zip() map[float64]float64
- type WeightedSum
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Float64WithPrecision ¶
Float64WithPrecision rounds float to certain precision
func RandomSineValue ¶
RandomSineValue returns sine of value between [0, limit] using a rand source
func SumFloat64s ¶
SumFloat64s returns the sum of all float64 in the input
Types ¶
type AbsoluteThreshold ¶
type AbsoluteThreshold struct {
// contains filtered or unexported fields
}
AbsoluteThreshold holds absolute threshold algorithm configuration. It takes the difference of lower and upper thresholds with the current value as anomaly score.
func NewAbsoluteThreshold ¶
func NewAbsoluteThreshold() *AbsoluteThreshold
NewAbsoluteThreshold returns AbsoluteThAbsoluteThreshold instance.
func (*AbsoluteThreshold) Run ¶
func (at *AbsoluteThreshold) Run(timeSeries *TimeSeries) *ScoreList
Run runs the absolute threshold algorithm over the time series.
func (*AbsoluteThreshold) Thresholds ¶
func (at *AbsoluteThreshold) Thresholds(lower, upper float64) Algorithm
Thresholds sets both lower and upper thresholds.
type Algorithm ¶
type Algorithm interface { Run(*TimeSeries) *ScoreList // contains filtered or unexported methods }
Algorithm is the base interface of all algorithms
type Anomaly ¶
type Anomaly struct { Timestamp float64 StartTimestamp float64 EndTimestamp float64 Score float64 Value float64 Severity string // contains filtered or unexported fields }
Anomaly holds information about the detected anomaly/outlier
func (*Anomaly) GetTimeWindow ¶
GetTimeWindow returns anomaly start and end timestamps
func (*Anomaly) GetTimestampedScore ¶
GetTimestampedScore returns anomaly exact timestamp with calculated score
type Bitmap ¶
type Bitmap struct {
// contains filtered or unexported fields
}
Bitmap holds bitmap algorithm configuration.
The Bitmap algorithm breaks the time series into chunks and uses the frequency of similar chunks to determine anomalies scores. The scoring happens by sliding both lagging and future windows.
func (*Bitmap) FutureWindowSize ¶
FutureWindowSize sets the future window size (default to 0).
func (*Bitmap) LagWindowSize ¶
LagWindowSize sets the lag window size (defaults to 0).
func (*Bitmap) Run ¶
func (b *Bitmap) Run(timeSeries *TimeSeries) *ScoreList
Run runs the bitmap algorithm over the time series
type BitmapBinary ¶
type BitmapBinary string
BitmapBinary wrapper type around a string with custom behaviour
func (BitmapBinary) At ¶
func (bb BitmapBinary) At(index int) BitmapBinary
At returns character string at the specified index
func (BitmapBinary) Len ¶
func (bb BitmapBinary) Len() int
Len returns the length of the underlying string
func (BitmapBinary) Slice ¶
func (bb BitmapBinary) Slice(lower, upper int) BitmapBinary
Slice slices a string in a Python-ish way When lower == upper, it returns an empty string When lower < 0 and upper < len(binary), it return an empty string When lower < 0 and upper >= len(binary), it returns the first character When lower >= 0 and upper >= len(binary), it slices the string from lower till end of string
func (BitmapBinary) String ¶
func (bb BitmapBinary) String() string
String returns the underlying string
type CorrelationAlgorithm ¶
type CorrelationAlgorithm interface { Run() float64 // contains filtered or unexported methods }
CorrelationAlgorithm base interface for correlation algorithms.
type CorrelationMethod ¶
type CorrelationMethod int32
CorrelationMethod type checker for correlation method
const ( // XCorr represents the Cross Correlation algorithm. XCorr CorrelationMethod = iota // SpearmanRank represents the Spearman Rank Correlation algorithm. SpearmanRank // Pearson represents the Pearson Correlation algorithm. Pearson )
type CorrelationResult ¶
CorrelationResult holds detected correlation result.
type Correlator ¶
type Correlator struct {
// contains filtered or unexported fields
}
Correlator holds the correlator configuration.
func NewCorrelator ¶
func NewCorrelator(current, target *TimeSeries) *Correlator
NewCorrelator returns an instance of the correlation algorithm.
func (*Correlator) CorrelationMethod ¶
func (c *Correlator) CorrelationMethod(method CorrelationMethod, options []float64) *Correlator
CorrelationMethod specifies which correlation method to use (XCross or SpearmanRank).
func (*Correlator) TimePeriod ¶
func (c *Correlator) TimePeriod(start, end float64) *Correlator
TimePeriod crops the current and target time series to specified range.
func (*Correlator) UseAnomalyScore ¶
func (c *Correlator) UseAnomalyScore(use bool) *Correlator
UseAnomalyScore tells the correlator to calculate anomaly scores from both time series.
type CrossCorrelation ¶
type CrossCorrelation struct {
// contains filtered or unexported fields
}
CrossCorrelation holds Cross Correlation algorithm parameters and settings. It is calculated by multiplying and summing the current and target time series together.
This implementation uses normalized time series which makes scoring easy to understand:
- The higher the coefficient, the higher the correlation is.
- The maximum value of the correlation coefficient is 1.
- The minimum value of the correlation coefficient is -1.
- Two time series are exactly the same when their correlation coefficient is equal to 1.
func NewCrossCorrelation ¶
func NewCrossCorrelation(current *TimeSeries, target *TimeSeries) *CrossCorrelation
NewCrossCorrelation returns an instance of the cross correlation struct.
func (*CrossCorrelation) GetCorrelationResult ¶
func (cc *CrossCorrelation) GetCorrelationResult() CorrelationResult
GetCorrelationResult runs the cross correlation algorithm.
func (*CrossCorrelation) Impact ¶
func (cc *CrossCorrelation) Impact(impact float64) *CrossCorrelation
Impact sets impact of shift on shifted correlation coefficient.
func (*CrossCorrelation) MaxShift ¶
func (cc *CrossCorrelation) MaxShift(shift float64) *CrossCorrelation
MaxShift sets the maximal shift in seconds.
func (*CrossCorrelation) Run ¶
func (cc *CrossCorrelation) Run() float64
Run runs the cross correlation algorithm and returns only the coefficient.
type Derivative ¶
type Derivative struct {
// contains filtered or unexported fields
}
Derivative holds the derivative algorithm configuration. It uses the derivative of the current value as anomaly score.
func (*Derivative) Run ¶
func (d *Derivative) Run(timeSeries *TimeSeries) *ScoreList
Run runs the derivative algorithm over the time series
func (*Derivative) SmoothingFactor ¶
func (d *Derivative) SmoothingFactor(factor float64) *Derivative
SmoothingFactor sets the smoothing factor.
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector is the default anomaly detector
func NewDetector ¶
func NewDetector(ts *TimeSeries) *Detector
NewDetector return an instance of the default detector.
func (*Detector) GetAnomalies ¶
GetAnomalies detects anomalies using the specified threshold on scores
type ExponentialMovingAverage ¶
type ExponentialMovingAverage struct {
// contains filtered or unexported fields
}
ExponentialMovingAverage holds the algorithm configuration. It uses the value's deviation from the exponential moving average of a lagging window to determine anomalies scores.
func NewEma ¶
func NewEma() *ExponentialMovingAverage
NewEma returns ExponentialMovingAverage instance
func (*ExponentialMovingAverage) LagWindowSize ¶
func (ema *ExponentialMovingAverage) LagWindowSize(size int) *ExponentialMovingAverage
LagWindowSize sets the lagging window size.
func (*ExponentialMovingAverage) Run ¶
func (ema *ExponentialMovingAverage) Run(timeSeries *TimeSeries) *ScoreList
Run runs the exponential moving average algorithm over the time series
func (*ExponentialMovingAverage) SmoothingFactor ¶
func (ema *ExponentialMovingAverage) SmoothingFactor(factor float64) *ExponentialMovingAverage
SmoothingFactor sets the smoothing factor.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator wraps a slice of float64 values with the current element position
func NewIterator ¶
NewIterator returns an iterator instance
type NormalDistribution ¶
type NormalDistribution struct {
// contains filtered or unexported fields
}
NormalDistribution holds the normal distribution algorithm configuration.
func NewNormalDistribution ¶
func NewNormalDistribution() *NormalDistribution
NewNormalDistribution returns normal distribution instance.
func (*NormalDistribution) EpsilonThreshold ¶
func (nd *NormalDistribution) EpsilonThreshold(threshold float64) *NormalDistribution
EpsilonThreshold sets the Gaussian epsilon threshold.
func (*NormalDistribution) Run ¶
func (nd *NormalDistribution) Run(timeSeries *TimeSeries) *ScoreList
Run runs the normal distribution algorithm over the time series.
type PearsonCorrelation ¶
type PearsonCorrelation struct {
// contains filtered or unexported fields
}
PearsonCorrelation struct which holds the current and target time series.
func NewPearsonCorrelation ¶
func NewPearsonCorrelation(current, target *TimeSeries) *PearsonCorrelation
NewPearsonCorrelation returns an instance of the pearson correlation struct. It measures the linear correlation between the current and target time series. It should be used when the two time series are normally distributed.
The correlation coefficient always has a value between -1 and +1 where:
- +1 is total positive linear correlation
- 0 is no linear correlation
- −1 is total negative linear correlation
For the used formula, check: https://en.wikipedia.org/wiki/Pearson_correlation_coefficient
func (*PearsonCorrelation) Run ¶
func (pc *PearsonCorrelation) Run() float64
Run runs the pearson correlation on the current and target time series. It returns the correlation coefficient which always has a value between -1 and +1.
type STL ¶
type STL struct {
// contains filtered or unexported fields
}
STL holds Seasonal-Trend With Loess algorithm configuration.
The STL algorithm decomposes a time series into seasonal, trend and remainder components. The paper describing this algorithm can found here: https://search.proquest.com/openview/cc5001e8a0978a6c029ae9a41af00f21
func (*STL) Iterations ¶
func (*STL) MethodType ¶
func (*STL) Periodicity ¶
func (*STL) RobustIterations ¶
func (*STL) Run ¶
func (s *STL) Run(timeSeries *TimeSeries) *ScoreList
Run runs the STL algorithm over the time series.
type ScoreList ¶
ScoreList holds timestamps and their scores
type SpearmanCorrelation ¶
type SpearmanCorrelation struct {
// contains filtered or unexported fields
}
SpearmanCorrelation holds the Spearman Correlation algorithm configuration. It is the non-parametric version of the Pearson correlation and it should be used when the time series distribution is unknown or not normally distributed.
Spearman’s correlator returns a value from -1 to 1, where:
- +1 = a perfect positive correlation between ranks
- -1 = a perfect negative correlation between ranks
- 0 = no correlation between ranks.
func NewSpearmanCorrelation ¶
func NewSpearmanCorrelation(current, target *TimeSeries) *SpearmanCorrelation
NewSpearmanCorrelation returns an instance of the spearman correlation struct.
func (*SpearmanCorrelation) Run ¶
func (sc *SpearmanCorrelation) Run() float64
Run runs the spearman correlation on the current and target time series.
type TimePeriod ¶
TimePeriod represents a time period marked by start and end timestamps.
type TimeSeries ¶
TimeSeries wrapper for timestamps and their values
func NewTimeSeries ¶
func NewTimeSeries(timestamps []float64, values []float64) *TimeSeries
NewTimeSeries creates a new time series data structure
func NewTimeSeriesFromCSV ¶
func NewTimeSeriesFromCSV(path string) *TimeSeries
NewTimeSeriesFromCSV create a new time series from a CSV file.
func (*TimeSeries) AddOffset ¶
func (ts *TimeSeries) AddOffset(offset float64) *TimeSeries
AddOffset increments time series timestamps by some offset
func (*TimeSeries) Align ¶
func (ts *TimeSeries) Align(other *TimeSeries)
Align aligns two time series so that they have the same dimension and same timestamps
func (*TimeSeries) Average ¶
func (ts *TimeSeries) Average() float64
Average calculates average value over the time series
func (*TimeSeries) Crop ¶
func (ts *TimeSeries) Crop(start, end float64) *TimeSeries
Crop crops the time series timestamps into the specified range [start, end]
func (*TimeSeries) EarliestTimestamp ¶
func (ts *TimeSeries) EarliestTimestamp() float64
EarliestTimestamp returns the earliest timestamp in the time series
func (*TimeSeries) LastestTimestamp ¶
func (ts *TimeSeries) LastestTimestamp() float64
LastestTimestamp returns the latest timestamp in the time series
func (*TimeSeries) Median ¶
func (ts *TimeSeries) Median() float64
Median calculates median value over the time series.
func (*TimeSeries) Normalize ¶
func (ts *TimeSeries) Normalize() *TimeSeries
Normalize normalizes the time series values by dividing by the maximum value
func (*TimeSeries) NormalizeWithMinMax ¶
func (ts *TimeSeries) NormalizeWithMinMax() *TimeSeries
NormalizeWithMinMax normalizes time series values using MixMax
func (*TimeSeries) Size ¶
func (ts *TimeSeries) Size() int
Size returns the time series dimension/size.
func (*TimeSeries) Stdev ¶
func (ts *TimeSeries) Stdev() float64
Stdev calculates the standard deviation of the time series
func (*TimeSeries) String ¶
func (ts *TimeSeries) String() string
String returns JSON representation of the time series
func (*TimeSeries) Zip ¶
func (ts *TimeSeries) Zip() map[float64]float64
Zip convert the time series to a map (map[Timestamp]Value)
type WeightedSum ¶
type WeightedSum struct { *ExponentialMovingAverage *Derivative // contains filtered or unexported fields }
WeightedSum holds the weighted sum algorithm configuration.
The weighted sum algorithm uses a weighted sum to calculate anomalies scores. It should be used ONLY on small data-sets.
func NewWeightedSum ¶
func NewWeightedSum() *WeightedSum
NewWeightedSum returns weighted sum instance
func (*WeightedSum) MinEmaScore ¶
func (ws *WeightedSum) MinEmaScore(value float64) *WeightedSum
MinEmaScore sets the minimal Ema score above which the weighted score is used.
func (*WeightedSum) Run ¶
func (ws *WeightedSum) Run(timeSeries *TimeSeries) *ScoreList
Run runs the weighted sum algorithm over the time series
func (*WeightedSum) ScoreWeight ¶
func (ws *WeightedSum) ScoreWeight(weight float64) *WeightedSum
ScoreWeight sets Ema's score weight.
Source Files ¶
- absolute_threshold.go
- algorithm.go
- anomaly.go
- bitmap.go
- bitmap_binary.go
- correlator.go
- cross_correlation.go
- derivative.go
- detector.go
- ema.go
- helpers.go
- iterator.go
- math.go
- normal_distribution.go
- pearson_correlation.go
- score_list.go
- semaphore.go
- spearman_correlation.go
- stl.go
- time_series.go
- weighted_sum.go