FileDocCategorySizeDatePackage
ExponentialMovingAverage.javaAPI DocAzureus 3.0.3.42275Tue Mar 21 15:01:32 GMT 2006com.aelitis.azureus.core.util.average

ExponentialMovingAverage

public class ExponentialMovingAverage extends Object implements Average
Implements an exponential moving average.

Fields Summary
private final float
weight
private double
prevEMA
Constructors Summary
public ExponentialMovingAverage(int periods)
Create a new exponential moving average which smooths over the given number of periods.

      if (periods < 1) {
         System.out.println("ExponentialMovingAverage:: ERROR: bad periods: " + periods);
      }
      this.weight = 2 / (float)(1 + periods);
      this.prevEMA = 0;
   
public ExponentialMovingAverage(float weight)
Create a new exponential moving average, using the given smoothing rate weight.

      if ((weight < 0.0) || (weight > 1.0)) {
         System.out.println("ExponentialMovingAverage:: ERROR: bad weight: " + weight);
      }
      this.weight = weight;
      this.prevEMA = 0;
   
Methods Summary
public doublegetAverage()
Return average-so-far.

 return prevEMA; 
public voidreset()

		 
	  this.prevEMA = 0;
   
public doubleupdate(double newValue)
Update average and return average-so-far.

      prevEMA = (weight * (newValue - prevEMA)) + prevEMA;
      return prevEMA;