https://github.com/wikimedia/runningstat
PHP implementations of online statistical algorithms. Mirror from https://gerrit.wikimedia.org/g/RunningStat - our actual code is hosted with Gerrit (please see https://www.mediawiki.org/wiki/Developer_access for contributing)
https://github.com/wikimedia/runningstat
Last synced: 2 months ago
JSON representation
PHP implementations of online statistical algorithms. Mirror from https://gerrit.wikimedia.org/g/RunningStat - our actual code is hosted with Gerrit (please see https://www.mediawiki.org/wiki/Developer_access for contributing)
- Host: GitHub
- URL: https://github.com/wikimedia/runningstat
- Owner: wikimedia
- License: gpl-2.0
- Created: 2015-10-26T22:16:10.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2025-03-27T14:08:37.000Z (3 months ago)
- Last Synced: 2025-04-09T13:07:38.507Z (2 months ago)
- Language: PHP
- Homepage: https://www.mediawiki.org/wiki/RunningStat
- Size: 129 KB
- Stars: 11
- Watchers: 15
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
RunningStat
===========RunningStat computes the central tendency, shape, and extrema of a set of
points online, in constant space. It uses a neat one-pass algorithm for
calculating variance, described here:This particular implementation adapts a sample C++ implementation by John D.
Cook to PHP. See also:*
*RunningStat instances can be combined. The resultant RunningStat has the same
state it would have had if it had been used to accumulate each point. This
property is attractive because it allows separate threads of execution to
process a stream in parallel. More importantly, individual points can be
accumulated in stages, without loss of fidelity, at intermediate points in the
aggregation process. JavaScript profiling samples can be accumulated in the
user's browser and be combined with measurements from other browsers on the
profiling data aggregator. Functions that are called multiple times in the
course of a profiled web request can be accumulated in MediaWiki prior to being
transmitted to the profiling data aggregator.Usage
-----
Here is how you use it:```php
use Wikimedia\RunningStat;$rstat = new RunningStat();
foreach ( [
49.7168, 74.3804, 7.0115, 96.5769, 34.9458,
36.9947, 33.8926, 89.0774, 23.7745, 73.5154,
86.1322, 53.2124, 16.2046, 73.5130, 10.4209,
42.7299, 49.3330, 47.0215, 34.9950, 18.2914,
] as $sample ) {
$rstat->addObservation( $sample );
}printf(
"n = %d; min = %.2f; max = %.2f; mean = %.2f; variance = %.2f; stddev = %.2f\n",
count( $rstat ),
$rstat->min,
$rstat->max,
$rstat->getMean(),
$rstat->getVariance(),
$rstat->getStdDev()
);
// Output:
// n = 20; min = 7.01; max = 96.58; mean = 47.59; variance = 725.71; stddev = 26.94
```License
-------
GPL-2.0-or-later