Package io.permazen.util
Class MovingAverage
java.lang.Object
io.permazen.util.MovingAverage
Exponential moving average calculator.
- See Also:
-
Constructor Summary
ConstructorDescriptionMovingAverage
(double alpha) Constructor.MovingAverage
(double alpha, double initialValue) Constructor with initial value. -
Method Summary
-
Constructor Details
-
MovingAverage
public MovingAverage(double alpha) Constructor.- Parameters:
alpha
- averaging parameter- Throws:
IllegalArgumentException
- ifalpha
is not a finite number in the range 0.0 to 1.0 (inclusive)
-
MovingAverage
public MovingAverage(double alpha, double initialValue) Constructor with initial value.- Parameters:
alpha
- averaging parameterinitialValue
- initial value- Throws:
IllegalArgumentException
- ifalpha
is not a finite number in the range 0.0 to 1.0 (inclusive)IllegalArgumentException
- ifinitialValue
is not a finite number
-
-
Method Details
-
get
public double get()Get the current average.- Returns:
- current average, or
Double.NaN
if no values have been added yet.
-
add
public void add(double value) Add a value to the moving average.- Parameters:
value
- value to add- Throws:
IllegalArgumentException
- ifvalue
is not a finite number
-