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