top of page

6_R

  • hrafnulf13
  • Oct 14, 2020
  • 1 min read

Updated: Oct 19, 2020


Online algorithm for the arithmetic mean


The main problem with naive approach is that it is not stable and can cause a loss of significance (catastrofic cancelation etc.) [1, 3].

Also depending on a task, the application might only need to keep and update the mean of the data. The naive approach usually requires to feed all the data and then compute the mean, which will require huge amount of memory to store the data and also to wait until all data is captured, which might not be the case for data stream.


Donald Knuth, in his book ‘The Art of Computer Programming’, proposed to estimate a weighted mean to update the value time to time:

def running_mean(data)
{
    mean = 0;
    for(int i = 0; i < data.size(); ++i)
    {
        mean += (data[i] - mean) / (i+1);
    }
}
    

Using this approach it is possible to compute a data-stream mean without any catastrophic cancellation [1, 2].

 


References


Recent Posts

See All

コメント


bottom of page