Home

Recent
Archive

Numerical experiments, Tips, Tricks and Gotchas

Numerically speaking

Single-Pass Online Statistics Algorithms

1. Introduction

The "textbook" two-pass algorithm for the centered moments (variance, skewness, kurtosis, covariance) is obviously inefficient. Unfortunately I could not find suitable one-pass windowed algorithms similar to the mowing average. Therefore I decided to derive the equations myself: Single-Pass Online Statistics Algorithms.

I also decided to publish my Python implementation of the windowed and cumulative first four centeral moments. I think that this will be a good complement to the article.

 

2. Implementation

My Python implementation can be found on GitHub: https://github.com/dr-nikolai/online_stat.

It contains the casses WindowedStat, CumulativeStat, WindowedCovariance, CumulativeCovariance and the function used for testing. It also includes the Jupyter notebook with a test/demo test_online_stat.ipynb.

Note that this code is not fully optimized. It is primarily an illustration to this article.

 

References

  1. Nikolai Shokhirev, Single-Pass Online Statistics Algorithms, 2013, http://www.numericalexpert.com/articles/single_pass_stat/.

 

© Nikolai Shokhirev, 2012-2018

email: nikolai(dot)shokhirev(at)gmail(dot)com

Count: