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.
Namespace: Algs4Net
public class Accumulator
The Accumulator type exposes the following members.
Name | Description | |
---|---|---|
![]() | Accumulator | Initializes an accumulator. |
Name | Description | |
---|---|---|
![]() | AddDataValue |
Adds the specified data value to the accumulator. |
![]() | Count |
Returns the number of data values. |
![]() ![]() | MainTest |
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. |
![]() | Mean |
Returns the mean of the data values. |
![]() | Stddev |
Returns the sample standard deviation of the data values. |
![]() | Var |
Returns the sample variance of the data values. |
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.