Last active
December 7, 2016 14:59
-
-
Save nanis/a3c0106f7f8d615fc1505f0972b56bf9 to your computer and use it in GitHub Desktop.
Simple C++ program to demonstrate boost's variance accumulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Confirmed on Windows as well