Database Reference
In-Depth Information
public class ExponentialMovingAverage {
double value = 0.0;
double alpha;
public ExponentialMovingAverage( double alpha) {
this .alpha = Math. min (alpha, 1.0);
}
public double observe( double x) {
value = alpha*x + (1-alpha)*value;
return value;
}
}
Like the normal moving average, selecting a value for alpha is more of an
art than a science. The most common rule of thumb is to set alpha to be
2/(k+1) where k is the number of values used in the moving average. The
result is roughly 86.5 percent of the weight to be derived from the most
recent k values and, as shown in Figure 11.2 , will very closely match the
standardmovingaverage. Figure11.2 alsoshowsthesamedatasetsmoothed
by two other exponential moving averages with k values of 20 and 30,
respectively.Theoriginalmovingaverageisalsoshownasthedottedlinefor
comparison. Notice how close the two forms of moving average track each
other. Because the values are close, the exponential moving average is the
algorithm most commonly used in practice.
 
Search WWH ::




Custom Search