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 Summary

    Constructors
    Constructor
    Description
    Constructs an empty mean/variance accumulator.
    MeanVarianceAccumulator(double[] values)
    Constructs a mean/variance accumulator and observes the supplied array.
    Copy constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    long
    Gets the observation count.
    double
    Gets the maximum observed value.
    double
    Gets the sample mean.
    double
    Gets the minimum observed value.
    double
    Gets the sample standard deviation.
    double
    Gets the sample variance.
    int
     
    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
    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.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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.