34 #include <agrum/tools/multidim/aggregators/median.h> 35 #include <agrum/tools/multidim/aggregators/multiDimAggregator.h> 39 namespace aggregator {
40 template <
typename GUM_SCALAR >
41 INLINE Median< GUM_SCALAR >::Median() : MultiDimAggregator< GUM_SCALAR >() {
42 GUM_CONSTRUCTOR(Median);
45 template <
typename GUM_SCALAR >
46 INLINE Median< GUM_SCALAR >::Median(
const Median< GUM_SCALAR >& from) :
47 MultiDimAggregator< GUM_SCALAR >(from) {
51 template <
typename GUM_SCALAR >
52 INLINE Median< GUM_SCALAR >::~Median() {
53 GUM_DESTRUCTOR(Median);
56 template <
typename GUM_SCALAR >
57 INLINE std::string Median< GUM_SCALAR >::aggregatorName()
const {
63 template <
typename GUM_SCALAR >
64 INLINE MultiDimContainer< GUM_SCALAR >* Median< GUM_SCALAR >::newFactory()
const {
65 return new Median< GUM_SCALAR >();
68 template <
typename GUM_SCALAR >
69 Idx Median< GUM_SCALAR >::buildValue_(
const gum::Instantiation& i)
const {
70 if (i.nbrDim() < 2)
return i.nbrDim() / 2;
73 Idx maxVal = i.variable(1).domainSize();
75 std::vector< Idx > cum(maxVal, 0);
77 for (Idx j = 1; j <
this->nbrDim(); j++)
80 Idx half = (
this->nbrDim() + 1) / 2;
83 for (Idx j = 0, sumcum = 0; j < maxVal; j++)
84 if ((sumcum += cum[j]) >= half) {
89 for (Idx j = maxVal - 1, jj = 0, sumcum = 0; jj < maxVal; jj++, j--)
90 if ((sumcum += cum[j]) >= half) {
96 return (maxR + max) / 2;
99 template <
typename GUM_SCALAR >
100 INLINE Idx Median< GUM_SCALAR >::fold_(
const DiscreteVariable& v,
103 bool& stop_iteration)
const {