dr-nikolai/online_stat

Single-pass online statistics.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
 Failed to load latest commit information. doc online_statistics test .gitignore README.md test_online_stat.ipynb

Single-Pass Online Statistics Algorithms

Suppliment to the article:

Single-Pass Online Statistics Algorithms, by Nikolai Shokhirev, 2013

Author

Nikolai Shokhirev

File structure & description

``````online_statatistics/
__init__.py
online_stat.py - Defined: WindowedStat, CumulativeStat, WindowedCovariance, CumulativeCovariance
test/
__init__.py
test_utils.py - Defined: win_moment, cum_moment, win_cov, cum_cov
doc/
online_statistics.html - Generated from notebook: all classes, functions and tests.
test_online_stat.ipynb - Test/Demo
``````

numpy

API

``````WindowedStat
rest(n) - can be called to reuse existing object.
s - sum
s2 - central 2-nd order sum
s3 - central 3-rd order sum
s4 - central 4-th order sum
m - mean
m2 - central 2-nd order moment
m3 - central 3-rd order moment
m4 - central 4-th order moment

CumulativeStat
rest() - can be called to reuse existing object.
Same as above.

WindowedCovariance
rest(n) - can be called to reuse existing object.
sx - x-sum
sy - y-sum
sxy - xy-sum
mx - x-mean
my - y-mean
cov - covarianxe

CumulativeCovariance
rest() - can be called to reuse existing object.
Same as above.
``````

Usage example

```# Test data
X = np.array([0.2,1.0,1.4,2.0,2.7,3.8,5.4,7.5,11,15],dtype=float)```
```    # Create processing object
n = 3 # window size
ws =  = WindowedStat(n)
print('Mean,  M2,  M3,  M4')
for x in X:
ws.push(x)
print(ws.m, ws.m2, ws.m3, ws.m4)```

Output:

``````Mean,       M2,  M3,  M4
0.2           0.0 0.0 0.0
0.6           0.16            1.38777878e-17  0.0256
0.86666666667 0.248888888889 -0.0474074074074 0.0929185185185
1.46666666667 0.168888888889  0.0165925925926 0.0427851851852
2.03333333333 0.282222222222  0.0140740740741 0.119474074074
2.83333333333 0.548888888889  0.107407407407  0.451918518519
3.96666666667 1.22888888889   0.302592592593  2.26525185185
5.56666666667 2.29555555556   0.569259259259  7.90436296296
7.96666666667 5.33555555556   3.63325925926 42.7022296296
11.1666666667 9.38888888889   2.34259259259 132.226851852

cs = CumulativeStat()

sSimilar with the other objects.
``````

Test / Demo

test_online_stat.ipynb

``````    The above copyright notice and this permission notice shall be
``````    THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,