Click or drag to resize
Accumulator Class

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.

Inheritance Hierarchy
SystemObject
  Algs4NetAccumulator

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class Accumulator

The Accumulator type exposes the following members.

Constructors
  NameDescription
Public methodAccumulator
Initializes an accumulator.
Top
Methods
  NameDescription
Public methodAddDataValue
Adds the specified data value to the accumulator.
Public methodCount
Returns the number of data values.
Public methodStatic memberMainTest
Demo test 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.
Public methodMean
Returns the mean of the data values.
Public methodStddev
Returns the sample standard deviation of the data values.
Public methodVar
Returns the sample variance of the data values.
Top
Remarks

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

This class is a C# port from the original Java class Accumulator implementation by the respective authors.

See Also