Code Examples
A repository of 155 code examples for BeepBeep
basic.Average Class Reference

Compute the cumulative average of a list of numbers. More...

Static Public Member Functions

static void main (String[] args)
 

Detailed Description

Compute the cumulative average of a list of numbers.

The cumulative average is the average of all the numbers processed so far.

Consider for example the stream of numbers 2, 7, 1, 8, …. After reading the first event, the cumulative average is 2  1 = 2. After reading the second event, the average is (2 + 7)  2, and after reading the third, the average is (2 + 7 + 1)  3 = 3.33 –and so on.

This example illustrates the use of the Cumulate and CumulativeFunction objects.

We will compute this average by computing the cumulative sum of a stream of numbers, and dividing it by the value of a counter that increments by 1 each time it is pulled. Represented graphically, this example corresponds to the following chain of processors:

Processor graph

The output of this program should look like this:

 The cumulative average is...
 2.0, 4.5, 3.3333333, 4.5, 4.0, 4.6666665, 4.142857, 4.625, 4.3333335, 
Author
Sylvain Hallé Easy

Definition at line 63 of file Average.java.


The documentation for this class was generated from the following file: