Package elki.math

Class Mean

  • Direct Known Subclasses:
    MeanVariance

    public class Mean
    extends java.lang.Object
    Compute the mean using a numerically stable online algorithm.

    This class can repeatedly be fed with data using the put() methods, the resulting values for mean can be queried at any time using getMean().

    The high-precision function is based on:

    P. M. Neely
    Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients
    Communications of the ACM 9(7), 1966

    Since:
    0.2
    Author:
    Erich Schubert
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected double n
      Weight sum (number of samples).
      protected double sum
      Sum of all values.
    • Constructor Summary

      Constructors 
      Constructor Description
      Mean()
      Empty constructor
      Mean​(Mean other)
      Constructor from other instance
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double getCount()
      Get the number of points the average is based on.
      double getMean()
      Return mean
      static double highPrecision​(double... data)
      Static helper function, with extra precision
      static Mean[] newArray​(int dimensionality)
      Create and initialize a new array of MeanVariance
      static double of​(double... data)
      Static helper function.
      void put​(double val)
      Add a single value with weight 1.0
      Mean put​(double[] vals)
      Add values with weight 1.0
      Mean put​(double[] vals, double[] weights)
      Add values with weight 1.0
      void put​(double val, double weight)
      Add data with a given weight.
      void put​(Mean other)
      Join the data of another MeanVariance instance.
      Mean reset()
      Reset the value.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • sum

        protected double sum
        Sum of all values.
      • n

        protected double n
        Weight sum (number of samples).
    • Constructor Detail

      • Mean

        public Mean()
        Empty constructor
      • Mean

        public Mean​(Mean other)
        Constructor from other instance
        Parameters:
        other - other instance to copy data from.
    • Method Detail

      • put

        public void put​(double val)
        Add a single value with weight 1.0
        Parameters:
        val - Value
      • put

        public void put​(double val,
                        double weight)
        Add data with a given weight.
        Parameters:
        val - data
        weight - weight
      • put

        public void put​(Mean other)
        Join the data of another MeanVariance instance.
        Parameters:
        other - Data to join with
      • put

        public Mean put​(double[] vals)
        Add values with weight 1.0
        Parameters:
        vals - Values
        Returns:
        this
      • put

        public Mean put​(double[] vals,
                        double[] weights)
        Add values with weight 1.0
        Parameters:
        vals - Values
        Returns:
        this
      • getCount

        public double getCount()
        Get the number of points the average is based on.
        Returns:
        number of data points
      • getMean

        public double getMean()
        Return mean
        Returns:
        mean
      • newArray

        public static Mean[] newArray​(int dimensionality)
        Create and initialize a new array of MeanVariance
        Parameters:
        dimensionality - Dimensionality
        Returns:
        New and initialized Array
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • reset

        public Mean reset()
        Reset the value.
        Returns:
        this accumulator
      • of

        public static double of​(double... data)
        Static helper function.
        Parameters:
        data - Data to compute the mean for.
        Returns:
        Mean
      • highPrecision

        @Reference(authors="P. M. Neely",
                   title="Comparison of Several Algorithms for Computation of Means, Standard Deviations and Correlation Coefficients",
                   booktitle="Communications of the ACM 9(7), 1966",
                   url="https://doi.org/10.1145/365719.365958",
                   bibkey="doi:10.1145/365719.365958")
        public static double highPrecision​(double... data)
        Static helper function, with extra precision
        Parameters:
        data - Data to compute the mean for.
        Returns:
        Mean