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; | |
} |
Confirmed on Windows as well
C:\...\var> cl -Ic:\opt\include -EHsc var.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 18.00.31101 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
var.cpp
Microsoft (R) Incremental Linker Version 12.00.31101.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:var.exe
var.obj
C:\...\var> var
0
22.5
10
22.5
1000
22.5
100000
22.5
100000000
22
1000000000
-128
*** MUST NOT USE lazy
***
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On OS X 10.11.6 compiled with
I get the output:
which is really bad.