|
Boost : |
Subject: [boost] [accumulators] Dependent and sliding accumulatos_set
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-10-10 02:23:55
Hi,
The acuumulator library allows to determine dependency between accumulator,
but not between accumulator_sets.
I would like to define an accumulator_set c so when we cumulate in two
others c1 and c2 accumulator_set we cumulate also in c, some thing like
typedef dependable_acumulator_set <double, ...> dependable_acc_type;
dependable_acc_type c1, c2;
dependable_acc_type c=c1+c2
dependable_acc_type c3;
c+=c3;
c1(1);
c2(1);
c3(2);
assert(count(c)==3);
assert(sum(c)==4);
How dependable_acumulator_set can be defined? Here follows the interfaces
of such a class and the pseudo code, I've named the class
dependable_acumulator_set, sorry but I have not found a shorter and better
name (may be observed/listened?)
template <typename T, typename F, typename W>
class dependable_acumulator_set : public acumulator_set<T,F,W>
{
public:
dependable_acumulator_set();
void add_dependent(dependable_acumulator_set&);
void remove_dependent(dependable_acumulator_set&);
template<typename A1>
void operator ()(A1 const &a1) {
for (acc in dependents) {
acc(a1);
}
this->acumulator_set_type::operator()(a1);
}
dependable_acumulator_set<T,F,W>&
operator+=(dependable_acumulator_set<T,F,W>);
dependable_acumulator_set<T,F,W>&
operator-=(dependable_acumulator_set<T,F,W>);
};
template <typename T, typename F, typename W>
dependable_acumulator_set<T,F,W>
operator+()(dependable_acumulator_set<T,F,W>,dependable_acumulator_set<T,F,W>);
In addition I would like to be able to cummulate on a sliding window, e.g.
on the last N cummulated values.
I have see the tail accumulator, but I dont know how to define a min_tail
accumulator with the current framework.
I would like a class that behaves like:
typedef sliding_acumulator_set <double, ...> sliding_acc_type;
sliding_acc_type c(window=2);
c(1);
c(5);
c(2);
assert(count(c)==3);
assert(sum(c)==7);
assert(min(c)==2);
We can state the sliding window at compile (template parameter) or run time
(constructor parameter).
template <std::size Window, typename T, typename F, typename W>
class static_sliding_acumulator_set;
template <typename T, typename F, typename W>
class sliding_acumulator_set;
Of course the complexities of the sliding accumulators operations is
increased.
Of course it will be interesting to have a sliding dependable accumulater
set. It would be great to integrate these features on a unique class
(accumulator_set?) in a clean way.
template <typename T, typename F, typename W, typename DependablePolicy,
typename SlicingPolicy>
class acumulator_set;
Please let me know if this can be done in a better way. Is there any
interest on these features?
Eric, what do you think?
Best,
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk