Database Reference
In-Depth Information
public WeightedMovingAverage( double [] kernel) {
this .kernel = kernel;
for ( double j : kernel) kernelSum += j;
values = new double [kernel.length];
}
public double observe( double x) {
values[k++] = x;
if (k == values.length) k = 0;
N++;
if (N < kernel.length) return Double. NaN ;
double y = 0;
for ( int i=0;i<kernel.length;i++)
y += kernel[i]*values[(k+i) % values.length];
return y/kernelSum;
}
}
The important thing to notice with the weighted moving average is that the
computation is much slower than the normal moving average, requiring k
operations for every observed value. For most offline analyses, this is not
a concern, but it can be a problem with a real-time environment's online
processing.
Exponential Moving Average
Many times, the kernel in a weighted moving average is used to place more
weight on recent observations than on older observations. The exponential
moving average also does this by taking the weighted average of the current
moving average value and the new observation:
EMA = a*X + (1-a)*EMA
The exponential moving average is not quite the same as the weighted
moving average, and it has several advantages. The first is that it only
requires a single operation to obtain a new value for the exponential moving
average instead of k operations. The second is that it only requires the
storage of a single value instead of the k values needed by both the moving
average and the weighted moving average. As expected, the implementation
is very simple:
Search WWH ::




Custom Search