aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
median.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief median aggregator
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27  */
28 
29 #ifndef GUM_MEDIAN_AGGREGATOR_H
30 #define GUM_MEDIAN_AGGREGATOR_H
31 
32 #include <agrum/tools/multidim/aggregators/multiDimAggregator.h>
33 
34 namespace gum {
35 
36  namespace aggregator {
37  // =========================================================================
38  // === GUM_MEDIAN_AGGREGATOR ===
39  // =========================================================================
40 
41  /**
42  * @class Median
43  * @headerfile median.h <agrum/tools/multidim/aggregators/median.h>
44  * @ingroup multidim_agg_group
45  *
46  * @brief median aggregator
47  *
48  * @see MultiDimAggregator for more details of implementations
49  *
50  * Median needs to have the same domain than its parent.
51  *
52  * @warning if the number of parent is even, the median (with the same type
53  * as its parents) is not well defined : the median of [1,1,3,3] is 2. But
54  * what is the median of [1,1,2,2] ? The mathematical response is 1.5
55  * which is not in the range of the variables. In that case, we choose
56  * (arbitrarilly by excess) the value 2.
57  */
58  template < typename GUM_SCALAR >
60  public:
61  Median();
62  Median(const Median< GUM_SCALAR >& from);
63  virtual ~Median();
64 
65  virtual std::string aggregatorName() const;
66 
67  /**
68  * This method creates a clone of this object, withouth its content
69  * (including variable), you must use this method if you want to ensure
70  * that the generated object has the same type than the object containing
71  * the called newFactory()
72  *
73  * For example :
74  * @code
75  * MultiDimArray<double> y;
76  * MultiDimContainer<double>* x = y.newFactory();
77  * @endcode
78  *
79  * Then x is a MultiDimArray<double>*
80  *
81  * @warning you must desallocate by yourself the memory
82  * @return an empty clone of this object with the same type
83  */
84  virtual MultiDimContainer< GUM_SCALAR >* newFactory() const;
85 
86  protected:
87  virtual Idx buildValue_(const gum::Instantiation& i) const;
88 
89  // fold scheme is not used, these methods are neutralized
90  virtual Idx neutralElt_() const { return 0; };
91  virtual Idx fold_(const DiscreteVariable& v,
92  Idx i1,
93  Idx i2,
94  bool& stop_iteration) const;
95 
96  private:
98  };
99 
100 
101 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
102  extern template class Median< double >;
103 #endif
104 
105 
106  } // namespace aggregator
107 } // namespace gum
108 
109 #include <agrum/tools/multidim/aggregators/median_tpl.h>
110 
111 #endif // GUM_MEDIAN_AGGREGATOR_H
Median(const Median< GUM_SCALAR > &from)
Definition: median_tpl.h:46
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
This method creates a clone of this object, withouth its content (including variable), you must use this method if you want to ensure that the generated object has the same type than the object containing the called newFactory()
Definition: median_tpl.h:65
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
virtual Idx buildValue_(const gum::Instantiation &i) const
by default, buildValue_ uses a "fold" scheme and the user has to implement neutralElt_ and fold_ but ...
Definition: median_tpl.h:70
virtual std::string aggregatorName() const
Definition: median_tpl.h:57
virtual Idx neutralElt_() const
neutralElt_() is the result value for the first application of fold_
Definition: median.h:90
virtual Idx fold_(const DiscreteVariable &v, Idx i1, Idx i2, bool &stop_iteration) const
fold_ is applied on value i1 for variable v. the actual result for precedent applications is i2...
Definition: median_tpl.h:102
median aggregator
Definition: median.h:59
INLINE std::ostream & operator<<(std::ostream &s, const MultiDimAggregator< GUM_SCALAR > &ag)
For friendly displaying the content of the array.