Overview
PyPi module | N/A |
git repository | https://bitbucket.org/arrizza-public/cpp-on-the-fly-stats |
git command | git clone git@bitbucket.org:arrizza-public/cpp-on-the-fly-stats.git |
Verification Report | https://arrizza.com/web-ver/cpp-on-the-fly-stats-report.html |
Version Info |
|
- installation: see https://arrizza.com/setup-common
Summary
This C++ library contains various statistic functions (e.g. standard deviation) that can be updated on the fly i.e. the entire dataset is not needed up front.
For a Python version see on-the-fly-stats
- run
./doit
Typical code:
auto otfs1 = OTFStats("ofts1"); # <== created a new set of stats
for (int i = 1; i <= 10; ++i) {
otfs1.update((double)i); # <== adds a new value to on-the-fly stream of values
otfs1.report(writeln); # <== write a formatted line of values
}
printf("%s: avg=%5.2f stddev=%5.2f\n", otfs1.tag().c_str(), otfs1.average(), otfs1.stddev());
Typical output:
-- 2] ofts1 1 1.000000 1.000000 1.000000 nan
-- 3] ofts1 2 1.000000 2.000000 1.500000 0.707107
-- 4] ofts1 3 1.000000 3.000000 2.000000 1.000000
-- 5] ofts1 4 1.000000 4.000000 2.500000 1.290994
-- 6] ofts1 5 1.000000 5.000000 3.000000 1.581139
-- 7] ofts1 6 1.000000 6.000000 3.500000 1.870829
-- 8] ofts1 7 1.000000 7.000000 4.000000 2.160247
-- 9] ofts1 8 1.000000 8.000000 4.500000 2.449490
-- 10] ofts1 9 1.000000 9.000000 5.000000 2.738613
-- 11] ofts1 10 1.000000 10.000000 5.500000 3.027650
-- 12] ofts1: avg= 5.50 stddev= 3.03
You can maintain multiple counters using OTFList. Typical code:
#include "otf_list.h"
// snip
OTFList stats;
stats.create("stats1");
stats.create("stats2");
stats.create("stats3");
stats.get("stats1")->update(1.0);
stats.get("stats2")->update(8.0);
stats.get("stats3")->update(22.0);
stats.report(writeln);
// defines a callback that prints a line from the report
// this can be used to write to a file or stdout as needed
// see ut/ut_tp002_report for an example of writing to an internal vector of lines
static void writeln(const std::string& s)
{
std::cout << s << std::endl;
}
Typical output:
-- 17] Name Count Min Max Average Std Dev
-- 18] --------------- --------------- --------------- --------------- --------------- ---------------
-- 19] stats1 1 1.000000 1.000000 1.000000 nan
-- 20] stats2 1 8.000000 8.000000 8.000000 nan
-- 21] stats3 1 22.000000 22.000000 22.000000 nan