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 >*
65 Median< GUM_SCALAR >::newFactory()
const {
66 return new Median< GUM_SCALAR >();
69 template <
typename GUM_SCALAR >
70 Idx Median< GUM_SCALAR >::buildValue_(
const gum::Instantiation& i)
const {
72 return i.nbrDim() / 2;
75 Idx maxVal = i.variable(1).domainSize();
77 std::vector< Idx > cum(maxVal, 0);
79 for (Idx j = 1; j <
this->nbrDim(); j++)
82 Idx half = (
this->nbrDim() + 1) / 2;
85 for (Idx j = 0, sumcum = 0; j < maxVal; j++)
86 if ((sumcum += cum[j]) >= half) {
91 for (Idx j = maxVal - 1, jj = 0, sumcum = 0; jj < maxVal; jj++, j--)
92 if ((sumcum += cum[j]) >= half) {
98 return (maxR + max) / 2;
101 template <
typename GUM_SCALAR >
102 INLINE Idx Median< GUM_SCALAR >::fold_(
const DiscreteVariable& v,
105 bool& stop_iteration)
const {