Package org.tribuo.util
Class MeanVarianceAccumulator
java.lang.Object
org.tribuo.util.MeanVarianceAccumulator
- All Implemented Interfaces:
Serializable
An accumulator for online calculation of the mean and variance of a
stream of doubles.
Note this class is not thread safe.
- See Also:
-
Constructor Summary
ConstructorDescriptionConstructs an empty mean/variance accumulator.MeanVarianceAccumulator
(double[] values) Constructs a mean/variance accumulator and observes the supplied array.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
long
getCount()
Gets the observation count.double
getMax()
Gets the maximum observed value.double
getMean()
Gets the sample mean.double
getMin()
Gets the minimum observed value.double
Gets the sample standard deviation.double
Gets the sample variance.int
hashCode()
static MeanVarianceAccumulator
merge
(MeanVarianceAccumulator first, MeanVarianceAccumulator second) Implement Chan's algorithm for merging two mean variance accumulators.void
observe
(double value) Observes a value, i.e., updates the sufficient statistics for computing mean, variance, max and min.void
observe
(double[] values) Observes a value, i.e., updates the sufficient statistics for computing mean, variance, max and min.void
reset()
Resets this accumulator to the starting state.double[]
standardize
(double[] input) Standardizes the input using the computed mean and variance in this accumulator.void
standardizeInPlace
(double[] input) Standardizes the input using the computed mean and variance in this accumulator.toString()
-
Constructor Details
-
MeanVarianceAccumulator
public MeanVarianceAccumulator()Constructs an empty mean/variance accumulator. -
MeanVarianceAccumulator
public MeanVarianceAccumulator(double[] values) Constructs a mean/variance accumulator and observes the supplied array.- Parameters:
values
- The array to operate on.
-
MeanVarianceAccumulator
Copy constructor.- Parameters:
other
- The MeanVarianceAccumulator to copy.
-
-
Method Details
-
reset
public void reset()Resets this accumulator to the starting state. -
observe
public void observe(double value) Observes a value, i.e., updates the sufficient statistics for computing mean, variance, max and min.- Parameters:
value
- The value to observe.
-
observe
public void observe(double[] values) Observes a value, i.e., updates the sufficient statistics for computing mean, variance, max and min.- Parameters:
values
- The values to observe.
-
getMin
public double getMin()Gets the minimum observed value.- Returns:
- The minimum value.
-
getMax
public double getMax()Gets the maximum observed value.- Returns:
- The maximum value.
-
getMean
public double getMean()Gets the sample mean.- Returns:
- The sample mean.
-
getVariance
public double getVariance()Gets the sample variance.- Returns:
- The sample variance.
-
getCount
public long getCount()Gets the observation count.- Returns:
- The observation count.
-
getStdDev
public double getStdDev()Gets the sample standard deviation.- Returns:
- The sample standard deviation.
-
equals
-
hashCode
public int hashCode() -
toString
-
standardize
public double[] standardize(double[] input) Standardizes the input using the computed mean and variance in this accumulator. Standardization means subtracting the mean and dividing by the variance.- Parameters:
input
- The input to standardize.- Returns:
- The standardized input.
-
standardizeInPlace
public void standardizeInPlace(double[] input) Standardizes the input using the computed mean and variance in this accumulator. Standardization means subtracting the mean and dividing by the variance.- Parameters:
input
- The input to standardize.
-
merge
public static MeanVarianceAccumulator merge(MeanVarianceAccumulator first, MeanVarianceAccumulator second) Implement Chan's algorithm for merging two mean variance accumulators.- Parameters:
first
- The first mean variance accumulator.second
- The second mean variance accumulator.- Returns:
- A merged mean variance accumulator.
-