aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
scheduleProjection.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 /** @file
23  * @brief A generic class to project efficiently a ScheduleMultiDim over a
24  *subset
25  * of its variables
26  *
27  * ScheduleProjection is a generic wrapper designed to project efficiently a
28  * multidimensional schedule object over a subset of its variables.
29  *
30  * To be quite generic, the ScheduleProjection takes in argument the function
31  * that produces the result of the projection of the multidimensional object.
32  * The following code gives an example of the usage of ScheduleProjection:
33  * @code
34  * // a function used to project a MultiDimImplementation<float>:
35  * MultiDimImplementation<float>*
36  * MinPot ( const MultiDimImplementation<float>& table,
37  * const Set<const DiscreteVariable*>& del_vars ) {
38  * return new MultiDimImplementation<float> (...);
39  * }
40  *
41  * // another function used to project a MultiDimImplementation<float>:
42  * MultiDimImplementation<float>*
43  * MaxPot ( const Potential<float>& table,
44  * const Set<const DiscreteVariable*>& del_vars ) {
45  * return new Potential<float> (...);
46  * }
47  *
48  *
49  * Schedule<float> schedule;
50  * ScheduleMultiDim<float> t1, t2;
51  * Set<const DiscreteVariable*> set1, set2;
52  * ScheduleProjectionBasic<float> Proj ( MinPot );
53  * ScheduleMultiDim<float> proj_table1 = Proj.project ( t1, set1, schedule );
54  *
55  * // change the operator to apply
56  * Proj.setProjectFunction ( MaxPot );
57  * ScheduleMultiDim<float> proj_table2 = Proj.project ( t2, set2, schedule );
58  *
59  * @endcode
60  *
61  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
62  */
63 
64 #ifndef GUM_SCHEDULE_PROJECTION_H
65 #define GUM_SCHEDULE_PROJECTION_H
66 
67 #include <agrum/tools/core/set.h>
68 #include <agrum/tools/graphicalModels/inference/scheduler/schedule.h>
69 #include <agrum/tools/graphicalModels/inference/scheduler/scheduleMultiDim.h>
70 #include <agrum/tools/variables/discreteVariable.h>
71 #include <utility>
72 
73 namespace gum {
74 
75  template < typename GUM_SCALAR >
77  public:
78  // ############################################################################
79  /// @name Constructors / Destructors
80  // ############################################################################
81  /// @{
82 
83  /// default constructor
85 
86  /// copy constructor
87  ScheduleProjection(const ScheduleProjection< GUM_SCALAR >&);
88 
89  /// destructor
90  virtual ~ScheduleProjection();
91 
92  /// virtual constructor
93  /** @return a new fresh ScheduleCombinator with the same projection
94  * function. */
95  virtual ScheduleProjection< GUM_SCALAR >* newFactory() const = 0;
96 
97  /// @}
98 
99  // ############################################################################
100  /// @name Accessors/Modifiers
101  // ############################################################################
102  /// @{
103 
104  /// creates and returns the projection of the table over a subset of its
105  /// vars
106  /** @return a new freshly created ScheduleMultiDim which is the result of
107  * the
108  * projection of the table passed in argument over the set of variables
109  * NOT IN del_vars
110  * @warning If del_vars is precisely equal to the variables of table, the
111  * result is an empty table. */
112  virtual ScheduleMultiDim< GUM_SCALAR >
114  const Set< const DiscreteVariable* >& del_vars,
116  = 0;
119  const Set< const DiscreteVariable* >& del_vars,
121  template < template < typename > class TABLE >
123  project(const TABLE< GUM_SCALAR >& table,
124  const Set< const DiscreteVariable* >& del_vars,
126 
127  /// changes the function used for projecting tables
130  const Set< const DiscreteVariable* >&))
131  = 0;
132 
133  /// returns the projection function currently used by the projector
134  virtual MultiDimImplementation< GUM_SCALAR >* (*projectFunction())(
135  const MultiDimImplementation< GUM_SCALAR >&,
136  const Set< const DiscreteVariable* >&)
137  = 0;
138 
139  /** @brief returns a rough estimate of the number of operations that will be
140  * performed to compute the projection */
141  virtual float nbOperations(const ScheduleMultiDim< GUM_SCALAR >& table,
142  const Set< const DiscreteVariable* >& del_vars,
143  const Schedule< GUM_SCALAR >& schedule)
144  = 0;
145  float nbOperations(const MultiDimImplementation< GUM_SCALAR >& table,
146  const Set< const DiscreteVariable* >& del_vars,
147  const Schedule< GUM_SCALAR >& schedule);
148  template < template < typename > class TABLE >
149  float nbOperations(const TABLE< GUM_SCALAR >& set,
150  const Set< const DiscreteVariable* >& del_vars,
151  const Schedule< GUM_SCALAR >& schedule);
152 
153  /// returns the memory consumption used during the projection
154  /** Actually, this function does not return a precise account of the memory
155  * used by the multidimProjection but a rough estimate based on the size
156  * of the table involved in the projection.
157  * @return a pair of memory consumption: the first one is the maximum
158  * amount of memory used during the combination and the second one is the
159  * amount of memory still used at the end of the function ( the memory used
160  * by
161  * the resulting table ) */
162  virtual std::pair< long, long >
163  memoryUsage(const ScheduleMultiDim< GUM_SCALAR >& table,
164  const Set< const DiscreteVariable* >& del_vars,
165  const Schedule< GUM_SCALAR >& schedule)
166  = 0;
167  std::pair< long, long >
168  memoryUsage(const MultiDimImplementation< GUM_SCALAR >& table,
169  const Set< const DiscreteVariable* >& del_vars,
170  const Schedule< GUM_SCALAR >& schedule);
171  template < template < typename > class TABLE >
172  std::pair< long, long >
173  memoryUsage(const TABLE< GUM_SCALAR >& table,
174  const Set< const DiscreteVariable* >& del_vars,
175  const Schedule< GUM_SCALAR >& schedule);
176 
177  /// @}
178 
179  private:
180  /// to be coherent with combinations, forbid copy operators
181  ScheduleProjection< GUM_SCALAR >&
182  operator=(const ScheduleProjection< GUM_SCALAR >&);
183  };
184 
185 } /* namespace gum */
186 
187 // always include the template implementation
188 #include <agrum/tools/graphicalModels/inference/scheduler/scheduleProjection_tpl.h>
189 
190 #endif /* GUM_SCHEDULE_PROJECTION_H */
virtual ScheduleProjection< GUM_SCALAR > * newFactory() const =0
virtual constructor
ScheduleProjection()
default constructor
float nbOperations(const TABLE< GUM_SCALAR > &set, const Set< const DiscreteVariable * > &del_vars, const Schedule< GUM_SCALAR > &schedule)
creates and returns the projection of the table over a subset of its vars
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
virtual ~ScheduleProjection()
destructor
float nbOperations(const MultiDimImplementation< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, const Schedule< GUM_SCALAR > &schedule)
creates and returns the projection of the table over a subset of its vars
std::pair< long, long > memoryUsage(const MultiDimImplementation< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, const Schedule< GUM_SCALAR > &schedule)
creates and returns the projection of the table over a subset of its vars
virtual void setProjectFunction(MultiDimImplementation< GUM_SCALAR > *(*proj)(const MultiDimImplementation< GUM_SCALAR > &, const Set< const DiscreteVariable * > &))=0
changes the function used for projecting tables
ScheduleMultiDim< GUM_SCALAR > project(const TABLE< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, Schedule< GUM_SCALAR > &schedule)
creates and returns the projection of the table over a subset of its vars
ScheduleProjection(const ScheduleProjection< GUM_SCALAR > &)
copy constructor
ScheduleMultiDim< GUM_SCALAR > project(const MultiDimImplementation< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, Schedule< GUM_SCALAR > &schedule)
creates and returns the projection of the table over a subset of its vars
ScheduleProjection< GUM_SCALAR > & operator=(const ScheduleProjection< GUM_SCALAR > &)
to be coherent with combinations, forbid copy operators
std::pair< long, long > memoryUsage(const TABLE< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, const Schedule< GUM_SCALAR > &schedule)
creates and returns the projection of the table over a subset of its vars