aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
scheduleProjection.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 /** @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. */
113  const Set< const DiscreteVariable* >& del_vars,
115  = 0;
117  const Set< const DiscreteVariable* >& del_vars,
119  template < template < typename > class TABLE >
121  const Set< const DiscreteVariable* >& del_vars,
123 
124  /// changes the function used for projecting tables
126  *proj)(const MultiDimImplementation< GUM_SCALAR >&, const Set< const DiscreteVariable* >&))
127  = 0;
128 
129  /// returns the projection function currently used by the projector
130  virtual MultiDimImplementation< GUM_SCALAR >* (*projectFunction())(
131  const MultiDimImplementation< GUM_SCALAR >&,
132  const Set< const DiscreteVariable* >&)
133  = 0;
134 
135  /** @brief returns a rough estimate of the number of operations that will be
136  * performed to compute the projection */
137  virtual float nbOperations(const ScheduleMultiDim< GUM_SCALAR >& table,
138  const Set< const DiscreteVariable* >& del_vars,
139  const Schedule< GUM_SCALAR >& schedule)
140  = 0;
141  float nbOperations(const MultiDimImplementation< GUM_SCALAR >& table,
142  const Set< const DiscreteVariable* >& del_vars,
143  const Schedule< GUM_SCALAR >& schedule);
144  template < template < typename > class TABLE >
145  float nbOperations(const TABLE< GUM_SCALAR >& set,
146  const Set< const DiscreteVariable* >& del_vars,
147  const Schedule< GUM_SCALAR >& schedule);
148 
149  /// returns the memory consumption used during the projection
150  /** Actually, this function does not return a precise account of the memory
151  * used by the multidimProjection but a rough estimate based on the size
152  * of the table involved in the projection.
153  * @return a pair of memory consumption: the first one is the maximum
154  * amount of memory used during the combination and the second one is the
155  * amount of memory still used at the end of the function ( the memory used
156  * by
157  * the resulting table ) */
158  virtual std::pair< long, long > memoryUsage(const ScheduleMultiDim< GUM_SCALAR >& table,
159  const Set< const DiscreteVariable* >& del_vars,
160  const Schedule< GUM_SCALAR >& schedule)
161  = 0;
162  std::pair< long, long > memoryUsage(const MultiDimImplementation< GUM_SCALAR >& table,
163  const Set< const DiscreteVariable* >& del_vars,
164  const Schedule< GUM_SCALAR >& schedule);
165  template < template < typename > class TABLE >
166  std::pair< long, long > memoryUsage(const TABLE< GUM_SCALAR >& table,
167  const Set< const DiscreteVariable* >& del_vars,
168  const Schedule< GUM_SCALAR >& schedule);
169 
170  /// @}
171 
172  private:
173  /// to be coherent with combinations, forbid copy operators
174  ScheduleProjection< GUM_SCALAR >& operator=(const ScheduleProjection< GUM_SCALAR >&);
175  };
176 
177 } /* namespace gum */
178 
179 // always include the template implementation
180 #include <agrum/tools/graphicalModels/inference/scheduler/scheduleProjection_tpl.h>
181 
182 #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:643
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