Boost logo

Boost Users :

Subject: Re: [Boost-users] Statistical Accumulator
From: Eric Niebler (eric_at_[hidden])
Date: 2010-07-07 11:52:49


On 7/7/2010 11:00 AM, Kraus Philipp wrote:
>
> Am 07.07.2010 um 14:00 schrieb Eric Niebler:
>
>> On 7/6/2010 4:31 PM, Kraus Philipp wrote:
>>> Hi,
>>>
>>> I try to calulate the covariance from some data.
>>>
>>> http://www.boost.org/doc/libs/1_43_0/doc/html/accumulators/user_s_guide.html#accumulators.user_s_guide.the_statistical_accumulators_library.covariance
>>>
>>>
>>> I don't understand the call "acc call". I would like to rebuild the cov
>>> command form Matlab for matrix data
>>> (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/cov.html).
>>> If this is correct, when I give as the first argument of command data
>>> from the first line and second as the data of the first column to the
>>> first value to calculate the new matrix?
>>>
>>> I try try compile the excample, but I get a compiler error on the
>>> "acc::tag::covariate1":
>>>
>>> acc::accumulator_set<double, acc::stats<acc::tag::covariance<double,
>>> acc::tag::covariate1> > > xx;
>>>
>>> xx(1., acc::tag::covariate1 = 2.);
>>> xx(1., acc::tag::covariate1 = 4.);
>>> xx(2., acc::tag::covariate1 = 3.);
>>> xx(6., acc::tag::covariate1 = 1.);
>>>
>>> std::cout << acc::covariance(xx) << std::endl;
>>>
>>> The error text: "expected primary-expression befor = token". Sorry, it's
>>> a little bit late, so I don't see my mistake
>>
>> It's impossible to say from just the little code fragment you've
>> included here. Have you #include
>> <boost/accumulators/statistics/covariance.hpp>?
>>
>> Please include a complete example that demonstrates the problem next
>> time.
>
> Yes, I have had take the example form the Boost page:
> http://boost-sandbox.sourceforge.net/libs/accumulators/doc/html/accumulators/user_s_guide/the_statistical_accumulators_library.html#accumulators.user_s_guide.the_statistical_accumulators_library.covariance
--------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

FYI, that's not where Boost's documentation lives. For the most recent
docs, see:

http://www.boost.org/doc/libs/1_43_0/doc/html/accumulators/user_s_guide.html#accumulators.user_s_guide.the_statistical_accumulators_library.covariance

> Mean and other statistical function works, but only the covariance doesn't

I think you need to add:

    #include <boost/accumulators/statistics/variates/covariate.hpp>

The following program compiles for me:

    #include <boost/accumulators/accumulators.hpp>
    #include <boost/accumulators/statistics/covariance.hpp>
    #include <boost/accumulators/statistics/variates/covariate.hpp>
    #include <boost/assert.hpp>

    namespace acc = boost::accumulators;

    int main()
    {
        acc::accumulator_set<double,
acc::features<acc::tag::covariance<double, acc::tag::covariate1> > > acc;
        acc(1., acc::covariate1 = 2.);
        acc(1., acc::covariate1 = 4.);
        acc(2., acc::covariate1 = 3.);
        acc(6., acc::covariate1 = 1.);
        BOOST_ASSERT(acc::covariance(acc) == -1.75);
    }

I'll add this information to the docs.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net