Reputation: 1587
I have a vector of data and I want to find the kurtosis of the data set. I wanted to do so with Boost and here is what I have so far (not compilable):
#include <boost/math/distributions.hpp>
using namespace std;
int main()
{
vector<double> a;
a.push_back(-1);
a.push_back(0);
a.push_back(1);
cout << "Kurtosis:"<< kurtosis(a) << endl;
return 0;
}
Why doesn't this work? My compiler gives me the error: "[...]\main.cpp|28|error: 'kurtosis' was not declared in this scope|"
Upvotes: 6
Views: 1375
Reputation: 158599
For one you were not including the header for kurtosis
:
#include <boost/accumulators/statistics/kurtosis.hpp>
Even if you did, as you see it does not work with a straight vector
, what you probably want to do is use an accumulator_set
and more headers as well.
Here is a minimal example using accumulator_set
, this shows a two methods to solve the problem:
#include <boost/math/distributions.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/variance.hpp>
#include <boost/accumulators/statistics/kurtosis.hpp>
#include <iostream>
#include <vector>
using namespace boost::accumulators;
int main()
{
accumulator_set<double, stats<tag::mean, tag::kurtosis > > acc;
accumulator_set<double, stats<tag::mean, tag::kurtosis > > acc2;
acc(2) ;
acc(3) ;
acc(4) ;
std::cout << mean(acc) << " " << kurtosis(acc) << std::endl ;
std::vector<double> v1 ;
v1.push_back(2);
v1.push_back(3);
v1.push_back(4);
acc2 = std::for_each( v1.begin(), v1.end(), acc2 ) ;
std::cout << mean(acc2) << " " << kurtosis(acc2) << std::endl ;
}
Here is a link to the Accumulators Framework
User's Guide. This guide has some nice examples.
This previous thread found a way to use vector
, although it is not straight forward at all and I could not get it work.
Upvotes: 1