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
ConstructorsConstructorDescriptionConstructs an empty mean/variance accumulator.MeanVarianceAccumulator(double[] values) Constructs a mean/variance accumulator and observes the supplied array.Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanlonggetCount()Gets the observation count.doublegetMax()Gets the maximum observed value.doublegetMean()Gets the sample mean.doublegetMin()Gets the minimum observed value.doubleGets the sample standard deviation.doubleGets the sample variance.inthashCode()voidobserve(double value) Observes a value, i.e., updates the sufficient statistics for computing mean, variance, max and min.voidobserve(double[] values) Observes a value, i.e., updates the sufficient statistics for computing mean, variance, max and min.voidreset()Resets this accumulator to the starting state.double[]standardize(double[] input) Standardizes the input using the computed mean and variance in this accumulator.voidstandardizeInPlace(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
-
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.
-