#include <vector>
#include <algorithm>
#include <iostream>
#include <functional>

#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/density.hpp>
#include <boost/accumulators/statistics/stats.hpp>

using namespace std;
using namespace std::placeholders;
using namespace boost;
using namespace boost::accumulators;

typedef accumulator_set<double, features<tag::density> > acc;
typedef iterator_range<std::vector<std::pair<double, double> >::iterator > histogram_type;

template <typename T>
class data_filler
{
public:
data_filler(){}
T operator()() { return rand()/(T)RAND_MAX; }
};

int main(int argc, char** argv)
{

acc myAccumulator( tag::density::num_bins = 20, tag::density::cache_size = 10);

vector<double> lines(100);
iota(lines,0);
for(auto &i:lines) i/=100;
boost::copy(lines, ostream_iterator<double>(cout,” “));
std::for_each(lines.begin(), lines.end(),std::ref(myAccumulator));

histogram_type hist = density(myAccumulator);

double total = 0.0;

for( int i = 0; i < hist.size(); i++ )
{
std::cout << “Bin lower bound: ” << hist[i].first << “, Value: ” << hist[i].second << std::endl;
total += hist[i].second;
}

std::cout << “Total: ” << total << std::endl; //should be 1 (and it is)

return 0;
}

Advertisements