Class MeanVarianceAccumulator

java.lang.Object
org.tribuo.util.MeanVarianceAccumulator
All Implemented Interfaces:
Serializable

public final class MeanVarianceAccumulator extends Object implements 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 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

      public MeanVarianceAccumulator(MeanVarianceAccumulator other)
      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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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

      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.