aGrUM  0.16.0
treeRegress_tpl.h
Go to the documentation of this file.
1 
34 
35 #define ALLOCATE(x) SmallObjectAllocator::instance().allocate(x)
36 #define DEALLOCATE(x, y) SmallObjectAllocator::instance().deallocate(x, y)
37 
38 namespace gum {
39 
40  template < typename GUM_SCALAR,
41  template < typename >
42  class COMBINEOPERATOR,
43  template < typename >
44  class PROJECTOPERATOR,
45  template < typename >
46  class TerminalNodePolicy >
50  const Bijection<
51  const DiscreteVariable*,
53  __vFunc(qAction),
54  __pxi(pxi) {
55  GUM_CONSTRUCTOR(TreeRegress);
56  }
57 
58  template < typename GUM_SCALAR,
59  template < typename >
60  class COMBINEOPERATOR,
61  template < typename >
62  class PROJECTOPERATOR,
63  template < typename >
64  class TerminalNodePolicy >
67  GUM_DESTRUCTOR(TreeRegress);
68  }
69 
70  // This function is the main function. To be call every time an operation
71  // between the two given Function Graphs is required
72  template < typename GUM_SCALAR,
73  template < typename >
74  class COMBINEOPERATOR,
75  template < typename >
76  class PROJECTOPERATOR,
77  template < typename >
78  class TerminalNodePolicy >
80  TreeRegress< GUM_SCALAR,
81  COMBINEOPERATOR,
82  PROJECTOPERATOR,
83  TerminalNodePolicy >::compute() {
85  if (__vFunc->isTerminalNode(__vFunc->root())) {
86  ret = MultiDimFunctionGraph< GUM_SCALAR,
87  TerminalNodePolicy >::getTreeInstance();
88  ret->copy(*__vFunc);
89  } else
90  ret = __xPloreVFunc(__vFunc->root());
91  return ret;
92  }
93 
94 
95  template < typename GUM_SCALAR,
96  template < typename >
97  class COMBINEOPERATOR,
98  template < typename >
99  class PROJECTOPERATOR,
100  template < typename >
101  class TerminalNodePolicy >
103  TreeRegress< GUM_SCALAR,
104  COMBINEOPERATOR,
105  PROJECTOPERATOR,
106  TerminalNodePolicy >::__xPloreVFunc(NodeId currentNodeId) {
107  const InternalNode* currentNode = __vFunc->node(currentNodeId);
108 
109  std::vector< MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* >
110  varbucket;
111 
112  for (Idx moda = 0; moda < currentNode->nodeVar()->domainSize(); ++moda) {
114  __context.insert(currentNode->nodeVar(), moda);
115  if (__vFunc->isTerminalNode(currentNode->son(moda))) {
116  GUM_SCALAR value = __vFunc->nodeValue(currentNode->son(moda));
117  if (value) {
118  vpxi = MultiDimFunctionGraph< GUM_SCALAR,
119  TerminalNodePolicy >::getTreeInstance();
120  vpxi->manager()->setRootNode(vpxi->manager()->addTerminalNode(value));
121  }
122  } else {
123  vpxi = __xPloreVFunc(currentNode->son(moda));
124  }
125 
126  if (vpxi != nullptr) {
128  vpxi, __pxi.second(currentNode->nodeVar()), __context);
129  varbucket.push_back(combinope.compute());
130  }
131  delete vpxi;
132  __context.erase(currentNode->nodeVar());
133  }
134 
135  if (varbucket.empty()) return nullptr;
136 
138  varbucket.pop_back();
139  while (!varbucket.empty()) {
141  TreeOperator< GUM_SCALAR, PROJECTOPERATOR > projope(vp, varbucket.back());
142  vp = projope.compute();
143  delete temp;
144  temp = varbucket.back();
145  varbucket.pop_back();
146  delete temp;
147  }
148 
149  return vp;
150  }
151 
152 } // namespace gum
Class used to perform Decision Tree Regression in the FMDP Framework.
Definition: treeRegress.h:55
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const DiscreteVariable * nodeVar() const
Returns the node variable.
NodeId son(Idx modality) const
Returns the son at a given index.
TreeRegress(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *qAction, const Bijection< const DiscreteVariable *, const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * > pxi)
Default constructor.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Base class for discrete random variable.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Class used to perform Decision Tree Operation in the FMDP Framework.
Definition: treeOperator.h:53
~TreeRegress()
Default destructor.
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __vFunc
The function graphs used for the operation.
Definition: treeRegress.h:90
virtual Size domainSize() const =0
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Structure used to represent a node internal structure.
Definition: internalNode.h:102
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
Class implementingting a function graph.
const Bijection< const DiscreteVariable *, const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *> __pxi
Definition: treeRegress.h:94
Size Idx
Type for indexes.
Definition: types.h:53
HashTable< const DiscreteVariable *, Idx > __context
Definition: treeRegress.h:95
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * __xPloreVFunc(NodeId currentNodeId)
The whatever 1.
Size NodeId
Type for node ids.
Definition: graphElements.h:98