rasp87
Posts: 94
Joined: Thu Jun 27, 2013 7:02 am

tedious boost problem with standard deviation

Wed Oct 01, 2014 8:16 am

According to http://stackoverflow.com/questions/7616 ... using-boos, I'm trying to get standard deviation for values of a vector with this code inside a function:

Code: Select all


// includes
#include "boost/accumulators/accumulators.hpp"
#include "boost/accumulators/statistics/stats.hpp"
#include "boost/accumulators/statistics/mean.hpp"
#include "boost/accumulators/statistics/moment.hpp"
#include "boost/bind.hpp"
...
vector<float> vcPenVals;
// initilizing vcPenVals is done here and then
using namespace boost::accumulators;
accumulator_set< float, stats<tag::variance> > acc;
for_each( vcPenVals.begin(), vcPenVals.end(), boost::bind<void>(boost::ref(acc), _1) );
float flStdDev = sqrt( tag::variance(acc) );
cout << "Standard Deviation = " <<  flStdDev << endl;
return flStdDev;

I get these errors though:
/usr/include/boost/accumulators/framework/depends_on.hpp:334: error: invalid use of incomplete type 'struct boost::accumulators::tag::variance'
/usr/include/boost/accumulators/statistics_fwd.hpp:139: error: forward declaration of 'struct boost::accumulators::tag::variance'

rasp87
Posts: 94
Joined: Thu Jun 27, 2013 7:02 am

Re: tedious boost problem with standard deviation

Sat Oct 04, 2014 6:22 am

Are there any ideas to solve this friends? Please say.

User avatar
PeterO
Posts: 4882
Joined: Sun Jul 22, 2012 4:14 pm

Re: tedious boost problem with standard deviation

Sat Oct 04, 2014 7:24 am

rasp87 wrote:Are there any ideas to solve this friends? Please say.
I can't help other than to say that C++ doesn't seem to be very popular on the Pi and that you would probably do better off asking your question on somewhere like stack overflow.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: tedious boost problem with standard deviation

Mon Oct 06, 2014 8:16 am

rasp87 wrote:error: forward declaration of 'struct boost::accumulators::tag::variance'
Just a guess as I'm not a C++ person, but would using a header file ".h" (or whatever C++ uses) fix the forward reference? Not sure, just guessing.

User avatar
jeanleflambeur
Posts: 157
Joined: Mon Jun 16, 2014 6:07 am
Contact: Website

Re: tedious boost problem with standard deviation

Mon Oct 06, 2014 11:37 am

What version of boost and what compiler are you using?

rasp87
Posts: 94
Joined: Thu Jun 27, 2013 7:02 am

Re: tedious boost problem with standard deviation

Mon Oct 06, 2014 1:05 pm

jeanleflambeur wrote:What version of boost and what compiler are you using?
I'm developing in qt creator 2.5.0 and boost version is 105000. (I got the vesion using below code:)

Code: Select all

cout << "boost version is " << BOOST_VERSION 

rasp87
Posts: 94
Joined: Thu Jun 27, 2013 7:02 am

Re: tedious boost problem with standard deviation

Mon Oct 06, 2014 1:07 pm

Ravenous wrote:
rasp87 wrote:error: forward declaration of 'struct boost::accumulators::tag::variance'
Just a guess as I'm not a C++ person, but would using a header file ".h" (or whatever C++ uses) fix the forward reference? Not sure, just guessing.
It doesn't fix all of them. I have mentioned the includes above. I think that is all there is.

User avatar
Redrobes
Posts: 80
Joined: Mon Dec 26, 2011 9:19 pm
Location: S.W. UK
Contact: Website

Re: tedious boost problem with standard deviation

Mon Oct 06, 2014 2:08 pm

I cant specifically help, not having boost etc loaded up right now but the issue is that one of the boost headers has forward declared the tag::variance type but has failed to fully define it. I would expect that there is another header that you would need.

My guess is that accumulators/accumulators.hpp either directly or indirectly includes accumulators/statistics_fwd.hpp and that is what is forward declaring the variance type (at line 139) probably along with a load of other stuff given the header files name. So I would imagine that somewhere in the accumulators.hpp is a list of includes to pull in and one of them below the statistics_fwd header has some compile time define switch tests and that you need something to turn one of them on.

Forward declarations are a huge pain and something I try to avoid as much as I possibly can.

If it were me at this point I would grep through all of boosts headers looking for any reference to the variance tag string and see who (i.e. which header) is actually defining that structure / class. Then go a look for a #include of that header - or possibly just include that header in your list of them.

rasp87
Posts: 94
Joined: Thu Jun 27, 2013 7:02 am

Re: tedious boost problem with standard deviation

Tue Oct 07, 2014 12:42 pm

Now I found it! When you copy code snippet from somewhere things can get a little boring! I was missing variance.hpp. However in the above mentioned thread the required includes weren't mentioned at all. So I write this code here in that someone might need it:

Code: Select all

// includes
#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/moment.hpp"
#include "boost/bind.hpp"
...
vector<float> vcPenVals;
// initilizing vcPenVals is done here and then
using namespace boost::accumulators;
accumulator_set< float, stats<tag::variance> > acc;
for_each( vcPenVals.begin(), vcPenVals.end(), boost::bind<void>(boost::ref(acc), _1) );
float flStdDev = sqrt( variance(acc) );
cout << "Standard Deviation = " <<  flStdDev << endl;

Return to “C/C++”