movingaverage

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Simple

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

Simple keeps track of a history of measurements and returns the average. One important feature of this implementation is that the average can go to zero. All methods are thread safe.

Alternative: consider exponential moving average where near-zero values are treated as zero (for scale to zero):

func MovingExpAvg(value, oldValue, fdtime, ftime float64) float64 {
 alpha := 1.0 - math.Exp(-fdtime/ftime)
 r := alpha * value + (1.0 - alpha) * oldValue
 return r
}

func NewSimple

func NewSimple(seed []float64) *Simple

func (*Simple) Calculate

func (a *Simple) Calculate() (result float64)

func (*Simple) History

func (a *Simple) History() []float64

func (*Simple) Next

func (a *Simple) Next(next float64)

Jump to

Keyboard shortcuts

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