aGrUM  0.16.0
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 58 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 51 of file imddi_tpl.h.

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

56  :
57  IncrementalGraphLearner< AttributeSelection, isScalar >(
58  target, attributeListe, learnedValue),
59  __lg(&(this->_model), pairSelectionThreshold), __nbTotalObservation(0),
60  __attributeSelectionThreshold(attributeSelectionThreshold) {
61  GUM_CONSTRUCTOR(IMDDI);
62  __addLeaf(this->_root);
63  }
LeafAggregator __lg
Definition: imddi.h:170
void __addLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:290
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition: imddi_tpl.h:51
NodeId _root
The root of the ordered tree.
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: imddi.h:178
NodeGraphPart _model
The source of nodeId.
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: imddi.h:175
+ 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 69 of file imddi_tpl.h.

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

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

◆ ~IMDDI()

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

Default destructor.

Definition at line 86 of file imddi_tpl.h.

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

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

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 290 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().

290  {
291  __leafMap.insert(currentNodeId,
292  new ConcreteLeaf< AttributeSelection, isScalar >(
293  currentNodeId,
294  this->_nodeId2Database[currentNodeId],
295  &(this->_valueAssumed)));
296  __lg.addLeaf(__leafMap[currentNodeId]);
297  }
LeafAggregator __lg
Definition: imddi.h:170
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:172
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 183 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().

184  {
185  if (!this->_nodeId2Database[nody]->isTestRelevant(var)) return;
186  double weight = (double)this->_nodeId2Database[nody]->nbObservation()
187  / (double)this->__nbTotalObservation;
188  vs.downdateScore(var,
189  weight * this->_nodeId2Database[nody]->testValue(var),
190  weight
191  * this->_nodeId2Database[nody]->testOtherCriterion(var));
192  }
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:175
+ 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 391 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().

392  {
393  double value = 0.0;
394  for (Idx moda = 0; moda < leaf->nbModa(); moda++) {
395  value += (double)leaf->effectif(moda) * this->_valueAssumed.atPos(moda);
396  }
397  if (leaf->total()) value /= (double)leaf->total();
398  return this->_target->manager()->addTerminalNode(value);
399  }
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 406 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().

407  {
408  NodeId* sonsMap = static_cast< NodeId* >(
409  SOA_ALLOCATE(sizeof(NodeId) * this->_value->domainSize()));
410  for (Idx modality = 0; modality < this->_value->domainSize(); ++modality) {
411  double newVal = 0.0;
412  if (leaf->total())
413  newVal = (double)leaf->effectif(modality) / (double)leaf->total();
414  sonsMap[modality] = this->_target->manager()->addTerminalNode(newVal);
415  }
416  return this->_target->manager()->addInternalNode(this->_value, sonsMap);
417  }
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:98
#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 328 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().

328  {
329  // *******************************************************************************************************
330  // Mise à jour de l'aggregateur de feuille
331  __lg.update();
332 
333  // *******************************************************************************************************
334  // Reinitialisation du Graphe de Décision
335  this->_target->clear();
336  for (auto varIter = __varOrder.beginSafe(); varIter != __varOrder.endSafe();
337  ++varIter)
338  this->_target->add(**varIter);
339  this->_target->add(*this->_value);
340 
342 
343  // *******************************************************************************************************
344  // Insertion des feuilles
345  HashTable< NodeId, AbstractLeaf* > treeNode2leaf = __lg.leavesMap();
346  HashTable< AbstractLeaf*, NodeId > leaf2DGNode;
347  for (HashTableConstIteratorSafe< NodeId, AbstractLeaf* > treeNodeIter =
348  treeNode2leaf.cbeginSafe();
349  treeNodeIter != treeNode2leaf.cendSafe();
350  ++treeNodeIter) {
351  if (!leaf2DGNode.exists(treeNodeIter.val()))
352  leaf2DGNode.insert(treeNodeIter.val(),
353  __insertLeafInFunctionGraph(treeNodeIter.val(),
354  Int2Type< isScalar >()));
355 
356  toTarget.insert(treeNodeIter.key(), leaf2DGNode[treeNodeIter.val()]);
357  }
358 
359  // *******************************************************************************************************
360  // Insertion des noeuds internes (avec vérification des possibilités de
361  // fusion)
362  for (SequenceIteratorSafe< const DiscreteVariable* > varIter =
363  __varOrder.rbeginSafe();
364  varIter != __varOrder.rendSafe();
365  --varIter) {
366  for (Link< NodeId >* curNodeIter = this->_var2Node[*varIter]->list();
367  curNodeIter;
368  curNodeIter = curNodeIter->nextLink()) {
369  NodeId* sonsMap = static_cast< NodeId* >(
370  SOA_ALLOCATE(sizeof(NodeId) * (*varIter)->domainSize()));
371  for (Idx modality = 0; modality < (*varIter)->domainSize(); ++modality)
372  sonsMap[modality] =
373  toTarget[this->_nodeSonsMap[curNodeIter->element()][modality]];
374  toTarget.insert(
375  curNodeIter->element(),
376  this->_target->manager()->addInternalNode(*varIter, sonsMap));
377  }
378  }
379 
380  // *******************************************************************************************************
381  // Polish
382  this->_target->manager()->setRootNode(toTarget[this->_root]);
383  this->_target->manager()->clean();
384  }
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:170
NodeId __insertLeafInFunctionGraph(AbstractLeaf *, Int2Type< true >)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:391
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:168
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:98
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 304 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().

304  {
305  __lg.removeLeaf(__leafMap[currentNodeId]);
306  delete __leafMap[currentNodeId];
307  __leafMap.erase(currentNodeId);
308  }
LeafAggregator __lg
Definition: imddi.h:170
HashTable< NodeId, AbstractLeaf *> __leafMap
Definition: imddi.h:172
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 201 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().

204  {
205  Set< NodeId > oldNodeSet(nodeSet);
206  nodeSet.clear();
207  for (SetIteratorSafe< NodeId > nodeIter = oldNodeSet.beginSafe();
208  nodeIter != oldNodeSet.endSafe();
209  ++nodeIter) {
210  if (this->_nodeId2Database[*nodeIter]->isTestRelevant(selectedVar)
211  && this->_nodeId2Database[*nodeIter]->testValue(selectedVar)
213  this->_transpose(*nodeIter, selectedVar);
214 
215  // Then we subtract the from the score given to each variables the
216  // quantity given by this node
217  for (vs.begin(); vs.hasNext(); vs.next()) {
218  __downdateScore(vs.current(), *nodeIter, vs);
219  }
220 
221  // And finally we add all its child to the new set of nodes
222  // and updates the remaining var's score
223  for (Idx modality = 0;
224  modality < this->_nodeVarMap[*nodeIter]->domainSize();
225  ++modality) {
226  NodeId sonId = this->_nodeSonsMap[*nodeIter][modality];
227  nodeSet << sonId;
228 
229  for (vs.begin(); vs.hasNext(); vs.next()) {
230  __updateScore(vs.current(), sonId, vs);
231  }
232  }
233  } else {
234  nodeSet << *nodeIter;
235  }
236  }
237  }
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:172
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:183
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: imddi.h:178
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:375
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ 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 172 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().

173  {
174  if (!this->_nodeId2Database[nody]->isTestRelevant(var)) return;
175  double weight = (double)this->_nodeId2Database[nody]->nbObservation()
176  / (double)this->__nbTotalObservation;
177  vs.updateScore(var,
178  weight * this->_nodeId2Database[nody]->testValue(var),
179  weight * this->_nodeId2Database[nody]->testOtherCriterion(var));
180  }
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:175
+ 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 262 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.

263  {
264  if (this->_nodeVarMap[currentNodeId] == this->_value)
265  __removeLeaf(currentNodeId);
266 
268  currentNodeId, desiredVar);
269 
270  if (desiredVar == this->_value) __addLeaf(currentNodeId);
271  }
void __removeLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:304
void __addLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:290
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 211 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().

212  {
213  if (_nodeVarMap[currentNodeId] != _value) {
214  _leafDatabase.insert(currentNodeId, new Set< const Observation* >());
215 
216  // Resolving potential sons issue
217  for (Idx modality = 0; modality < _nodeVarMap[currentNodeId]->domainSize();
218  ++modality) {
219  NodeId sonId = _nodeSonsMap[currentNodeId][modality];
220  _convertNode2Leaf(sonId);
221  (*_leafDatabase[currentNodeId]) =
222  (*_leafDatabase[currentNodeId]) + *(_leafDatabase[sonId]);
223  _removeNode(sonId);
224  }
225 
226  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
227  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
228  _nodeSonsMap.erase(currentNodeId);
229 
230  _chgNodeBoundVar(currentNodeId, _value);
231  }
232  }
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:98
+ 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 383 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().

386  {
387  NodeId newNodeId = this->_insertNode(nDB, boundVar);
388  _nodeSonsMap.insert(newNodeId, sonsMap);
389  return newNodeId;
390  }
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:98
+ 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 244 of file imddi_tpl.h.

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

247  {
248  NodeId currentNodeId =
250  nDB, boundVar, obsSet);
251 
252  __addLeaf(currentNodeId);
253 
254  return currentNodeId;
255  }
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:290
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ 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 358 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().

360  {
361  NodeId newNodeId = _model.addNode();
362  _nodeVarMap.insert(newNodeId, boundVar);
363  _nodeId2Database.insert(newNodeId, nDB);
364  _var2Node[boundVar]->addLink(newNodeId);
365 
366  _needUpdate = true;
367 
368  return newNodeId;
369  }
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:98
+ 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 278 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.

278  {
279  if (this->_nodeVarMap[currentNodeId] == this->_value)
280  __removeLeaf(currentNodeId);
282  currentNodeId);
283  }
void __removeLeaf(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:304
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 240 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().

241  {
242  // **************************************************************************************
243  // Si le noeud courant contient déjà la variable qu'on souhaite lui amener
244  // Il n'y a rien à faire
245  if (_nodeVarMap[currentNodeId] == desiredVar) { return; }
246 
247  // **************************************************************************************
248  // Si le noeud courant est terminal,
249  // Il faut artificiellement insérer un noeud liant à la variable
250  if (_nodeVarMap[currentNodeId] == _value) {
251  // We turned this leaf into an internal node.
252  // This mean that we'll need to install children leaves for each value of
253  // desiredVar
254 
255  // First We must prepare these new leaves NodeDatabases and Sets<const
256  // Observation*>
257  NodeDatabase< AttributeSelection, isScalar >** dbMap =
258  static_cast< NodeDatabase< AttributeSelection, isScalar >** >(
259  SOA_ALLOCATE(sizeof(NodeDatabase< AttributeSelection, isScalar >*)
260  * desiredVar->domainSize()));
261  Set< const Observation* >** obsetMap =
262  static_cast< Set< const Observation* >** >(SOA_ALLOCATE(
263  sizeof(Set< const Observation* >*) * desiredVar->domainSize()));
264  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality) {
265  dbMap[modality] =
266  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value);
267  obsetMap[modality] = new Set< const Observation* >();
268  }
269  for (SetIteratorSafe< const Observation* > obsIter =
270  _leafDatabase[currentNodeId]->beginSafe();
271  _leafDatabase[currentNodeId]->endSafe() != obsIter;
272  ++obsIter) {
273  dbMap[__branchObs(*obsIter, desiredVar)]->addObservation(*obsIter);
274  obsetMap[__branchObs(*obsIter, desiredVar)]->insert(*obsIter);
275  }
276 
277  // Then we can install each new leaves (and put in place the sonsMap)
278  NodeId* sonsMap = static_cast< NodeId* >(
279  SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
280  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality)
281  sonsMap[modality] =
282  _insertLeafNode(dbMap[modality], _value, obsetMap[modality]);
283 
284  // Some necessary clean up
285  SOA_DEALLOCATE(dbMap,
286  sizeof(NodeDatabase< AttributeSelection, isScalar >*)
287  * desiredVar->domainSize());
289  obsetMap, sizeof(Set< const Observation* >*) * desiredVar->domainSize());
290 
291  // And finally we can turn the node into an internal node associated to
292  // desiredVar
293  _chgNodeBoundVar(currentNodeId, desiredVar);
294  _nodeSonsMap.insert(currentNodeId, sonsMap);
295 
296  return;
297  }
298 
299  // *************************************************************************************
300  // Remains the general case where currentNodeId is an internal node.
301 
302  // First we ensure that children node use desiredVar as variable
303  for (Idx modality = 0; modality < _nodeVarMap[currentNodeId]->domainSize();
304  ++modality)
305  _transpose(_nodeSonsMap[currentNodeId][modality], desiredVar);
306 
307  // Sequence<NodeDatabase<AttributeSelection, isScalar>*>
308  // sonsNodeDatabase =
309  // _nodeId2Database[currentNodeId]->splitOnVar(desiredVar);
310  NodeId* sonsMap = static_cast< NodeId* >(
311  SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
312 
313  // Then we create the new mapping
314  for (Idx desiredVarModality = 0; desiredVarModality < desiredVar->domainSize();
315  ++desiredVarModality) {
316  NodeId* grandSonsMap = static_cast< NodeId* >(
317  SOA_ALLOCATE(sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize()));
318  NodeDatabase< AttributeSelection, isScalar >* sonDB =
319  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value);
320  for (Idx currentVarModality = 0;
321  currentVarModality < _nodeVarMap[currentNodeId]->domainSize();
322  ++currentVarModality) {
323  grandSonsMap[currentVarModality] =
324  _nodeSonsMap[_nodeSonsMap[currentNodeId][currentVarModality]]
325  [desiredVarModality];
326  sonDB->operator+=((*_nodeId2Database[grandSonsMap[currentVarModality]]));
327  }
328 
329  sonsMap[desiredVarModality] =
330  _insertInternalNode(sonDB, _nodeVarMap[currentNodeId], grandSonsMap);
331  }
332 
333  // Finally we clean the old remaining nodes
334  for (Idx currentVarModality = 0;
335  currentVarModality < _nodeVarMap[currentNodeId]->domainSize();
336  ++currentVarModality) {
337  _removeNode(_nodeSonsMap[currentNodeId][currentVarModality]);
338  }
339 
340  // We suppress the old sons map and remap to the new one
341  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
342  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
343  _nodeSonsMap[currentNodeId] = sonsMap;
344 
345  _chgNodeBoundVar(currentNodeId, desiredVar);
346  }
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:98
#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 180 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().

181  {
182  // If this node has no interesting variable, we turn it into a leaf
183  if (varsOfInterest.empty()) {
184  _convertNode2Leaf(updatedNode);
185  return;
186  }
187 
188  // If this node has already one of the best variable intalled as test, we
189  // move on
190  if (_nodeVarMap.exists(updatedNode)
191  && varsOfInterest.exists(_nodeVarMap[updatedNode])) {
192  return;
193  }
194 
195  // In any other case we have to install variable as best test
196  Idx randy = (Idx)(std::rand() / RAND_MAX) * varsOfInterest.size(), basc = 0;
197  SetConstIteratorSafe< const DiscreteVariable* > varIter;
198  for (varIter = varsOfInterest.cbeginSafe(), basc = 0;
199  varIter != varsOfInterest.cendSafe() && basc < randy;
200  ++varIter, basc++)
201  ;
202 
203  _transpose(updatedNode, *varIter);
204  }
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:53
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 108 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().

109  {
110  IncrementalGraphLearner< AttributeSelection,
111  isScalar >::_updateNodeWithObservation(newObs,
112  currentNodeId);
113  if (this->_nodeVarMap[currentNodeId] == this->_value)
114  __lg.updateLeaf(__leafMap[currentNodeId]);
115  }
LeafAggregator __lg
Definition: imddi.h:170
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:108
HashTable< NodeId, AbstractLeaf *> __leafMap
Definition: imddi.h:172
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 101 of file imddi_tpl.h.

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

102  {
105  }
virtual void addObservation(const Observation *obs)
Inserts a new observation.
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: imddi.h:175
+ 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 159 of file imddi.h.

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

159  {
160  for (SequenceIteratorSafe< const DiscreteVariable* > varIter =
161  __varOrder.beginSafe();
162  varIter != __varOrder.endSafe();
163  ++varIter)
164  ret->add(**varIter);
165  }
Sequence< const DiscreteVariable *> __varOrder
Definition: imddi.h:168
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 318 of file incrementalGraphLearner.h.

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

318 { 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 337 of file incrementalGraphLearner.h.

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

337  {
338  return this->_nodeId2Database[ni]->nbObservation();
339  }
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 330 of file incrementalGraphLearner.h.

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

330  {
331  return this->_nodeSonsMap[ni][modality];
332  }
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 323 of file incrementalGraphLearner.h.

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

323  {
324  return this->_nodeVarMap[ni];
325  }
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 313 of file incrementalGraphLearner.h.

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

313 { 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 302 of file incrementalGraphLearner.h.

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

302 { 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 316 of file imddi_tpl.h.

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

316  {
317  // if( __lg.needsUpdate() || this->_needUpdate ){
319  this->_needUpdate = false;
320  // }
321  }
void __rebuildFunctionGraph()
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:328
+ 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 122 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().

122  {
123  __varOrder.clear();
124 
125  // First xe initialize the node set which will give us the scores
126  Set< NodeId > currentNodeSet;
127  currentNodeSet.insert(this->_root);
128 
129  // Then we initialize the pool of variables to consider
130  VariableSelector vs(this->_setOfVars);
131  for (vs.begin(); vs.hasNext(); vs.next()) {
132  __updateScore(vs.current(), this->_root, vs);
133  }
134 
135  // Then, until there's no node remaining
136  while (!vs.isEmpty()) {
137  // We select the best var
138  const DiscreteVariable* selectedVar = vs.select();
139  __varOrder.insert(selectedVar);
140 
141  // Then we decide if we update each node according to this var
142  __updateNodeSet(currentNodeSet, selectedVar, vs);
143  }
144 
145  // If there are remaining node that are not leaves after we establish the
146  // var order
147  // these nodes are turned into leaf.
148  for (SetIteratorSafe< NodeId > nodeIter = currentNodeSet.beginSafe();
149  nodeIter != currentNodeSet.endSafe();
150  ++nodeIter)
151  this->_convertNode2Leaf(*nodeIter);
152 
153 
154  if (__lg.needsUpdate()) __lg.update();
155  }
LeafAggregator __lg
Definition: imddi.h:170
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:172
virtual void _convertNode2Leaf(NodeId)
Turns the given node into a leaf if not already so.
Sequence< const DiscreteVariable *> __varOrder
Definition: imddi.h:168
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Definition: set_tpl.h:502
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
Definition: set_tpl.h:488
NodeId _root
The root of the ordered tree.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
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:201
+ 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 158 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().

159  {
160  Link< NodeId >* nodIter = _var2Node[var]->list();
161  Link< NodeId >* nni = nullptr;
162  while (nodIter) {
163  nni = nodIter->nextLink();
164  _convertNode2Leaf(nodIter->element());
165  nodIter = nni;
166  }
167  }
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 178 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: