aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
scheduleProjectionBasic.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_BASIC_H
65 #define GUM_SCHEDULE_PROJECTION_BASIC_H
66 
67 #include <agrum/tools/graphicalModels/inference/scheduler/scheduleProjection.h>
68 
69 namespace gum {
70 
71  template < typename GUM_SCALAR >
73  public:
74  // ############################################################################
75  /// @name Constructors / Destructors
76  // ############################################################################
77  /// @{
78 
79  /// default constructor
82  const Set< const DiscreteVariable* >&));
83 
84  /// copy constructor
86 
87  /// destructor
88  virtual ~ScheduleProjectionBasic();
89 
90  /// virtual constructor
91  /** @return a new fresh ScheduleCombinator with the same projection
92  * function. */
93  virtual ScheduleProjectionBasic< GUM_SCALAR >* newFactory() const;
94 
95  /// @}
96 
97  // ############################################################################
98  /// @name Accessors/Modifiers
99  // ############################################################################
100  /// @{
101 
102  /// creates and returns the projection of the table over a subset of its
103  /// vars
104  /** @return a new freshly created ScheduleMultiDim which is the result of
105  * the
106  * projection of the table passed in argument over the set of variables
107  * NOT IN del_vars
108  * @warning If del_vars is precisely equal to the variables of table, the
109  * result is an empty table. */
112  const Set< const DiscreteVariable* >& del_vars,
116  const Set< const DiscreteVariable* >& del_vars,
118  template < template < typename > class TABLE >
120  project(const TABLE< GUM_SCALAR >& table,
121  const Set< const DiscreteVariable* >& del_vars,
123 
124  /// changes the function used for projecting tables
127  const Set< const DiscreteVariable* >&));
128 
129  /// returns the projection function currently used by the projector
130  MultiDimImplementation< GUM_SCALAR >* (*projectFunction())(
131  const MultiDimImplementation< GUM_SCALAR >&,
132  const Set< const DiscreteVariable* >&);
133 
134  /** @brief returns a rough estimate of the number of operations that will be
135  * performed to compute the projection */
136  virtual float nbOperations(const ScheduleMultiDim< GUM_SCALAR >& table,
137  const Set< const DiscreteVariable* >& del_vars,
138  const Schedule< GUM_SCALAR >& schedule);
139  float nbOperations(const MultiDimImplementation< GUM_SCALAR >& table,
140  const Set< const DiscreteVariable* >& del_vars,
141  const Schedule< GUM_SCALAR >& schedule);
142  template < template < typename > class TABLE >
143  float nbOperations(const TABLE< GUM_SCALAR >& set,
144  const Set< const DiscreteVariable* >& del_vars,
145  const Schedule< GUM_SCALAR >& schedule);
146 
147  /// returns the memory consumption used during the projection
148  /** Actually, this function does not return a precise account of the memory
149  * used by the multidimProjection but a rough estimate based on the size
150  * of the table involved in the projection.
151  * @return a pair of memory consumption: the first one is the maximum
152  * amount of memory used during the combination and the second one is the
153  * amount of memory still used at the end of the function ( the memory used
154  * by
155  * the resulting table ) */
156  virtual std::pair< long, long >
158  const Set< const DiscreteVariable* >& del_vars,
159  const Schedule< GUM_SCALAR >& schedule);
160  std::pair< long, long >
162  const Set< const DiscreteVariable* >& del_vars,
163  const Schedule< GUM_SCALAR >& schedule);
164  template < template < typename > class TABLE >
165  std::pair< long, long >
166  memoryUsage(const TABLE< GUM_SCALAR >& table,
167  const Set< const DiscreteVariable* >& del_vars,
168  const Schedule< GUM_SCALAR >& schedule);
169 
170  /// @}
171 
172  protected:
173  /// the projection function actually used
176  const Set< const DiscreteVariable* >&);
177 
178  private:
179  /// to be coherent with combinations, forbid copy operators
180  ScheduleProjectionBasic< GUM_SCALAR >&
181  operator=(const ScheduleProjectionBasic< GUM_SCALAR >&);
182  };
183 
184 } /* namespace gum */
185 
186 // always include the template implementation
187 #include <agrum/tools/graphicalModels/inference/scheduler/scheduleProjectionBasic_tpl.h>
188 
189 #endif /* GUM_SCHEDULE_PROJECTION_H */
ScheduleProjectionBasic(MultiDimImplementation< GUM_SCALAR > *(*proj)(const MultiDimImplementation< GUM_SCALAR > &, const Set< const DiscreteVariable * > &))
default 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
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
ScheduleProjectionBasic< GUM_SCALAR > & operator=(const ScheduleProjectionBasic< GUM_SCALAR > &)
to be coherent with combinations, forbid copy operators
virtual ~ScheduleProjectionBasic()
destructor
void setProjectFunction(MultiDimImplementation< GUM_SCALAR > *(*proj)(const MultiDimImplementation< GUM_SCALAR > &, const Set< const DiscreteVariable * > &))
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
ScheduleProjectionBasic(const ScheduleProjectionBasic< GUM_SCALAR > &)
copy constructor
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
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
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
virtual ScheduleProjectionBasic< GUM_SCALAR > * newFactory() const
virtual constructor