aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
regress.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  * @brief Class used to compute the operation between two decision diagrams
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
28  * GONZALES(@AMU)
29  */
30 
31 #ifndef GUM_REGRESS_H
32 #define GUM_REGRESS_H
33 
34 #include <agrum/tools/multidim/implementations/multiDimFunctionGraph.h>
35 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/o4DGContext.h>
36 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/terminalNodePolicies/ExactTerminalNodePolicy.h>
37 
38 namespace gum {
39 
40  /**
41  * @class Regress
42  * @headerfile regress.h <agrum/tools/multidim/patterns/regress.h>
43  * @brief Class used to perform Function Graph Operations in the FMDP
44  * Framework
45  * @ingroup multidim_group
46  */
47  template < typename GUM_SCALAR,
48  template < typename >
49  class COMBINEOPERATOR,
50  template < typename >
51  class PROJECTOPERATOR,
52  template < typename > class TerminalNodePolicy = ExactTerminalNodePolicy >
53  class Regress {
54  public:
55  // ============================================================================
56  /// @name Constructors / Destructors
57  // ============================================================================
58  /// @{
59 
60  /// Default constructor.
61  Regress(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* vfunction,
62  const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* probDist,
63  const Set< const DiscreteVariable* >* primedVars,
64  const DiscreteVariable* targetVar,
65  const GUM_SCALAR neutral);
66 
67  /// Default destructor.
68  ~Regress();
69 
70  /// @}
71 
72  // ============================================================================
73  /// @name Main Method
74  // ============================================================================
75  /// @{
76 
77  /// Computes and builds the Function Graph that is the result of the
78  /// operation
80 
81  /// @}
82 
83  private:
84  /// Computes an order for the final Decision graph that will minimize the
85  /// number
86  /// of re exploration
87  void _establishVarOrder_();
88 
89  /// Establish for each node in both function graph if it has retrograde
90  /// variables
91  /// beneath it
92  void
93  _findRetrogradeVariables_(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* dg,
94  HashTable< NodeId, short int* >& dgInstNeed);
95 
96  /// The main recursion function
98 
99  /// One of the two function graphs used for the operation
101 
102  /// The other one
104 
105  /// The resulting function graph
107 
108  /// The set of variables we want to keep at the end
110 
111  /// The variable we work on to eleminate
113 
114  /// The function to be performed on the leaves
115  const GUM_SCALAR _neutral_;
116 
117  /// The total number of variable implied in the operation
119 
120  /// The functions to be performed on the leaves
121  const COMBINEOPERATOR< GUM_SCALAR > _combine_;
122  const PROJECTOPERATOR< GUM_SCALAR > _project_;
123 
124  /// The hashtable used to know if two pair of nodes have already been
125  /// visited
127 
128  /// Table uses to know if a given node of given function graph has
129  /// retrograde variables
132 
133  /// Just a computationnal trick
134  short int* _default_;
135  };
136 
137 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
138  extern template class Regress< double, std::multiplies, std::plus >;
139 #endif
140 
141 } // namespace gum
142 
143 #include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/regress_tpl.h>
144 
145 #endif // GUM_REGRESS_H
const Set< const DiscreteVariable *> * _primedVars_
The set of variables we want to keep at the end.
Definition: regress.h:109
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
const PROJECTOPERATOR< GUM_SCALAR > _project_
Definition: regress.h:122
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Definition: regress_tpl.h:98
NodeId _compute_(O4DGContext &currentSituation, Idx lastInstVarPos)
The main recursion function.
Definition: regress_tpl.h:310
HashTable< NodeId, short int *> _DG1InstantiationNeeded_
Table uses to know if a given node of given function graph has retrograde variables.
Definition: regress.h:130
Regress(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *vfunction, const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *probDist, const Set< const DiscreteVariable * > *primedVars, const DiscreteVariable *targetVar, const GUM_SCALAR neutral)
Default constructor.
Definition: regress_tpl.h:46
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _rd_
The resulting function graph.
Definition: regress.h:106
const COMBINEOPERATOR< GUM_SCALAR > _combine_
The functions to be performed on the leaves.
Definition: regress.h:121
HashTable< double, NodeId > _explorationTable_
The hashtable used to know if two pair of nodes have already been visited.
Definition: regress.h:126
short int * _default_
Just a computationnal trick.
Definition: regress.h:134
Class used to perform Function Graph Operations in the FMDP Framework.
Definition: regress.h:53
Idx _nbVar_
The total number of variable implied in the operation.
Definition: regress.h:118
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _DG1_
One of the two function graphs used for the operation.
Definition: regress.h:100
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _DG2_
The other one.
Definition: regress.h:103
void _findRetrogradeVariables_(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *dg, HashTable< NodeId, short int * > &dgInstNeed)
Establish for each node in both function graph if it has retrograde variables beneath it...
Definition: regress_tpl.h:218
const DiscreteVariable * _targetVar_
The variable we work on to eleminate.
Definition: regress.h:112
HashTable< NodeId, short int *> _DG2InstantiationNeeded_
Definition: regress.h:131
const GUM_SCALAR _neutral_
The function to be performed on the leaves.
Definition: regress.h:115
~Regress()
Default destructor.
Definition: regress_tpl.h:71
void _establishVarOrder_()
Computes an order for the final Decision graph that will minimize the number of re exploration...
Definition: regress_tpl.h:135