Documentation ¶
Overview ¶
Package ewma implements exponentially weighted moving averages.
Index ¶
Constants ¶
const ( // By default, we average over a one-minute period, which means the average // age of the metrics in the period is 30 seconds. AVG_METRIC_AGE float64 = 30.0 // The formula for computing the decay factor from the average age comes // from "Production and Operations Analysis" by Steven Nahmias. DECAY float64 = 2 / (float64(AVG_METRIC_AGE) + 1) // For best results, the moving average should not be initialized to the // samples it sees immediately. The book "Production and Operations // Analysis" by Steven Nahmias suggests initializing the moving average to // the mean of the first 10 samples. Until the VariableEwma has seen this // many samples, it is not "ready" to be queried for the value of the // moving average. This adds some memory cost. WARMUP_SAMPLES uint8 = 10 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MovingAverage ¶
MovingAverage is the interface that computes a moving average over a time- series stream of numbers. The average may be over a window or exponentially decaying.
func NewMovingAverage ¶
func NewMovingAverage(age ...float64) MovingAverage
NewMovingAverage constructs a MovingAverage that computes an average with the desired characteristics in the moving window or exponential decay. If no age is given, it constructs a default exponentially weighted implementation that consumes minimal memory. The age is related to the decay factor alpha by the formula given for the DECAY constant. It signifies the average age of the samples as time goes to infinity.
type SimpleEWMA ¶
type SimpleEWMA struct {
// contains filtered or unexported fields
}
A SimpleEWMA represents the exponentially weighted moving average of a series of numbers. It WILL have different behavior than the VariableEWMA for multiple reasons. It has no warm-up period and it uses a constant decay. These properties let it use less memory. It will also behave differently when it's equal to zero, which is assumed to mean uninitialized, so if a value is likely to actually become zero over time, then any non-zero value will cause a sharp jump instead of a small change. However, note that this takes a long time, and the value may just decays to a stable value that's close to zero, but which won't be mistaken for uninitialized. See http://play.golang.org/p/litxBDr_RC for example.
func (*SimpleEWMA) Add ¶
func (e *SimpleEWMA) Add(value float64)
Add adds a value to the series and updates the moving average.
func (*SimpleEWMA) Value ¶
func (e *SimpleEWMA) Value() float64
Value returns the current value of the moving average.
type VariableEWMA ¶
type VariableEWMA struct {
// contains filtered or unexported fields
}
VariableEWMA represents the exponentially weighted moving average of a series of numbers. Unlike SimpleEWMA, it supports a custom age, and thus uses more memory.
func (*VariableEWMA) Add ¶
func (e *VariableEWMA) Add(value float64)
Add adds a value to the series and updates the moving average.
func (*VariableEWMA) Value ¶
func (e *VariableEWMA) Value() float64
Value returns the current value of the average, or 0.0 if the series hasn't warmed up yet.