Numerical experiments, Tips, Tricks and Gotchas
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.
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.
© Nikolai Shokhirev, 2012-2024
email: nikolai(dot)shokhirev(at)gmail(dot)com