类 Accumulator


  • public class Accumulator
    extends java.lang.Object
    The Accumulator class is a data type for computing the running mean, sample standard deviation, and sample variance of a stream of real numbers. It provides an example of a mutable data type and a streaming algorithm.

    This implementation uses a one-pass algorithm that is less susceptible to floating-point roundoff error than the more straightforward implementation based on saving the sum of the squares of the numbers. This technique is due to B. P. Welford. Each operation takes constant time in the worst case. The amount of memory is constant - the data values are not stored.

    For additional documentation, see Section 1.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • 构造器概要

      构造器 
      构造器 说明
      Accumulator()
      Initializes an accumulator.
    • 方法概要

      修饰符和类型 方法 说明
      void addDataValue​(double x)
      Adds the specified data value to the accumulator.
      int count()
      Returns the number of data values.
      static void main​(java.lang.String[] args)
      Unit tests the Accumulator data type.
      double mean()
      Returns the mean of the data values.
      double stddev()
      Returns the sample standard deviation of the data values.
      java.lang.String toString()
      Returns a string representation of this accumulator.
      double var()
      Returns the sample variance of the data values.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 构造器详细资料

      • Accumulator

        public Accumulator()
        Initializes an accumulator.
    • 方法详细资料

      • addDataValue

        public void addDataValue​(double x)
        Adds the specified data value to the accumulator.
        参数:
        x - the data value
      • mean

        public double mean()
        Returns the mean of the data values.
        返回:
        the mean of the data values
      • var

        public double var()
        Returns the sample variance of the data values.
        返回:
        the sample variance of the data values
      • stddev

        public double stddev()
        Returns the sample standard deviation of the data values.
        返回:
        the sample standard deviation of the data values
      • count

        public int count()
        Returns the number of data values.
        返回:
        the number of data values
      • toString

        public java.lang.String toString()
        Returns a string representation of this accumulator.
        覆盖:
        toString 在类中 java.lang.Object
        返回:
        a string representation of this accumulator
      • main

        public static void main​(java.lang.String[] args)
        Unit tests the Accumulator data type. Reads in a stream of real number from standard input; adds them to the accumulator; and prints the mean, sample standard deviation, and sample variance to standard output.
        参数:
        args - the command-line arguments