Package org.dellroad.stuff.util
Class Averager
java.lang.Object
org.dellroad.stuff.util.Averager
- All Implemented Interfaces:
Cloneable
Calculates running averages and variance.
Instances are not thread safe.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionAdd this instance to the given instance and return a new combined instance.void
addValue
(double value) Add a value.clone()
boolean
Get the average of all the data points added to this instance so far.Get the coefficient of variation (the standard deviation divided by the average).Get the sample (unbiased estimated) standard deviation.Get the sample (unbiased estimated) variance.Get the population standard deviation.Get the population variance.int
hashCode()
boolean
isEmpty()
Determine whether any data points have been added to this instance yet.void
reset()
Reset this instance.int
size()
Get the number of data points added so far.Subtract the given instance from this instance.toString()
-
Constructor Details
-
Averager
public Averager()Default constructor.Creates an empty (and therefore invalid) instance.
-
Averager
public Averager(double firstValue) Constructor taking first datapoint.- Parameters:
firstValue
- first data point
-
-
Method Details
-
addValue
public void addValue(double value) Add a value.- Parameters:
value
- value to add to the running average- Throws:
IllegalArgumentException
- ifvalue
isNaN
or infinity
-
add
Add this instance to the given instance and return a new combined instance.- Parameters:
that
- other instance- Returns:
- combined average
-
subtract
Subtract the given instance from this instance.- Returns:
- average with
that
data points removed
-
reset
public void reset()Reset this instance. -
size
public int size()Get the number of data points added so far.- Returns:
- the number of data points added to this instance
-
isEmpty
public boolean isEmpty()Determine whether any data points have been added to this instance yet.- Returns:
- true if no data points have been added yet
-
getAverage
Get the average of all the data points added to this instance so far.- Returns:
- average value, or empty if no data points have been added yet
-
getVariance
Get the population variance.- Returns:
- population variance, or empty if no data points have been added yet
-
getStandardDeviation
Get the population standard deviation.- Returns:
- population standard deviation, or empty if no data points have been added yet
-
getSampleVariance
Get the sample (unbiased estimated) variance.- Returns:
- sample variance, or empty if less than two data points have been added yet
-
getSampleStandardDeviation
Get the sample (unbiased estimated) standard deviation.- Returns:
- population standard deviation, or empty if less than two data points have been added yet
-
getCoefficientOfVariation
Get the coefficient of variation (the standard deviation divided by the average).Note: if the average is zero, then
Double.NaN
is returned.- Returns:
- coefficient of variation, or empty if no data points have been added yet
-
toString
-
equals
-
hashCode
public int hashCode() -
clone
-