Boost logo

Boost Users :

Subject: [Boost-users] [Accumulators] Retract samples
From: Alex Hagen-Zanker (ahh34_at_[hidden])
Date: 2010-12-23 07:00:40


Dear all,

I am considering using Boost Accumulators for a moving window
calculation. When a window would step from left to right, it should add
the sample on the right side of the window and retract the sample on the
left side on each step.

For weighted accumulators, it might be possible to use negative weights.
But, since the accumulators do not appear to be intended for this use,
there may be implementation details that invalidate the use of negative
weights.

Is there a recommended way to retract samples in Boost Accumulators?

Thanks, Alex

p.s. the general idea:

void movingwindowsum(const vector<double>& in, vector<double>& out,
size_t radius )
{
     size_t n = in.size();
     double sum = 0; // This should be an accumulator
     for(size_t i = 0; i < min(n, radius); ++i) {
         sum += in[i ]; // add sample
     }
     out.resize(n);
     for(size_t i = 0; i < n; ++i) {
         size_t left = i - radius - 1;
         size_t right = i + radius;
         if (left >= 0) sum -= in[left]; // retract sample
         if (right < n) sum += in[right]; // add sample
         out[i] = sum;
}


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