aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
projectionPattern4MultiDimFunctionGraph.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  * @brief the pattern used by all the projections of multidimensional tables
26  *
27  * @author Jean-Christophe MAGNAN
28  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
29  */
30 
31 #include <agrum/tools/multidim/instantiation.h>
32 
33 // check if we allowed these patterns to be used
34 #ifndef GUM_PROJECTION_PATTERN_ALLOWED
35 
36 // #warning To use projectionPattern, you must define
37 // GUM_PROJECTION_PATTERN_ALLOWED
38 
39 #else
40 
41 # include <agrum/tools/multidim/implementations/multiDimFunctionGraph.h>
42 # include <agrum/tools/multidim/implementations/multiDimImplementation.h>
43 # include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/multiDimFunctionGraphProjector.h>
44 
45 namespace gum {
46 
47  // a specialized function for projecting a multiDimFunctionGraph over a subset
48  // of its vars
49 
50 # ifdef GUM_MULTI_DIM_PROJECTION_NAME
51 # define GUM_MULTI_DIM_PROJECTION_TYPE GUM_SCALAR
52  template < typename GUM_SCALAR >
53  MultiDimFunctionGraph< GUM_SCALAR >*
54  GUM_MULTI_DIM_PROJECTION_NAME(const MultiDimFunctionGraph< GUM_SCALAR >* table,
55  const Set< const DiscreteVariable* >& delVars)
56 # endif
57 
58 
59 # ifdef GUM_MULTI_DIM_PROJECTION_IMPL2DECISION_GRAPH_NAME
60 # define GUM_MULTI_DIM_PROJECTION_TYPE GUM_SCALAR
61  template < typename GUM_SCALAR >
62  MultiDimImplementation< GUM_SCALAR >* GUM_MULTI_DIM_PROJECTION_IMPL2DECISION_GRAPH_NAME(
63  const MultiDimImplementation< GUM_SCALAR >* ttable,
64  const Set< const DiscreteVariable* >& delVars)
65 # endif
66  {
67 
68 # ifdef GUM_MULTI_DIM_PROJECTION_IMPL2DECISION_GRAPH_NAME
69  const MultiDimFunctionGraph< GUM_SCALAR >* table
70  = reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(ttable);
71 # endif
72 
73  MultiDimFunctionGraphProjector< GUM_MULTI_DIM_PROJECTION_TYPE,
74  GUM_MULTI_DIM_PROJECTION_OPERATOR >
75  proj(table, delVars, GUM_MULTI_DIM_PROJECTION_NEUTRAL);
76 
77  return proj.project();
78  }
79 
80 
81 # undef GUM_MULTI_DIM_PROJECTION_TYPE
82 } // namespace gum
83 #endif /* GUM_PROJECTION_PATTERN_ALLOWED */