[Boost-users] [accumulators] Any was to reset an accumulator_set object?

197 views
Skip to first unread message

dhruva

unread,
Feb 23, 2009, 10:14:38 PM2/23/09
to BOOST users

Hello,
I am using boost::accumulator_set to compute mean. After every 100 samples, I need to start afresh. Since I am using accumulator_set as a member variable in a class (I get samples one at a time and need to preserve accumulator_set object across function calls), I need some mechanism to reset it to its initial state. I am not doing anything fancy like using droppable functionality. As a real crude work around, I am keeping 2 objects. The first is not used for any computing and hence its state is same throughout. The computing is done using the second object. After 100 samples, I just copy the first onto the second hoping the state of second object will be same as first which is the initial state.
Is there a better way to achieve the above requirement?

-dhruva

Download prohibited? No problem. CHAT from any browser, without download. Go to http://in.webmessenger.yahoo.com/
_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

er

unread,
Mar 1, 2009, 6:12:46 PM3/1/09
to boost...@lists.boost.org
dhruva wrote:
> Hello,
> I am using boost::accumulator_set to compute mean. After every 100 samples, I need to start afresh. Since I am using accumulator_set as a member variable in a class

(I get samples one at a time and need to preserve accumulator_set object
across function calls), I need some mechanism to reset it to its initial
state.

I am not doing anything fancy like using droppable functionality. As a
real crude work around, I am keeping 2 objects. The first is not used
for any computing and hence

its state is same throughout. The computing is done using the second
object. After 100 samples, I just copy the first onto the second hoping
the state of second object will

be same as first which is the initial state.
> Is there a better way to achieve the above requirement?
>
> -dhruva
>
>
>
> Download prohibited? No problem. CHAT from any browser, without download. Go to http://in.webmessenger.yahoo.com/

As a user of this library I'd think that if n+m is the current iteration
and you want to go back to state n, the easiest way -as you say- is to
create a copy of the set at n. But if n = 0, perhaps obj.set =
set_type(initial parameters)?

Eric Niebler

unread,
Mar 2, 2009, 12:47:30 PM3/2/09
to boost...@lists.boost.org
dhruva wrote:
> Hello, I am using boost::accumulator_set to compute mean. After every
> 100 samples, I need to start afresh. Since I am using accumulator_set
> as a member variable in a class (I get samples one at a time and need
> to preserve accumulator_set object across function calls), I need
> some mechanism to reset it to its initial state.

The issue of being able to reset an accumulator_set was raised during
its review. In the review summary, there is this note:

> The ability to "reset" and accumulator was requested. Eric pointed
> out that it is quite possible to make accumulators with reset methods.
> He also pointed out that it might be desirable to reset
> accumulator_sets, but this could also pose a problem. It is not clear
> what should happen if one of the accumulators used by an accumulator set
> does not have a reset method. Further thought should be given to this
> for possible inclusion in a later revision.

For some accumulators, the "initial state" depends on its initialization
parameters, so resetting can only be done if those parameters are cached
somewhere, or else they are resupplied when calling reset().

It might actually be possible to define a "resetable" accumulator set
that saves its configuration state in a type-erased form and then either
resets itself either by constructing a temporary and doing an
assignment, or else by in-place destruct/construct. The configuration
state could be saved in a pseudo-accumulator. Hmm ...

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

Reply all
Reply to author
Forward
0 new messages