Skip to content

Instantly share code, notes, and snippets.

@nanis
Last active December 7, 2016 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nanis/a3c0106f7f8d615fc1505f0972b56bf9 to your computer and use it in GitHub Desktop.
Save nanis/a3c0106f7f8d615fc1505f0972b56bf9 to your computer and use it in GitHub Desktop.
Simple C++ program to demonstrate boost's variance accumulator
#include <iomanip>
#include <iostream>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/variance.hpp>
#include <boost/accumulators/statistics/stats.hpp>
namespace bacc = boost::accumulators;
static void
demo(const double base)
{
bacc::accumulator_set<double, bacc::stats<bacc::tag::variance(bacc::lazy)> > acc;
std::cout << std::setprecision(15) << base << '\n';
acc(base + 4);
acc(base + 7);
acc(base + 13);
acc(base + 16);
std::cout << bacc::variance(acc) << '\n';
return;
}
int
main(int argc, char *argv[])
{
demo(0);
demo(1e1);
demo(1e3);
demo(1e5);
demo(1e8);
demo(1e9);
return 0;
}
@nanis
Copy link
Author

nanis commented Dec 7, 2016

*** MUST NOT USE lazy***

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment