Boost logo

Boost :

Subject: Re: [boost] [accumulators] Help understanding implementation of weighted accumulators
From: Gabriel Redner (gredner_at_[hidden])
Date: 2013-10-02 16:48:59


Sorry to revive an old thread, but I'd still be interested in the
answers to these questions.

-Gabe

On Wed, May 1, 2013 at 11:06 PM, Gabriel Redner <gredner_at_[hidden]> wrote:
> Hi Eric,
>
> Thanks very much for your response. That does help, and I have some follow-ups.
>
> First, let me make sure I am understanding correctly. If my Sample is
> some FancyType whose default constructor does not do the right thing
> (or perhaps does not exist), I should do:
>
> accumulator_set<FancyType, features<some_features> > acc(sample =
> some_initial_fancytype_value);
>
> Is that right? If so, I would say that:
> - This usage is not mentioned in the docs anywhere, and
> - It seems strange to overload the meaning of 'sample' in this way.
> Wouldn't it be clearer and accomplish the same goal to use a different
> name? "initialValue" perhaps?
> - Do all accumulators support this feature? I can imagine some that
> might not (indeed I am implementing one). This is not mentioned in
> the docs either.
>
> Second, I have a sort-of-question-but-mostly-a-kvetch about defining
> keywords for accumulators that need initialization parameters (e.g.
> tail). The library itself uses the macro
> BOOST_PARAMETER_NESTED_KEYWORD for this, which is not documented. I
> do not understand what this macro does - why the name, why the alias,
> etc? My own accumulators need initialization parameters, and I have
> just been aping what the library itself does - using the macro
> although it's not documented, and hoping for the best. It seems to be
> working, but I'd like to understand if this is the right approach,
> whether I can rely on this undocumented macro, and what it's doing.
> Can you shed any light?
>
> Thanks,
> -Gabe
>
> On Wed, May 1, 2013 at 8:23 PM, Eric Niebler <eniebler_at_[hidden]> wrote:
>> On 5/1/2013 1:13 PM, Gabriel Redner wrote:
>>> Hi folks,
>>>
>>> I am trying to implement a weighted accumulator, but I'm having
>>> trouble understanding a few things about the existing ones.
>>>
>>> Looking at the implementation of weighted_sum, I see (weighted_sum.hpp:37):
>>>
>>> template<typename Args>
>>> weighted_sum_impl(Args const &args)
>>> : weighted_sum_(
>>> args[parameter::keyword<Tag>::get() | Sample()]
>>> * numeric::one<Weight>::value
>>> )
>>> {
>>> }
>>>
>>> My questions are:
>>>
>>> - It's taking the first sample from the args and multiplying it by a
>>> weight of 1. Isn't this wrong - ignoring the real weight of this
>>> sample? Shouldn't this produce incorrect results?
>>
>> It's not taking the first sample. It's (optionally) taking an element
>> representing zero. In most cases, a default-constructed Sample() is
>> satisfactory for a zero element, but in some cases it's not. Consider
>> what happens if your Sample type is std::vector<int>, and all your
>> samples are going to be 3-element vectors. Then your zero is a
>> std::vector<int> with 3 zeros. Any other starting value would cause all
>> future computation to fail.
>>
>> And we multiply by one to make the type promotion come out right.
>>
>>> - I've never understood anyways how there can be an initial argument
>>> during construction of the accumulator. I haven't found any
>>> explanation in the docs beyond "Maybe there is an initial value in the
>>> argument pack". Maybe? How?
>>
>> I hope that clears it up.
>>
>> --
>> Eric Niebler
>> Boost.org
>> http://www.boost.org
>>
>> _______________________________________________
>> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk