ema

package module
v0.0.0-...-d6854b6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2016 License: MIT Imports: 2 Imported by: 0

README

Exponential Moving Average

This is meant for sliding windows where the window size is time based and not bucket based It is self cleansing, since it keeps a buffer is applied (without storing) between ticks

Usage

// create exponential moving average with the size of 10ms
em, err := ema.NewExpMovingAverage(10*time.Millisecond, 0.0)

for i := 1.0; i <= 100; i++ {
    time.Sleep(1 * time.Millisecond)
    // add i every 1ms
    avg = em.Add(i)
}

em.Get() // ==> ~92

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExpMovingAverage

type ExpMovingAverage struct {
	// contains filtered or unexported fields
}

ExpMovingAverage ...

func NewExpMovingAverage

func NewExpMovingAverage(ttl time.Duration, initValue float64) (*ExpMovingAverage, error)

NewExpMovingAverage ...

func (*ExpMovingAverage) Add

func (ema *ExpMovingAverage) Add(value float64) float64

Add adds a value and returns the new average

func (*ExpMovingAverage) Get

func (ema *ExpMovingAverage) Get() float64

Get returns the current average

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL