aGrUM  0.14.2
gum::IMDDI< AttributeSelection, isScalar > Class Template Reference

#include <agrum/FMDP/planning/FunctionGraph/imddi.h>

+ Inheritance diagram for gum::IMDDI< AttributeSelection, isScalar >:
+ Collaboration diagram for gum::IMDDI< AttributeSelection, isScalar >:

Public Member Functions

void insertSetOfVars (MultiDimFunctionGraph< double > *ret) const
 
Size size ()
 
Constructor & destructor.
 IMDDI (MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
 Variable Learner constructor. More...
 
 IMDDI (MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe)
 Reward Learner constructor. More...
 
 ~IMDDI ()
 Default destructor. More...
 
Visit Methods
NodeId root () const
 
bool isTerminal (NodeId ni) const
 
const DiscreteVariablenodeVar (NodeId ni) const
 
NodeId nodeSon (NodeId ni, Idx modality) const
 
Idx nodeNbObservation (NodeId ni) const
 

Protected Attributes

MultiDimFunctionGraph< double > * _target
 The final diagram we're building. More...
 
Set< const DiscreteVariable *> _setOfVars
 
const DiscreteVariable_value
 
Sequence< ValueType_valueAssumed
 
bool _needUpdate
 
Model handling datastructures
NodeGraphPart _model
 The source of nodeId. More...
 
NodeId _root
 The root of the ordered tree. More...
 
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
 Gives for any node its associated variable. More...
 
HashTable< NodeId, NodeId *> _nodeSonsMap
 A table giving for any node a table mapping to its son idx is the modality of associated variable. More...
 
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> _var2Node
 Associates to any variable the list of all nodes associated to this variable. More...
 
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
 This hashtable binds every node to an associated NodeDatabase which handles every observation that concerns that node. More...
 
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
 This hashtable binds to every leaf an associated set of all hte observations compatible with it. More...
 

Incrementals methods

void addObservation (const Observation *)
 Adds a new observation to the structure. More...
 
void updateGraph ()
 Updates the tree after a new observation has been added. More...
 
void _updateNodeWithObservation (const Observation *newObs, NodeId currentNodeId)
 Adds a new observation to the structure. More...
 
NodeId _insertLeafNode (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *sonsMap)
 Adds a new observation to the structure. More...
 
void _chgNodeBoundVar (NodeId chgedNodeId, const DiscreteVariable *desiredVar)
 Adds a new observation to the structure. More...
 
void _removeNode (NodeId removedNodeId)
 Adds a new observation to the structure. More...
 
void __addLeaf (NodeId)
 Adds a new observation to the structure. More...
 
void __removeLeaf (NodeId)
 Adds a new observation to the structure. More...
 

Updating private methods

void updateFunctionGraph ()
 Computes the score of the given variables for the given node. More...
 
void __updateScore (const DiscreteVariable *, NodeId, VariableSelector &vs)
 Computes the score of the given variables for the given node. More...
 
void __downdateScore (const DiscreteVariable *, NodeId, VariableSelector &vs)
 Computes the score of the given variables for the given node. More...
 
void __updateNodeSet (Set< NodeId > &, const DiscreteVariable *, VariableSelector &)
 For each node in the given set, this methods checks whether or not we should installed the given variable as a test. If so, the node is updated. More...
 
void __rebuildFunctionGraph ()
 Computes the score of the given variables for the given node. More...
 
NodeId __insertLeafInFunctionGraph (AbstractLeaf *, Int2Type< true >)
 Computes the score of the given variables for the given node. More...
 
NodeId __insertLeafInFunctionGraph (AbstractLeaf *, Int2Type< false >)
 Computes the score of the given variables for the given node. More...
 

Graph Structure update methods

virtual void updateVar (const DiscreteVariable *)
 If a new modality appears to exists for given variable, call this method to turn every associated node to this variable into leaf. Graph has then indeed to be revised. More...
 
void _updateNode (NodeId nody, Set< const DiscreteVariable * > &bestVars)
 From the given sets of node, selects randomly one and installs it on given node. More...
 
virtual void _convertNode2Leaf (NodeId)
 Turns the given node into a leaf if not already so. More...
 
virtual void _transpose (NodeId, const DiscreteVariable *)
 Installs given variable to the given node, ensuring that the variable is not present in its subtree. More...
 
virtual NodeId _insertNode (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
 inserts a new node in internal graph More...
 
virtual NodeId _insertInternalNode (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
 inserts a new internal node in internal graph More...
 

Detailed Description

template<TESTNAME AttributeSelection, bool isScalar = false>
class gum::IMDDI< AttributeSelection, isScalar >

Definition at line 55 of file imddi.h.

Constructor & Destructor Documentation

◆ IMDDI() [1/2]

template<TESTNAME AttributeSelection, bool isScalar>
gum::IMDDI< AttributeSelection, isScalar >::IMDDI ( MultiDimFunctionGraph< double > *  target,
double  attributeSelectionThreshold,
double  pairSelectionThreshold,
Set< const DiscreteVariable * >  attributeListe,
const DiscreteVariable learnedValue 
)

Variable Learner constructor.

Definition at line 48 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__addLeaf(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root.

53  :
54  IncrementalGraphLearner< AttributeSelection, isScalar >(
55  target, attributeListe, learnedValue),
56  __lg(&(this->_model), pairSelectionThreshold), __nbTotalObservation(0),
57  __attributeSelectionThreshold(attributeSelectionThreshold) {
58  GUM_CONSTRUCTOR(IMDDI);
59  __addLeaf(this->_root);
60  }
LeafAggregator __lg
Definition: imddi.h:167
void __addLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:287
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition: imddi_tpl.h:48
NodeId _root
The root of the ordered tree.
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: imddi.h:175
NodeGraphPart _model
The source of nodeId.
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: imddi.h:172
+ Here is the call graph for this function:

◆ IMDDI() [2/2]

template<TESTNAME AttributeSelection, bool isScalar>
gum::IMDDI< AttributeSelection, isScalar >::IMDDI ( MultiDimFunctionGraph< double > *  target,
double  attributeSelectionThreshold,
double  pairSelectionThreshold,
Set< const DiscreteVariable * >  attributeListe 
)

Reward Learner constructor.

Definition at line 66 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__addLeaf(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root.

70  :
71  IncrementalGraphLearner< AttributeSelection, isScalar >(
72  target, attributeListe, new LabelizedVariable("Reward", "", 2)),
73  __lg(&(this->_model), pairSelectionThreshold), __nbTotalObservation(0),
74  __attributeSelectionThreshold(attributeSelectionThreshold) {
75  GUM_CONSTRUCTOR(IMDDI);
76  __addLeaf(this->_root);
77  }
LeafAggregator __lg
Definition: imddi.h:167
void __addLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:287
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition: imddi_tpl.h:48
NodeId _root
The root of the ordered tree.
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: imddi.h:175
NodeGraphPart _model
The source of nodeId.
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: imddi.h:172
+ Here is the call graph for this function:

◆ ~IMDDI()

template<TESTNAME AttributeSelection, bool isScalar>
gum::IMDDI< AttributeSelection, isScalar >::~IMDDI ( )

Default destructor.

Definition at line 83 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__leafMap.

83  {
84  GUM_DESTRUCTOR(IMDDI);
85  for (HashTableIteratorSafe< NodeId, AbstractLeaf* > leafIter =
86  __leafMap.beginSafe();
87  leafIter != __leafMap.endSafe();
88  ++leafIter)
89  delete leafIter.val();
90  }
HashTable< NodeId, AbstractLeaf *> __leafMap
Definition: imddi.h:169
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition: imddi_tpl.h:48

Member Function Documentation

◆ __addLeaf()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::__addLeaf ( NodeId  currentNodeId)
private

Adds a new observation to the structure.

Definition at line 287 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__leafMap, gum::IMDDI< AttributeSelection, isScalar >::__lg, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_valueAssumed, and gum::LeafAggregator::addLeaf().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::IMDDI< AttributeSelection, isScalar >::_insertLeafNode(), and gum::IMDDI< AttributeSelection, isScalar >::IMDDI().

287  {
288  __leafMap.insert(currentNodeId,
289  new ConcreteLeaf< AttributeSelection, isScalar >(
290  currentNodeId,
291  this->_nodeId2Database[currentNodeId],
292  &(this->_valueAssumed)));
293  __lg.addLeaf(__leafMap[currentNodeId]);
294  }
LeafAggregator __lg
Definition: imddi.h:167
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
HashTable< NodeId, AbstractLeaf *> __leafMap
Definition: imddi.h:169
void addLeaf(AbstractLeaf *)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __downdateScore()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::__downdateScore ( const DiscreteVariable var,
NodeId  nody,
VariableSelector vs 
)
private

Computes the score of the given variables for the given node.

Definition at line 180 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__nbTotalObservation, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, and gum::VariableSelector::downdateScore().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet().

181  {
182  if (!this->_nodeId2Database[nody]->isTestRelevant(var)) return;
183  double weight = (double)this->_nodeId2Database[nody]->nbObservation()
184  / (double)this->__nbTotalObservation;
185  vs.downdateScore(var,
186  weight * this->_nodeId2Database[nody]->testValue(var),
187  weight
188  * this->_nodeId2Database[nody]->testOtherCriterion(var));
189  }
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: imddi.h:172
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __insertLeafInFunctionGraph() [1/2]

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::IMDDI< AttributeSelection, isScalar >::__insertLeafInFunctionGraph ( AbstractLeaf leaf,
Int2Type< true >   
)
private

Computes the score of the given variables for the given node.

Definition at line 388 of file imddi_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_target, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_valueAssumed, gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addTerminalNode(), gum::AbstractLeaf::effectif(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::manager(), gum::AbstractLeaf::nbModa(), and gum::AbstractLeaf::total().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::__rebuildFunctionGraph().

389  {
390  double value = 0.0;
391  for (Idx moda = 0; moda < leaf->nbModa(); moda++) {
392  value += (double)leaf->effectif(moda) * this->_valueAssumed.atPos(moda);
393  }
394  if (leaf->total()) value /= (double)leaf->total();
395  return this->_target->manager()->addTerminalNode(value);
396  }
MultiDimFunctionGraph< double > * _target
The final diagram we&#39;re building.
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __insertLeafInFunctionGraph() [2/2]

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::IMDDI< AttributeSelection, isScalar >::__insertLeafInFunctionGraph ( AbstractLeaf leaf,
Int2Type< false >   
)
private

Computes the score of the given variables for the given node.

Definition at line 403 of file imddi_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_target, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode(), gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addTerminalNode(), gum::DiscreteVariable::domainSize(), gum::AbstractLeaf::effectif(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::manager(), SOA_ALLOCATE, and gum::AbstractLeaf::total().

404  {
405  NodeId* sonsMap = static_cast< NodeId* >(
406  SOA_ALLOCATE(sizeof(NodeId) * this->_value->domainSize()));
407  for (Idx modality = 0; modality < this->_value->domainSize(); ++modality) {
408  double newVal = 0.0;
409  if (leaf->total())
410  newVal = (double)leaf->effectif(modality) / (double)leaf->total();
411  sonsMap[modality] = this->_target->manager()->addTerminalNode(newVal);
412  }
413  return this->_target->manager()->addInternalNode(this->_value, sonsMap);
414  }
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
MultiDimFunctionGraph< double > * _target
The final diagram we&#39;re building.
virtual Size domainSize() const =0
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define SOA_ALLOCATE(x)
+ Here is the call graph for this function:

◆ __rebuildFunctionGraph()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::__rebuildFunctionGraph ( )
private

Computes the score of the given variables for the given node.

Definition at line 325 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__insertLeafInFunctionGraph(), gum::IMDDI< AttributeSelection, isScalar >::__lg, gum::IMDDI< AttributeSelection, isScalar >::__varOrder, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_target, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_var2Node, gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::add(), gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode(), gum::HashTable< Key, Val, Alloc >::cbeginSafe(), gum::HashTable< Key, Val, Alloc >::cendSafe(), gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::clean(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::clear(), gum::HashTable< Key, Val, Alloc >::exists(), gum::HashTable< Key, Val, Alloc >::insert(), gum::LeafAggregator::leavesMap(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::manager(), gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::setRootNode(), SOA_ALLOCATE, and gum::LeafAggregator::update().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::updateFunctionGraph().

325  {
326  // *******************************************************************************************************
327  // Mise à jour de l'aggregateur de feuille
328  __lg.update();
329 
330  // *******************************************************************************************************
331  // Reinitialisation du Graphe de Décision
332  this->_target->clear();
333  for (auto varIter = __varOrder.beginSafe(); varIter != __varOrder.endSafe();
334  ++varIter)
335  this->_target->add(**varIter);
336  this->_target->add(*this->_value);
337 
339 
340  // *******************************************************************************************************
341  // Insertion des feuilles
342  HashTable< NodeId, AbstractLeaf* > treeNode2leaf = __lg.leavesMap();
343  HashTable< AbstractLeaf*, NodeId > leaf2DGNode;
344  for (HashTableConstIteratorSafe< NodeId, AbstractLeaf* > treeNodeIter =
345  treeNode2leaf.cbeginSafe();
346  treeNodeIter != treeNode2leaf.cendSafe();
347  ++treeNodeIter) {
348  if (!leaf2DGNode.exists(treeNodeIter.val()))
349  leaf2DGNode.insert(treeNodeIter.val(),
350  __insertLeafInFunctionGraph(treeNodeIter.val(),
351  Int2Type< isScalar >()));
352 
353  toTarget.insert(treeNodeIter.key(), leaf2DGNode[treeNodeIter.val()]);
354  }
355 
356  // *******************************************************************************************************
357  // Insertion des noeuds internes (avec vérification des possibilités de
358  // fusion)
359  for (SequenceIteratorSafe< const DiscreteVariable* > varIter =
360  __varOrder.rbeginSafe();
361  varIter != __varOrder.rendSafe();
362  --varIter) {
363  for (Link< NodeId >* curNodeIter = this->_var2Node[*varIter]->list();
364  curNodeIter;
365  curNodeIter = curNodeIter->nextLink()) {
366  NodeId* sonsMap = static_cast< NodeId* >(
367  SOA_ALLOCATE(sizeof(NodeId) * (*varIter)->domainSize()));
368  for (Idx modality = 0; modality < (*varIter)->domainSize(); ++modality)
369  sonsMap[modality] =
370  toTarget[this->_nodeSonsMap[curNodeIter->element()][modality]];
371  toTarget.insert(
372  curNodeIter->element(),
373  this->_target->manager()->addInternalNode(*varIter, sonsMap));
374  }
375  }
376 
377  // *******************************************************************************************************
378  // Polish
379  this->_target->manager()->setRootNode(toTarget[this->_root]);
380  this->_target->manager()->clean();
381  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
LeafAggregator __lg
Definition: imddi.h:167
NodeId __insertLeafInFunctionGraph(AbstractLeaf *, Int2Type< true >)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:388
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> _var2Node
Associates to any variable the list of all nodes associated to this variable.
void clean()
Removes var without nodes in the diagram.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
MultiDimFunctionGraph< double > * _target
The final diagram we&#39;re building.
Sequence< const DiscreteVariable *> __varOrder
Definition: imddi.h:165
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
HashTable< NodeId, AbstractLeaf *> leavesMap()
NodeId _root
The root of the ordered tree.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void clear()
Clears the function graph.
#define SOA_ALLOCATE(x)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __removeLeaf()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::__removeLeaf ( NodeId  currentNodeId)
private

Adds a new observation to the structure.

Definition at line 301 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__leafMap, gum::IMDDI< AttributeSelection, isScalar >::__lg, and gum::LeafAggregator::removeLeaf().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_chgNodeBoundVar(), and gum::IMDDI< AttributeSelection, isScalar >::_removeNode().

301  {
302  __lg.removeLeaf(__leafMap[currentNodeId]);
303  delete __leafMap[currentNodeId];
304  __leafMap.erase(currentNodeId);
305  }
LeafAggregator __lg
Definition: imddi.h:167
HashTable< NodeId, AbstractLeaf *> __leafMap
Definition: imddi.h:169
void removeLeaf(AbstractLeaf *)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __updateNodeSet()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet ( Set< NodeId > &  nodeSet,
const DiscreteVariable selectedVar,
VariableSelector vs 
)
private

For each node in the given set, this methods checks whether or not we should installed the given variable as a test. If so, the node is updated.

Definition at line 198 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__attributeSelectionThreshold, gum::IMDDI< AttributeSelection, isScalar >::__downdateScore(), gum::IMDDI< AttributeSelection, isScalar >::__updateScore(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), gum::VariableSelector::begin(), gum::Set< Key, Alloc >::beginSafe(), gum::Set< Key, Alloc >::clear(), gum::VariableSelector::current(), gum::Set< Key, Alloc >::endSafe(), gum::VariableSelector::hasNext(), and gum::VariableSelector::next().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::updateGraph().

201  {
202  Set< NodeId > oldNodeSet(nodeSet);
203  nodeSet.clear();
204  for (SetIteratorSafe< NodeId > nodeIter = oldNodeSet.beginSafe();
205  nodeIter != oldNodeSet.endSafe();
206  ++nodeIter) {
207  if (this->_nodeId2Database[*nodeIter]->isTestRelevant(selectedVar)
208  && this->_nodeId2Database[*nodeIter]->testValue(selectedVar)
210  this->_transpose(*nodeIter, selectedVar);
211 
212  // Then we subtract the from the score given to each variables the
213  // quantity given by this node
214  for (vs.begin(); vs.hasNext(); vs.next()) {
215  __downdateScore(vs.current(), *nodeIter, vs);
216  }
217 
218  // And finally we add all its child to the new set of nodes
219  // and updates the remaining var's score
220  for (Idx modality = 0;
221  modality < this->_nodeVarMap[*nodeIter]->domainSize();
222  ++modality) {
223  NodeId sonId = this->_nodeSonsMap[*nodeIter][modality];
224  nodeSet << sonId;
225 
226  for (vs.begin(); vs.hasNext(); vs.next()) {
227  __updateScore(vs.current(), sonId, vs);
228  }
229  }
230  } else {
231  nodeSet << *nodeIter;
232  }
233  }
234  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
void __updateScore(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:169
virtual void _transpose(NodeId, const DiscreteVariable *)
Installs given variable to the given node, ensuring that the variable is not present in its subtree...
void __downdateScore(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:180
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: imddi.h:175
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:372
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __updateScore()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::__updateScore ( const DiscreteVariable var,
NodeId  nody,
VariableSelector vs 
)
private

Computes the score of the given variables for the given node.

Definition at line 169 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__nbTotalObservation, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, and gum::VariableSelector::updateScore().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet(), and gum::IMDDI< AttributeSelection, isScalar >::updateGraph().

170  {
171  if (!this->_nodeId2Database[nody]->isTestRelevant(var)) return;
172  double weight = (double)this->_nodeId2Database[nody]->nbObservation()
173  / (double)this->__nbTotalObservation;
174  vs.updateScore(var,
175  weight * this->_nodeId2Database[nody]->testValue(var),
176  weight * this->_nodeId2Database[nody]->testOtherCriterion(var));
177  }
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: imddi.h:172
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _chgNodeBoundVar()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::_chgNodeBoundVar ( NodeId  chgedNodeId,
const DiscreteVariable desiredVar 
)
protectedvirtual

Adds a new observation to the structure.

Reimplemented from gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 259 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__addLeaf(), gum::IMDDI< AttributeSelection, isScalar >::__removeLeaf(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value.

260  {
261  if (this->_nodeVarMap[currentNodeId] == this->_value)
262  __removeLeaf(currentNodeId);
263 
265  currentNodeId, desiredVar);
266 
267  if (desiredVar == this->_value) __addLeaf(currentNodeId);
268  }
void __removeLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:301
void __addLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:287
virtual void _chgNodeBoundVar(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Changes the associated variable of a node.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
+ Here is the call graph for this function:

◆ _convertNode2Leaf()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_convertNode2Leaf ( NodeId  currentNodeId)
protectedvirtualinherited

Turns the given node into a leaf if not already so.

Definition at line 208 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_leafDatabase, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_removeNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::HashTable< Key, Val, Alloc >::erase(), and SOA_DEALLOCATE.

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation(), gum::IMDDI< AttributeSelection, isScalar >::updateGraph(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateVar().

209  {
210  if (_nodeVarMap[currentNodeId] != _value) {
211  _leafDatabase.insert(currentNodeId, new Set< const Observation* >());
212 
213  // Resolving potential sons issue
214  for (Idx modality = 0; modality < _nodeVarMap[currentNodeId]->domainSize();
215  ++modality) {
216  NodeId sonId = _nodeSonsMap[currentNodeId][modality];
217  _convertNode2Leaf(sonId);
218  (*_leafDatabase[currentNodeId]) =
219  (*_leafDatabase[currentNodeId]) + *(_leafDatabase[sonId]);
220  _removeNode(sonId);
221  }
222 
223  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
224  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
225  _nodeSonsMap.erase(currentNodeId);
226 
227  _chgNodeBoundVar(currentNodeId, _value);
228  }
229  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
void erase(const Key &key)
Removes a given element from the hash table.
#define SOA_DEALLOCATE(x, y)
virtual void _convertNode2Leaf(NodeId)
Turns the given node into a leaf if not already so.
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
virtual void _removeNode(NodeId removedNodeId)
Removes a node from the internal graph.
virtual void _chgNodeBoundVar(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Changes the associated variable of a node.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _insertInternalNode()

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertInternalNode ( NodeDatabase< AttributeSelection, isScalar > *  nDB,
const DiscreteVariable boundVar,
NodeId sonsMap 
)
protectedvirtualinherited

inserts a new internal node in internal graph

Parameters
nDB: the associated database
boundVar: the associated variable
sonsMap: a table giving node's sons node
Returns
the newly created node's id

Definition at line 380 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, and gum::HashTable< Key, Val, Alloc >::insert().

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

383  {
384  NodeId newNodeId = this->_insertNode(nDB, boundVar);
385  _nodeSonsMap.insert(newNodeId, sonsMap);
386  return newNodeId;
387  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
virtual NodeId _insertNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
inserts a new node in internal graph
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _insertLeafNode()

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::IMDDI< AttributeSelection, isScalar >::_insertLeafNode ( NodeDatabase< AttributeSelection, isScalar > *  nDB,
const DiscreteVariable boundVar,
Set< const Observation * > *  sonsMap 
)
protectedvirtual

Adds a new observation to the structure.

Reimplemented from gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 241 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__addLeaf(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertLeafNode().

244  {
245  NodeId currentNodeId =
247  nDB, boundVar, obsSet);
248 
249  __addLeaf(currentNodeId);
250 
251  return currentNodeId;
252  }
virtual NodeId _insertLeafNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
inserts a new leaf node in internal graohs
void __addLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:287
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ _insertNode()

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertNode ( NodeDatabase< AttributeSelection, isScalar > *  nDB,
const DiscreteVariable boundVar 
)
protectedvirtualinherited

inserts a new node in internal graph

Parameters
nDB: the associated database
boundVar: the associated variable
Returns
the newly created node's id

Reimplemented in gum::ITI< AttributeSelection, isScalar >.

Definition at line 355 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_model, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_needUpdate, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_var2Node, and gum::NodeGraphPart::addNode().

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertInternalNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertLeafNode(), gum::ITI< AttributeSelection, isScalar >::_insertNode(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

357  {
358  NodeId newNodeId = _model.addNode();
359  _nodeVarMap.insert(newNodeId, boundVar);
360  _nodeId2Database.insert(newNodeId, nDB);
361  _var2Node[boundVar]->addLink(newNodeId);
362 
363  _needUpdate = true;
364 
365  return newNodeId;
366  }
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> _var2Node
Associates to any variable the list of all nodes associated to this variable.
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
virtual NodeId addNode()
insert a new node and return its id
NodeGraphPart _model
The source of nodeId.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _removeNode()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::_removeNode ( NodeId  removedNodeId)
protectedvirtual

Adds a new observation to the structure.

Reimplemented from gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 275 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__removeLeaf(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_removeNode(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value.

275  {
276  if (this->_nodeVarMap[currentNodeId] == this->_value)
277  __removeLeaf(currentNodeId);
279  currentNodeId);
280  }
void __removeLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:301
virtual void _removeNode(NodeId removedNodeId)
Removes a node from the internal graph.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
+ Here is the call graph for this function:

◆ _transpose()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose ( NodeId  currentNodeId,
const DiscreteVariable desiredVar 
)
protectedvirtualinherited

Installs given variable to the given node, ensuring that the variable is not present in its subtree.

Definition at line 237 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::__branchObs(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertInternalNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertLeafNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_leafDatabase, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_removeNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_setOfVars, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::NodeDatabase< AttributeSelection, isScalar >::addObservation(), gum::DiscreteVariable::domainSize(), gum::Set< Key, Alloc >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), SOA_ALLOCATE, and SOA_DEALLOCATE.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

238  {
239  // **************************************************************************************
240  // Si le noeud courant contient déjà la variable qu'on souhaite lui amener
241  // Il n'y a rien à faire
242  if (_nodeVarMap[currentNodeId] == desiredVar) { return; }
243 
244  // **************************************************************************************
245  // Si le noeud courant est terminal,
246  // Il faut artificiellement insérer un noeud liant à la variable
247  if (_nodeVarMap[currentNodeId] == _value) {
248  // We turned this leaf into an internal node.
249  // This mean that we'll need to install children leaves for each value of
250  // desiredVar
251 
252  // First We must prepare these new leaves NodeDatabases and Sets<const
253  // Observation*>
254  NodeDatabase< AttributeSelection, isScalar >** dbMap =
255  static_cast< NodeDatabase< AttributeSelection, isScalar >** >(
256  SOA_ALLOCATE(sizeof(NodeDatabase< AttributeSelection, isScalar >*)
257  * desiredVar->domainSize()));
258  Set< const Observation* >** obsetMap =
259  static_cast< Set< const Observation* >** >(SOA_ALLOCATE(
260  sizeof(Set< const Observation* >*) * desiredVar->domainSize()));
261  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality) {
262  dbMap[modality] =
263  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value);
264  obsetMap[modality] = new Set< const Observation* >();
265  }
266  for (SetIteratorSafe< const Observation* > obsIter =
267  _leafDatabase[currentNodeId]->beginSafe();
268  _leafDatabase[currentNodeId]->endSafe() != obsIter;
269  ++obsIter) {
270  dbMap[__branchObs(*obsIter, desiredVar)]->addObservation(*obsIter);
271  obsetMap[__branchObs(*obsIter, desiredVar)]->insert(*obsIter);
272  }
273 
274  // Then we can install each new leaves (and put in place the sonsMap)
275  NodeId* sonsMap = static_cast< NodeId* >(
276  SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
277  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality)
278  sonsMap[modality] =
279  _insertLeafNode(dbMap[modality], _value, obsetMap[modality]);
280 
281  // Some necessary clean up
282  SOA_DEALLOCATE(dbMap,
283  sizeof(NodeDatabase< AttributeSelection, isScalar >*)
284  * desiredVar->domainSize());
286  obsetMap, sizeof(Set< const Observation* >*) * desiredVar->domainSize());
287 
288  // And finally we can turn the node into an internal node associated to
289  // desiredVar
290  _chgNodeBoundVar(currentNodeId, desiredVar);
291  _nodeSonsMap.insert(currentNodeId, sonsMap);
292 
293  return;
294  }
295 
296  // *************************************************************************************
297  // Remains the general case where currentNodeId is an internal node.
298 
299  // First we ensure that children node use desiredVar as variable
300  for (Idx modality = 0; modality < _nodeVarMap[currentNodeId]->domainSize();
301  ++modality)
302  _transpose(_nodeSonsMap[currentNodeId][modality], desiredVar);
303 
304  // Sequence<NodeDatabase<AttributeSelection, isScalar>*>
305  // sonsNodeDatabase =
306  // _nodeId2Database[currentNodeId]->splitOnVar(desiredVar);
307  NodeId* sonsMap = static_cast< NodeId* >(
308  SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
309 
310  // Then we create the new mapping
311  for (Idx desiredVarModality = 0; desiredVarModality < desiredVar->domainSize();
312  ++desiredVarModality) {
313  NodeId* grandSonsMap = static_cast< NodeId* >(
314  SOA_ALLOCATE(sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize()));
315  NodeDatabase< AttributeSelection, isScalar >* sonDB =
316  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value);
317  for (Idx currentVarModality = 0;
318  currentVarModality < _nodeVarMap[currentNodeId]->domainSize();
319  ++currentVarModality) {
320  grandSonsMap[currentVarModality] =
321  _nodeSonsMap[_nodeSonsMap[currentNodeId][currentVarModality]]
322  [desiredVarModality];
323  sonDB->operator+=((*_nodeId2Database[grandSonsMap[currentVarModality]]));
324  }
325 
326  sonsMap[desiredVarModality] =
327  _insertInternalNode(sonDB, _nodeVarMap[currentNodeId], grandSonsMap);
328  }
329 
330  // Finally we clean the old remaining nodes
331  for (Idx currentVarModality = 0;
332  currentVarModality < _nodeVarMap[currentNodeId]->domainSize();
333  ++currentVarModality) {
334  _removeNode(_nodeSonsMap[currentNodeId][currentVarModality]);
335  }
336 
337  // We suppress the old sons map and remap to the new one
338  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
339  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
340  _nodeSonsMap[currentNodeId] = sonsMap;
341 
342  _chgNodeBoundVar(currentNodeId, desiredVar);
343  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
Set< const DiscreteVariable *> _setOfVars
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
virtual NodeId _insertInternalNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
inserts a new internal node in internal graph
Idx __branchObs(const Observation *obs, const DiscreteVariable *var)
Seek modality assumed in obs for given var.
#define SOA_DEALLOCATE(x, y)
virtual NodeId _insertLeafNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
inserts a new leaf node in internal graohs
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
virtual void _transpose(NodeId, const DiscreteVariable *)
Installs given variable to the given node, ensuring that the variable is not present in its subtree...
virtual void _removeNode(NodeId removedNodeId)
Removes a node from the internal graph.
virtual void _chgNodeBoundVar(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Changes the associated variable of a node.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define SOA_ALLOCATE(x)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _updateNode()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode ( NodeId  updatedNode,
Set< const DiscreteVariable * > &  varsOfInterest 
)
protectedinherited

From the given sets of node, selects randomly one and installs it on given node.

Chechks of course if node's current variable is not in that set first.

Parameters
nody: the node we update
bestVars: the set of interessting vars to be installed here

Chechks of course if node's current variable is not in that set first.

Parameters
nody: the node we update
bestVar: the set of interessting vars to be installed here

Definition at line 177 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_convertNode2Leaf(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), gum::Set< Key, Alloc >::cbeginSafe(), gum::Set< Key, Alloc >::cendSafe(), gum::Set< Key, Alloc >::empty(), gum::Set< Key, Alloc >::exists(), and gum::Set< Key, Alloc >::size().

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().

178  {
179  // If this node has no interesting variable, we turn it into a leaf
180  if (varsOfInterest.empty()) {
181  _convertNode2Leaf(updatedNode);
182  return;
183  }
184 
185  // If this node has already one of the best variable intalled as test, we
186  // move on
187  if (_nodeVarMap.exists(updatedNode)
188  && varsOfInterest.exists(_nodeVarMap[updatedNode])) {
189  return;
190  }
191 
192  // In any other case we have to install variable as best test
193  Idx randy = (Idx)(std::rand() / RAND_MAX) * varsOfInterest.size(), basc = 0;
194  SetConstIteratorSafe< const DiscreteVariable* > varIter;
195  for (varIter = varsOfInterest.cbeginSafe(), basc = 0;
196  varIter != varsOfInterest.cendSafe() && basc < randy;
197  ++varIter, basc++)
198  ;
199 
200  _transpose(updatedNode, *varIter);
201  }
virtual void _convertNode2Leaf(NodeId)
Turns the given node into a leaf if not already so.
virtual void _transpose(NodeId, const DiscreteVariable *)
Installs given variable to the given node, ensuring that the variable is not present in its subtree...
Size Idx
Type for indexes.
Definition: types.h:50
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _updateNodeWithObservation()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::_updateNodeWithObservation ( const Observation newObs,
NodeId  currentNodeId 
)
protectedvirtual

Adds a new observation to the structure.

Reimplemented from gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 105 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__leafMap, gum::IMDDI< AttributeSelection, isScalar >::__lg, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, and gum::LeafAggregator::updateLeaf().

106  {
107  IncrementalGraphLearner< AttributeSelection,
108  isScalar >::_updateNodeWithObservation(newObs,
109  currentNodeId);
110  if (this->_nodeVarMap[currentNodeId] == this->_value)
111  __lg.updateLeaf(__leafMap[currentNodeId]);
112  }
LeafAggregator __lg
Definition: imddi.h:167
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, Set< const DiscreteVariable * > attributesSet, const DiscreteVariable *learnVariable)
Default constructor.
void _updateNodeWithObservation(const Observation *newObs, NodeId currentNodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:105
HashTable< NodeId, AbstractLeaf *> __leafMap
Definition: imddi.h:169
bool updateLeaf(AbstractLeaf *)
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
+ Here is the call graph for this function:

◆ addObservation()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::addObservation ( const Observation obs)
virtual

Adds a new observation to the structure.

Reimplemented from gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 98 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__nbTotalObservation, and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::addObservation().

99  {
102  }
virtual void addObservation(const Observation *obs)
Inserts a new observation.
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: imddi.h:172
+ Here is the call graph for this function:

◆ insertSetOfVars()

template<TESTNAME AttributeSelection, bool isScalar = false>
void gum::IMDDI< AttributeSelection, isScalar >::insertSetOfVars ( MultiDimFunctionGraph< double > *  ret) const
inlinevirtual

Reimplemented from gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 156 of file imddi.h.

References gum::IMDDI< AttributeSelection, isScalar >::__varOrder, and gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::add().

156  {
157  for (SequenceIteratorSafe< const DiscreteVariable* > varIter =
158  __varOrder.beginSafe();
159  varIter != __varOrder.endSafe();
160  ++varIter)
161  ret->add(**varIter);
162  }
Sequence< const DiscreteVariable *> __varOrder
Definition: imddi.h:165
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
+ Here is the call graph for this function:

◆ isTerminal()

template<TESTNAME AttributeSelection, bool isScalar = false>
bool gum::IncrementalGraphLearner< AttributeSelection, isScalar >::isTerminal ( NodeId  ni) const
inlinevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 315 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, and gum::HashTable< Key, Val, Alloc >::exists().

315 { return !this->_nodeSonsMap.exists(ni); }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
+ Here is the call graph for this function:

◆ nodeNbObservation()

template<TESTNAME AttributeSelection, bool isScalar = false>
Idx gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeNbObservation ( NodeId  ni) const
inlinevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 334 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database.

334  {
335  return this->_nodeId2Database[ni]->nbObservation();
336  }
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...

◆ nodeSon()

template<TESTNAME AttributeSelection, bool isScalar = false>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeSon ( NodeId  ni,
Idx  modality 
) const
inlinevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 327 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap.

327  {
328  return this->_nodeSonsMap[ni][modality];
329  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...

◆ nodeVar()

template<TESTNAME AttributeSelection, bool isScalar = false>
const DiscreteVariable* gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeVar ( NodeId  ni) const
inlinevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 320 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap.

320  {
321  return this->_nodeVarMap[ni];
322  }
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.

◆ root()

template<TESTNAME AttributeSelection, bool isScalar = false>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::root ( ) const
inlinevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 310 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root.

310 { return this->_root; }
NodeId _root
The root of the ordered tree.

◆ size()

template<TESTNAME AttributeSelection, bool isScalar = false>
Size gum::IncrementalGraphLearner< AttributeSelection, isScalar >::size ( )
inlineinherited

Definition at line 299 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap.

299 { return _nodeVarMap.size(); }
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.

◆ updateFunctionGraph()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::updateFunctionGraph ( )
virtual

Computes the score of the given variables for the given node.

Implements gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 313 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__rebuildFunctionGraph(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_needUpdate.

313  {
314  // if( __lg.needsUpdate() || this->_needUpdate ){
316  this->_needUpdate = false;
317  // }
318  }
void __rebuildFunctionGraph()
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:325
+ Here is the call graph for this function:

◆ updateGraph()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::updateGraph ( )
virtual

Updates the tree after a new observation has been added.

Implements gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 119 of file imddi_tpl.h.

References gum::IMDDI< AttributeSelection, isScalar >::__lg, gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet(), gum::IMDDI< AttributeSelection, isScalar >::__updateScore(), gum::IMDDI< AttributeSelection, isScalar >::__varOrder, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_convertNode2Leaf(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_setOfVars, gum::VariableSelector::begin(), gum::Set< Key, Alloc >::beginSafe(), gum::VariableSelector::current(), gum::Set< Key, Alloc >::endSafe(), gum::VariableSelector::hasNext(), gum::Set< Key, Alloc >::insert(), gum::VariableSelector::isEmpty(), gum::LeafAggregator::needsUpdate(), gum::VariableSelector::next(), gum::VariableSelector::select(), and gum::LeafAggregator::update().

119  {
120  __varOrder.clear();
121 
122  // First xe initialize the node set which will give us the scores
123  Set< NodeId > currentNodeSet;
124  currentNodeSet.insert(this->_root);
125 
126  // Then we initialize the pool of variables to consider
127  VariableSelector vs(this->_setOfVars);
128  for (vs.begin(); vs.hasNext(); vs.next()) {
129  __updateScore(vs.current(), this->_root, vs);
130  }
131 
132  // Then, until there's no node remaining
133  while (!vs.isEmpty()) {
134  // We select the best var
135  const DiscreteVariable* selectedVar = vs.select();
136  __varOrder.insert(selectedVar);
137 
138  // Then we decide if we update each node according to this var
139  __updateNodeSet(currentNodeSet, selectedVar, vs);
140  }
141 
142  // If there are remaining node that are not leaves after we establish the
143  // var order
144  // these nodes are turned into leaf.
145  for (SetIteratorSafe< NodeId > nodeIter = currentNodeSet.beginSafe();
146  nodeIter != currentNodeSet.endSafe();
147  ++nodeIter)
148  this->_convertNode2Leaf(*nodeIter);
149 
150 
151  if (__lg.needsUpdate()) __lg.update();
152  }
LeafAggregator __lg
Definition: imddi.h:167
Set< const DiscreteVariable *> _setOfVars
void __updateScore(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:169
virtual void _convertNode2Leaf(NodeId)
Turns the given node into a leaf if not already so.
Sequence< const DiscreteVariable *> __varOrder
Definition: imddi.h:165
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Definition: set_tpl.h:499
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
Definition: set_tpl.h:485
NodeId _root
The root of the ordered tree.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
void __updateNodeSet(Set< NodeId > &, const DiscreteVariable *, VariableSelector &)
For each node in the given set, this methods checks whether or not we should installed the given vari...
Definition: imddi_tpl.h:198
+ Here is the call graph for this function:

◆ updateVar()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateVar ( const DiscreteVariable var)
virtualinherited

If a new modality appears to exists for given variable, call this method to turn every associated node to this variable into leaf. Graph has then indeed to be revised.

Definition at line 155 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_convertNode2Leaf(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_var2Node, gum::Link< T >::element(), and gum::Link< T >::nextLink().

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

156  {
157  Link< NodeId >* nodIter = _var2Node[var]->list();
158  Link< NodeId >* nni = nullptr;
159  while (nodIter) {
160  nni = nodIter->nextLink();
161  _convertNode2Leaf(nodIter->element());
162  nodIter = nni;
163  }
164  }
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> _var2Node
Associates to any variable the list of all nodes associated to this variable.
virtual void _convertNode2Leaf(NodeId)
Turns the given node into a leaf if not already so.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ __attributeSelectionThreshold

template<TESTNAME AttributeSelection, bool isScalar = false>
double gum::IMDDI< AttributeSelection, isScalar >::__attributeSelectionThreshold
private

The threshold above which we consider variables to be dependant.

Definition at line 175 of file imddi.h.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet().

◆ __leafMap

◆ __lg

◆ __nbTotalObservation

template<TESTNAME AttributeSelection, bool isScalar = false>
Idx gum::IMDDI< AttributeSelection, isScalar >::__nbTotalObservation
private

◆ __varOrder

template<TESTNAME AttributeSelection, bool isScalar = false>
Sequence< const DiscreteVariable* > gum::IMDDI< AttributeSelection, isScalar >::__varOrder
private

◆ _leafDatabase

◆ _model

◆ _needUpdate

◆ _nodeId2Database

◆ _nodeSonsMap

◆ _nodeVarMap

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, const DiscreteVariable* > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap
protectedinherited

◆ _root

◆ _setOfVars

◆ _target

◆ _value

◆ _valueAssumed

template<TESTNAME AttributeSelection, bool isScalar = false>
Sequence< ValueType > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_valueAssumed
protectedinherited

◆ _var2Node


The documentation for this class was generated from the following files: