Question about boost::accumulators

1
2
3
4
5
6
  std::tr1::array<double, 10> alpha;
  std::iota(alpha.begin(), alpha.end(), 0);
  using namespace boost::accumulators;
  size_t const SIZE = 1000000; 
  accumulator_set<double, stats<tag::mean, tag::lazy_variance > > acc;
  std::for_each(alpha.begin(), alpha.end(), [&](double const VALUE){ acc(VALUE);});

How could I clear the contents of the acc if I want to evaluate a new mean and variance?
Thank you very much.
Last edited on
I didn't see any way on boost's website.
Thanks, I got the answer from the other side(daniweb)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
include <iostream>
include <new>
include <boost/utility.hpp>
include <boost/accumulators/accumulators.hpp>
include <boost/accumulators/statistics/stats.hpp>
include <boost/accumulators/statistics/mean.hpp>

template< typename DEFAULT_INITIALIZABLE >
inline void clear( DEFAULT_INITIALIZABLE& object )
{
  object.DEFAULT_INITIALIZABLE::~DEFAULT_INITIALIZABLE();
  ::new ( boost::addressof(object) ) DEFAULT_INITIALIZABLE() ;
}

int main()
{
  using namespace boost::accumulators ;
  accumulator_set< double, features< tag::count, tag::sum, tag::mean > > ac ;
  ac(123) ; ac(456) ; ac(789) ; ac(1234) ;
  std::cout << sum(ac) << '/' << count(ac) << " == " << mean(ac) << '\n' ;
  clear(ac) ;
  ac(1) ; ac(22) ; ac(333) ;
  std::cout << sum(ac) << '/' << count(ac) << " == " << mean(ac) << '\n' ;
}


There are something I don't know
Is accumulator_set using dynamic memory?
Last edited on
Topic archived. No new replies allowed.