aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
multiDimCombineAndProjectDefault.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  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 
28 #ifndef GUM_MULTI_DIM_COMBINE_AND_PROJECT_DEFAULT_H
29 #define GUM_MULTI_DIM_COMBINE_AND_PROJECT_DEFAULT_H
30 
31 #include <agrum/tools/multidim/utils/operators/multiDimCombinationDefault.h>
32 #include <agrum/tools/multidim/utils/operators/multiDimCombineAndProject.h>
33 #include <agrum/tools/multidim/utils/operators/multiDimProjection.h>
34 
35 namespace gum {
36 
37  // clang-format off
38  /**
39  * @class MultiDimCombineAndProjectDefault
40  * @headerfile multiDimCombineAndProjectDefault.h <agrum/tools/multidim/operators/multiDimCombineAndProjectDefault.h>
41  * @ingroup multidim_op_group
42  *
43  * @brief An efficient class for combining and projecting MultiDim tables
44  */
45  // clang-format on
46  template < typename GUM_SCALAR, template < typename > class TABLE >
49  public:
50  // ========================================================================
51  /// @name Constructors / Destructors
52  // ========================================================================
53  /// @{
54 
55  /// Default constructor
57  TABLE< GUM_SCALAR >* (*combine)(const TABLE< GUM_SCALAR >&,
58  const TABLE< GUM_SCALAR >&),
59  TABLE< GUM_SCALAR >* (*project)(const TABLE< GUM_SCALAR >&,
60  const Set< const DiscreteVariable* >&));
61 
62  /// Copy constructor
65 
66  /// Destructor
68 
69  /**
70  * @brief virtual constructor
71  *
72  * @return a new fresh MultiDimCombineAndProjectDefault with the same
73  * combination and projection functions.
74  */
76  newFactory() const;
77 
78  /// @}
79  // ========================================================================
80  /// @name Accessors/Modifiers
81  // ========================================================================
82  /// @{
83 
84  /**
85  * @brief creates and returns the result of the projection over the
86  * variables not in del_vars of the combination of the tables within set
87  *
88  * @return a new freshly created TABLE which is the result of the
89  * projection of the combination of all the TABLES passed in argument
90  *
91  * @throws InvalidArgumentsNumber exception is thrown if the set passed in
92  * argument contains less than two elements.
93  */
94  virtual Set< const TABLE< GUM_SCALAR >* >
96  Set< const DiscreteVariable* > del_vars);
97 
98  /// changes the function used for combining two TABLES
99  virtual void setCombineFunction(TABLE< GUM_SCALAR >* (
100  *combine)(const TABLE< GUM_SCALAR >&, const TABLE< GUM_SCALAR >&));
101 
102  /**
103  * @brief changes the class that performs the combinations
104  *
105  * Combinations are performed by pair, the CombineFunction being the
106  * function used to combine 2 tables, thus producing a new one. Of course,
107  * when we have to combine, say T1 * T2 * T3 * T4, there are several ways
108  * to do this computation. For instance, we might first compute T1 * T2,
109  * then T3 * T4, and finally compute the product of the resulting two
110  * tables. Or we might compute T1 * T2, then combine the result with T3,
111  * and then combine the last result with T4. The CombinationClass is
112  * responsible for determining which of these possibilities will actually
113  * be used. Function setCombinationClass allows to change the
114  * combinationClass and, thus, the way all those tables will be combined.
115  */
116  virtual void setCombinationClass(
117  const MultiDimCombination< GUM_SCALAR, TABLE >& comb_class);
118 
119  /// Returns the current combination function
120  virtual TABLE< GUM_SCALAR >* (*combineFunction())(const TABLE< GUM_SCALAR >&,
121  const TABLE< GUM_SCALAR >&);
122 
123  /// Changes the function used for projecting TABLES
124  virtual void setProjectFunction(TABLE< GUM_SCALAR >* (
125  *proj)(const TABLE< GUM_SCALAR >&, const Set< const DiscreteVariable* >&));
126 
127  /**
128  * @brief Changes the class that performs the projections.
129  *
130  * As for the combination class, it is possible to change the projection
131  * class, thus defining a new projection behaviour.
132  */
133  virtual void setProjectionClass(
134  const MultiDimProjection< GUM_SCALAR, TABLE >& proj_class);
135 
136  /// returns the current projection function
137  virtual TABLE< GUM_SCALAR >* (*projectFunction())(
138  const TABLE< GUM_SCALAR >&,
139  const Set< const DiscreteVariable* >&);
140 
141  /**
142  * @brief returns a rough estimate of the number of operations that will be
143  * performed to compute the combination.
144  */
145  virtual float
146  nbOperations(const Set< const TABLE< GUM_SCALAR >* >& set,
147  const Set< const DiscreteVariable* >& del_vars) const;
148 
149  /**
150  * @brief returns a rough estimate of the number of operations that will be
151  * performed to compute the combination.
152  */
153  virtual float
154  nbOperations(const Set< const Sequence< const DiscreteVariable* >* >& set,
155  Set< const DiscreteVariable* > del_vars) const;
156 
157  /**
158  * @brief returns the memory consumption used during the combinations and
159  * projections
160  *
161  * Actually, this function does not return a precise account of the memory
162  * used by the MultiDimCombineAndProject but a rough estimate based on the
163  * size of the tables involved in the combinations and projections.
164  *
165  * @return a pair of memory consumption: the first one is the maximum
166  * amount of memory used during the set of combinations and projections
167  * performed, and the second one is the amount of memory still used at the
168  * end of the function ( the memory used by the resulting tables )
169  */
170  virtual std::pair< long, long >
171  memoryUsage(const Set< const TABLE< GUM_SCALAR >* >& set,
172  const Set< const DiscreteVariable* >& del_vars) const;
173 
174  /**
175  * @brief returns the memory consumption used during the combinations and
176  * projections
177  *
178  * Actually, this function does not return a precise account of the memory
179  * used by the MultiDimCombineAndProject but a rough estimate based on the
180  * size of the tables involved in the combinations and projections.
181  *
182  * @return a pair of memory consumption: the first one is the maximum
183  * amount of memory used during the set of combinations and projections
184  * performed, and the second one is the amount of memory still used at the
185  * end of the function ( the memory used by the resulting tables )
186  */
187  virtual std::pair< long, long >
188  memoryUsage(const Set< const Sequence< const DiscreteVariable* >* >& set,
189  Set< const DiscreteVariable* > del_vars) const;
190 
191  /// @}
192 
193  private:
194  /// the class used for the combinations
196 
197  /// the class used for the projections
199  };
200 
201 } /* namespace gum */
202 
203 // always include the template implementation
204 #include <agrum/tools/multidim/utils/operators/multiDimCombineAndProjectDefault_tpl.h>
205 
206 #endif /* GUM_MULTI_DIM_COMBINE_AND_PROJECT_DEFAULT_H */
An efficient class for combining and projecting MultiDim tables.
virtual ~MultiDimCombineAndProjectDefault()
Destructor.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
virtual void setCombineFunction(TABLE< GUM_SCALAR > *(*combine)(const TABLE< GUM_SCALAR > &, const TABLE< GUM_SCALAR > &))
changes the function used for combining two TABLES
MultiDimCombineAndProjectDefault(const MultiDimCombineAndProjectDefault< GUM_SCALAR, TABLE > &)
Copy constructor.
virtual std::pair< long, long > memoryUsage(const Set< const Sequence< const DiscreteVariable * > * > &set, Set< const DiscreteVariable * > del_vars) const
returns the memory consumption used during the combinations and projections
virtual float nbOperations(const Set< const TABLE< GUM_SCALAR > * > &set, const Set< const DiscreteVariable * > &del_vars) const
returns a rough estimate of the number of operations that will be performed to compute the combinatio...
virtual void setProjectionClass(const MultiDimProjection< GUM_SCALAR, TABLE > &proj_class)
Changes the class that performs the projections.
virtual void setCombinationClass(const MultiDimCombination< GUM_SCALAR, TABLE > &comb_class)
changes the class that performs the combinations
MultiDimCombination< GUM_SCALAR, TABLE > * combination__
the class used for the combinations
MultiDimProjection< GUM_SCALAR, TABLE > * projection__
the class used for the projections
MultiDimCombineAndProjectDefault(TABLE< GUM_SCALAR > *(*combine)(const TABLE< GUM_SCALAR > &, const TABLE< GUM_SCALAR > &), TABLE< GUM_SCALAR > *(*project)(const TABLE< GUM_SCALAR > &, const Set< const DiscreteVariable * > &))
Default constructor.
virtual MultiDimCombineAndProjectDefault< GUM_SCALAR, TABLE > * newFactory() const
virtual constructor
virtual float nbOperations(const Set< const Sequence< const DiscreteVariable * > * > &set, Set< const DiscreteVariable * > del_vars) const
returns a rough estimate of the number of operations that will be performed to compute the combinatio...
virtual std::pair< long, long > memoryUsage(const Set< const TABLE< GUM_SCALAR > * > &set, const Set< const DiscreteVariable * > &del_vars) const
returns the memory consumption used during the combinations and projections
virtual void setProjectFunction(TABLE< GUM_SCALAR > *(*proj)(const TABLE< GUM_SCALAR > &, const Set< const DiscreteVariable * > &))
Changes the function used for projecting TABLES.
virtual Set< const TABLE< GUM_SCALAR > *> combineAndProject(Set< const TABLE< GUM_SCALAR > * > set, Set< const DiscreteVariable * > del_vars)
creates and returns the result of the projection over the variables not in del_vars of the combinatio...