Moving Average/Exponential

From testwiki
Revision as of 17:55, 9 October 2020 by imported>Bert Niehaus (New resource with "==Exponential moving average== {{further|Wikipedia:EWMA chart|Wikipedia:Exponential smoothing}} Image:Exponential moving average weights N=15.png|thumb|right|EMA weights&nbs...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Exponential moving average

Template:Further

EMA weights N = 200

An exponential moving average (EMA), also known as an exponentially weighted moving average (EWMA),[1] is a type of infinite impulse response filter that applies weighting factors which decrease exponentially. The weighting for each older datum decreases exponentially, never reaching zero. The graph at right shows an example of the weight decrease.

The EMA for a series C:=(C(0),C(1),) of collected data with a set of dates T:=0, where C(t) is the collected data at time index tT:=0.

  • First of all we have to defined a value α with 0<α<1, that represents the degree of weighting decrease as a constant smoothing factor between 0 and 1. A lower α discounts older observations faster.
  • The weights are defined by
wt=(1α)αt for all tT:=0 with t=0wt=1 (geometric series).
  • The sum of weights from 0 to the time index tT is defined by:
s(t)=k=0twk=k=0t(1α)αk=(1α)k=0tαk=1αt+11α=(1α)1αt+11α=1αt+1
  • The discrete probability mass function is defined by:
pt(x)={wtxs(t)=(1α)αtx1αt+1for 0xt,0for x<0 or x>t

The definition above creates the exponential moving average EMA with discrete probability mass function pt by

EMA(t):=kTpt(k)C(k)=k=0tpt(k)C(k)=x=0twtks(t)C(k)=k=0t(1α)αtk1αt+1C(k)

The EMA at time index tT:=0 may be calculated recursively:

EMA(0):=C(0) and
EMA(t+1):=1α1αt+2C(t+1)+α1αt+11αt+2EMA(t) for all tT=0={0,1,2,3,...}

Where:

  • The coefficient α represents the degree of weighting decrease from EMA(t) to EMA(t+1). This implements the aging of data from t to time index t+1.
  • the fraction 1αt+11αt+2 adjusts the denominator EMA(t) for EMA(t+1).
  • the coefficient 1α1αt+2=pt+1(t+1)=w(t+1)(t+1)s(t+1) in the EMA at time index t+1.

Initialization of EMA and Elimination of MA Impact form old data

EMA(0) may be initialized in a number of different ways, most commonly by setting EMA(0) to the first collected data C(0) at time index 0 as shown above, though other techniques exist, such as starting the calculation of the moving average after the first 4 or 5 observations. Furthermore only a most recent subset of collected data before the time index t from the total history of collected date might be used for the EMA(t). The discrete probability mass function puts weights on the most recent m+1 values of the collected data by:

pt(x)={wtxs(t)=(1α)αtx1αt+1for 0xt and tmwtxs(t)s(tm)=(1α)αtx1αt+1(1αtm+1)=(1α)αtxαtm+1αt+1for (tm)xt and t>m,0for x<0 or x>t

The limitations to the most recent m+1 values of the collected data eliminates the impact of very old data on the resultant moving average completely. By choosing a small α old data is less important than recent data and discounts older observations faster, but even the oldest data has a impact on the calculation of EMA(t) at time index t.

Tne initialiation of EMA(t) could incorporate something about values prior to the available data, i.e. history before t=0. Tne initialiation could introduce an error in the EMA(t). In view of this the early results should be regarded as unreliable until the iterations have had time to converge. This is sometimes called a 'spin-up' interval.

This formulation of EMA is designed as an application of an expected value, which is a standard definition in probability theory.

According to Hunter (1986).[2] this can be written as an repeated application of the recursive formula for different times t without standardisation, i.e.

xTpt(x)=1.

An alternate approach defined by Roberts (1959)[3] is missing the standardisation of the probability distribution too, while the basic principle of exponential moving average remains the same.

Application to measuring computer performance

Some computer performance metrics, e.g. the average process queue length, or the average CPU utilization, use a form of exponential moving average with the recursive definition.

Sn=α(tntn1)×Yn+(1α(tntn1))×Sn1.

Here Template:Mvar is defined as a function of time between two readings. An example of a coefficient giving bigger weight to the current reading, and smaller weight to the older readings is

α(tntn1)=1exp(tntn1W×60)

where Template:Math is the exponential function, time for readings tn is expressed in seconds, and Template:Mvar is the period of time in minutes over which the reading is said to be averaged (the mean lifetime of each reading in the average). Given the above definition of Template:Mvar, the moving average can be expressed as

Sn=(1exp(tntn1W×60))×Yn+exp(tntn1W×60)×Sn1

For example, a 15-minute average L of a process queue length Q, measured every 5 seconds (time difference is 5 seconds), is computed as

Ln=(1exp(515×60))×Qn+e515×60×Ln1=(1exp(1180))×Qn+e1/180×Ln1=Qn+e1/180×(Ln1Qn)