aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
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 DiscreteVariablevalue_
 
Sequence< ValueTypevalueAssumed_
 
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 57 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::Set< Key, Alloc >::emplace().

55  :
56  IncrementalGraphLearner< AttributeSelection, isScalar >(target, attributeListe, learnedValue),
57  _lg_(&(this->model_), pairSelectionThreshold), _nbTotalObservation_(0),
58  _attributeSelectionThreshold_(attributeSelectionThreshold) {
59  GUM_CONSTRUCTOR(IMDDI);
60  _addLeaf_(this->root_);
61  }
LeafAggregator _lg_
Definition: imddi.h:166
void _addLeaf_(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:282
NodeId root_
The root of the ordered tree.
double _attributeSelectionThreshold_
The threshold above which we consider variables to be dependant.
Definition: imddi.h:174
Idx _nbTotalObservation_
The total number of observation added to this tree.
Definition: imddi.h:171
NodeGraphPart model_
The source of nodeId.
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition: imddi_tpl.h:51
+ 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 67 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

70  :
71  IncrementalGraphLearner< AttributeSelection, isScalar >(
72  target,
73  attributeListe,
74  new LabelizedVariable("Reward", "", 2)),
75  _lg_(&(this->model_), pairSelectionThreshold), _nbTotalObservation_(0),
76  _attributeSelectionThreshold_(attributeSelectionThreshold) {
77  GUM_CONSTRUCTOR(IMDDI);
78  _addLeaf_(this->root_);
79  }
LeafAggregator _lg_
Definition: imddi.h:166
void _addLeaf_(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:282
NodeId root_
The root of the ordered tree.
double _attributeSelectionThreshold_
The threshold above which we consider variables to be dependant.
Definition: imddi.h:174
Idx _nbTotalObservation_
The total number of observation added to this tree.
Definition: imddi.h:171
NodeGraphPart model_
The source of nodeId.
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition: imddi_tpl.h:51
+ Here is the call graph for this function:

◆ ~IMDDI()

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

Default destructor.

Definition at line 85 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

85  {
86  GUM_DESTRUCTOR(IMDDI);
87  for (HashTableIteratorSafe< NodeId, AbstractLeaf* > leafIter = _leafMap_.beginSafe();
88  leafIter != _leafMap_.endSafe();
89  ++leafIter)
90  delete leafIter.val();
91  }
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition: imddi_tpl.h:51
HashTable< NodeId, AbstractLeaf *> _leafMap_
Definition: imddi.h:168
+ Here is the call graph for this function:

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 282 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

282  {
283  _leafMap_.insert(
284  currentNodeId,
285  new ConcreteLeaf< AttributeSelection, isScalar >(currentNodeId,
286  this->nodeId2Database_[currentNodeId],
287  &(this->valueAssumed_)));
288  _lg_.addLeaf(_leafMap_[currentNodeId]);
289  }
LeafAggregator _lg_
Definition: imddi.h:166
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:168
void addLeaf(AbstractLeaf *)
+ Here is the call 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::Set< Key, Alloc >::emplace().

182  {
183  if (!this->nodeId2Database_[nody]->isTestRelevant(var)) return;
184  double weight
185  = (double)this->nodeId2Database_[nody]->nbObservation() / (double)this->_nbTotalObservation_;
186  vs.downdateScore(var,
187  weight * this->nodeId2Database_[nody]->testValue(var),
188  weight * this->nodeId2Database_[nody]->testOtherCriterion(var));
189  }
Idx _nbTotalObservation_
The total number of observation added to this tree.
Definition: imddi.h:171
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> nodeId2Database_
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
+ Here is the call 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 377 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

378  {
379  double value = 0.0;
380  for (Idx moda = 0; moda < leaf->nbModa(); moda++) {
381  value += (double)leaf->effectif(moda) * this->valueAssumed_.atPos(moda);
382  }
383  if (leaf->total()) value /= (double)leaf->total();
384  return this->target_->manager()->addTerminalNode(value);
385  }
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:

◆ _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 392 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

393  {
394  NodeId* sonsMap
395  = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * this->value_->domainSize()));
396  for (Idx modality = 0; modality < this->value_->domainSize(); ++modality) {
397  double newVal = 0.0;
398  if (leaf->total()) newVal = (double)leaf->effectif(modality) / (double)leaf->total();
399  sonsMap[modality] = this->target_->manager()->addTerminalNode(newVal);
400  }
401  return this->target_->manager()->addInternalNode(this->value_, sonsMap);
402  }
MultiDimFunctionGraph< double > * target_
The final diagram we&#39;re building.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
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 320 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

320  {
321  // *******************************************************************************************************
322  // Mise à jour de l'aggregateur de feuille
323  _lg_.update();
324 
325  // *******************************************************************************************************
326  // Reinitialisation du Graphe de Décision
327  this->target_->clear();
328  for (auto varIter = _varOrder_.beginSafe(); varIter != _varOrder_.endSafe(); ++varIter)
329  this->target_->add(**varIter);
330  this->target_->add(*this->value_);
331 
333 
334  // *******************************************************************************************************
335  // Insertion des feuilles
336  HashTable< NodeId, AbstractLeaf* > treeNode2leaf = _lg_.leavesMap();
337  HashTable< AbstractLeaf*, NodeId > leaf2DGNode;
338  for (HashTableConstIteratorSafe< NodeId, AbstractLeaf* > treeNodeIter
339  = treeNode2leaf.cbeginSafe();
340  treeNodeIter != treeNode2leaf.cendSafe();
341  ++treeNodeIter) {
342  if (!leaf2DGNode.exists(treeNodeIter.val()))
343  leaf2DGNode.insert(treeNodeIter.val(),
344  _insertLeafInFunctionGraph_(treeNodeIter.val(), Int2Type< isScalar >()));
345 
346  toTarget.insert(treeNodeIter.key(), leaf2DGNode[treeNodeIter.val()]);
347  }
348 
349  // *******************************************************************************************************
350  // Insertion des noeuds internes (avec vérification des possibilités de
351  // fusion)
352  for (SequenceIteratorSafe< const DiscreteVariable* > varIter = _varOrder_.rbeginSafe();
353  varIter != _varOrder_.rendSafe();
354  --varIter) {
355  for (Link< NodeId >* curNodeIter = this->var2Node_[*varIter]->list(); curNodeIter;
356  curNodeIter = curNodeIter->nextLink()) {
357  NodeId* sonsMap
358  = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * (*varIter)->domainSize()));
359  for (Idx modality = 0; modality < (*varIter)->domainSize(); ++modality)
360  sonsMap[modality] = toTarget[this->nodeSonsMap_[curNodeIter->element()][modality]];
361  toTarget.insert(curNodeIter->element(),
362  this->target_->manager()->addInternalNode(*varIter, sonsMap));
363  }
364  }
365 
366  // *******************************************************************************************************
367  // Polish
368  this->target_->manager()->setRootNode(toTarget[this->root_]);
369  this->target_->manager()->clean();
370  }
void clean()
Removes var without nodes in the diagram.
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
MultiDimFunctionGraph< double > * target_
The final diagram we&#39;re building.
LeafAggregator _lg_
Definition: imddi.h:166
NodeId root_
The root of the ordered tree.
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> var2Node_
Associates to any variable the list of all nodes associated to this variable.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
Sequence< const DiscreteVariable *> _varOrder_
Definition: imddi.h:164
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, AbstractLeaf *> leavesMap()
NodeId _insertLeafInFunctionGraph_(AbstractLeaf *, Int2Type< true >)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:377
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:

◆ _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 296 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

296  {
297  _lg_.removeLeaf(_leafMap_[currentNodeId]);
298  delete _leafMap_[currentNodeId];
299  _leafMap_.erase(currentNodeId);
300  }
LeafAggregator _lg_
Definition: imddi.h:166
void removeLeaf(AbstractLeaf *)
HashTable< NodeId, AbstractLeaf *> _leafMap_
Definition: imddi.h:168
+ Here is the call 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::Set< Key, Alloc >::emplace().

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

References gum::Set< Key, Alloc >::emplace().

170  {
171  if (!this->nodeId2Database_[nody]->isTestRelevant(var)) return;
172  double weight
173  = (double)this->nodeId2Database_[nody]->nbObservation() / (double)this->_nbTotalObservation_;
174  vs.updateScore(var,
175  weight * this->nodeId2Database_[nody]->testValue(var),
176  weight * this->nodeId2Database_[nody]->testOtherCriterion(var));
177  }
Idx _nbTotalObservation_
The total number of observation added to this tree.
Definition: imddi.h:171
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> nodeId2Database_
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
+ 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 99 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

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:171
+ Here is the call 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 257 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

258  {
259  if (this->nodeVarMap_[currentNodeId] == this->value_) _removeLeaf_(currentNodeId);
260 
262  desiredVar);
263 
264  if (desiredVar == this->value_) _addLeaf_(currentNodeId);
265  }
void _addLeaf_(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:282
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.
void _removeLeaf_(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:296
+ 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 200 of file incrementalGraphLearner_tpl.h.

References gum::Set< Key, Alloc >::emplace().

201  {
202  if (nodeVarMap_[currentNodeId] != value_) {
203  leafDatabase_.insert(currentNodeId, new Set< const Observation* >());
204 
205  // Resolving potential sons issue
206  for (Idx modality = 0; modality < nodeVarMap_[currentNodeId]->domainSize(); ++modality) {
207  NodeId sonId = nodeSonsMap_[currentNodeId][modality];
208  convertNode2Leaf_(sonId);
209  (*leafDatabase_[currentNodeId]) = (*leafDatabase_[currentNodeId]) + *(leafDatabase_[sonId]);
210  removeNode_(sonId);
211  }
212 
213  SOA_DEALLOCATE(nodeSonsMap_[currentNodeId],
214  sizeof(NodeId) * nodeVarMap_[currentNodeId]->domainSize());
215  nodeSonsMap_.erase(currentNodeId);
216 
217  chgNodeBoundVar_(currentNodeId, value_);
218  }
219  }
virtual void convertNode2Leaf_(NodeId)
Turns the given node into a leaf if not already so.
void erase(const Key &key)
Removes a given element from the hash table.
#define SOA_DEALLOCATE(x, y)
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, NodeId *> nodeSonsMap_
A table giving for any node a table mapping to its son idx is the modality of associated variable...
HashTable< NodeId, Set< const Observation *> *> leafDatabase_
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
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:

◆ 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 362 of file incrementalGraphLearner_tpl.h.

References gum::Set< Key, Alloc >::emplace().

365  {
366  NodeId newNodeId = this->insertNode_(nDB, boundVar);
367  nodeSonsMap_.insert(newNodeId, sonsMap);
368  return newNodeId;
369  }
virtual NodeId insertNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
inserts a new node in internal graph
HashTable< NodeId, NodeId *> nodeSonsMap_
A table giving for any node a table mapping to its son idx is the modality of associated variable...
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:

◆ 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 238 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

241  {
242  NodeId currentNodeId
244  boundVar,
245  obsSet);
246 
247  _addLeaf_(currentNodeId);
248 
249  return currentNodeId;
250  }
void _addLeaf_(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:282
virtual NodeId insertLeafNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
inserts a new leaf node in internal graohs
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 338 of file incrementalGraphLearner_tpl.h.

References gum::Set< Key, Alloc >::emplace().

340  {
341  NodeId newNodeId = model_.addNode();
342  nodeVarMap_.insert(newNodeId, boundVar);
343  nodeId2Database_.insert(newNodeId, nDB);
344  var2Node_[boundVar]->addLink(newNodeId);
345 
346  needUpdate_ = true;
347 
348  return newNodeId;
349  }
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> var2Node_
Associates to any variable the list of all nodes associated to this variable.
virtual NodeId addNode()
insert a new node and return its id
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> nodeId2Database_
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
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:

◆ 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.

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

◆ isTerminal()

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

Implements gum::IVisitableGraphLearner.

Definition at line 306 of file incrementalGraphLearner.h.

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

◆ nodeNbObservation()

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

Implements gum::IVisitableGraphLearner.

Definition at line 321 of file incrementalGraphLearner.h.

321 { return this->nodeId2Database_[ni]->nbObservation(); }
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 316 of file incrementalGraphLearner.h.

316 { return this->nodeSonsMap_[ni][modality]; }
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 311 of file incrementalGraphLearner.h.

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

◆ 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 272 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

272  {
273  if (this->nodeVarMap_[currentNodeId] == this->value_) _removeLeaf_(currentNodeId);
275  }
virtual void removeNode_(NodeId removedNodeId)
Removes a node from the internal graph.
HashTable< NodeId, const DiscreteVariable *> nodeVarMap_
Gives for any node its associated variable.
void _removeLeaf_(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:296
+ Here is the call graph for this function:

◆ root()

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

Implements gum::IVisitableGraphLearner.

Definition at line 301 of file incrementalGraphLearner.h.

301 { 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 290 of file incrementalGraphLearner.h.

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

◆ 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 227 of file incrementalGraphLearner_tpl.h.

References gum::Set< Key, Alloc >::emplace().

229  {
230  // **************************************************************************************
231  // Si le noeud courant contient déjà la variable qu'on souhaite lui amener
232  // Il n'y a rien à faire
233  if (nodeVarMap_[currentNodeId] == desiredVar) { return; }
234 
235  // **************************************************************************************
236  // Si le noeud courant est terminal,
237  // Il faut artificiellement insérer un noeud liant à la variable
238  if (nodeVarMap_[currentNodeId] == value_) {
239  // We turned this leaf into an internal node.
240  // This mean that we'll need to install children leaves for each value of
241  // desiredVar
242 
243  // First We must prepare these new leaves NodeDatabases and Sets<const
244  // Observation*>
245  NodeDatabase< AttributeSelection, isScalar >** dbMap
246  = static_cast< NodeDatabase< AttributeSelection, isScalar >** >(SOA_ALLOCATE(
247  sizeof(NodeDatabase< AttributeSelection, isScalar >*) * desiredVar->domainSize()));
248  Set< const Observation* >** obsetMap = static_cast< Set< const Observation* >** >(
249  SOA_ALLOCATE(sizeof(Set< const Observation* >*) * desiredVar->domainSize()));
250  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality) {
251  dbMap[modality] = new NodeDatabase< AttributeSelection, isScalar >(&setOfVars_, value_);
252  obsetMap[modality] = new Set< const Observation* >();
253  }
254  for (SetIteratorSafe< const Observation* > obsIter
255  = leafDatabase_[currentNodeId]->beginSafe();
256  leafDatabase_[currentNodeId]->endSafe() != obsIter;
257  ++obsIter) {
258  dbMap[_branchObs_(*obsIter, desiredVar)]->addObservation(*obsIter);
259  obsetMap[_branchObs_(*obsIter, desiredVar)]->insert(*obsIter);
260  }
261 
262  // Then we can install each new leaves (and put in place the sonsMap)
263  NodeId* sonsMap
264  = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
265  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality)
266  sonsMap[modality] = insertLeafNode_(dbMap[modality], value_, obsetMap[modality]);
267 
268  // Some necessary clean up
269  SOA_DEALLOCATE(dbMap,
270  sizeof(NodeDatabase< AttributeSelection, isScalar >*)
271  * desiredVar->domainSize());
272  SOA_DEALLOCATE(obsetMap, sizeof(Set< const Observation* >*) * desiredVar->domainSize());
273 
274  // And finally we can turn the node into an internal node associated to
275  // desiredVar
276  chgNodeBoundVar_(currentNodeId, desiredVar);
277  nodeSonsMap_.insert(currentNodeId, sonsMap);
278 
279  return;
280  }
281 
282  // *************************************************************************************
283  // Remains the general case where currentNodeId is an internal node.
284 
285  // First we ensure that children node use desiredVar as variable
286  for (Idx modality = 0; modality < nodeVarMap_[currentNodeId]->domainSize(); ++modality)
287  transpose_(nodeSonsMap_[currentNodeId][modality], desiredVar);
288 
289  // Sequence<NodeDatabase<AttributeSelection, isScalar>*>
290  // sonsNodeDatabase =
291  // nodeId2Database_[currentNodeId]->splitOnVar(desiredVar);
292  NodeId* sonsMap
293  = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
294 
295  // Then we create the new mapping
296  for (Idx desiredVarModality = 0; desiredVarModality < desiredVar->domainSize();
297  ++desiredVarModality) {
298  NodeId* grandSonsMap = static_cast< NodeId* >(
299  SOA_ALLOCATE(sizeof(NodeId) * nodeVarMap_[currentNodeId]->domainSize()));
300  NodeDatabase< AttributeSelection, isScalar >* sonDB
301  = new NodeDatabase< AttributeSelection, isScalar >(&setOfVars_, value_);
302  for (Idx currentVarModality = 0;
303  currentVarModality < nodeVarMap_[currentNodeId]->domainSize();
304  ++currentVarModality) {
305  grandSonsMap[currentVarModality]
306  = nodeSonsMap_[nodeSonsMap_[currentNodeId][currentVarModality]][desiredVarModality];
307  sonDB->operator+=((*nodeId2Database_[grandSonsMap[currentVarModality]]));
308  }
309 
310  sonsMap[desiredVarModality]
311  = insertInternalNode_(sonDB, nodeVarMap_[currentNodeId], grandSonsMap);
312  }
313 
314  // Finally we clean the old remaining nodes
315  for (Idx currentVarModality = 0; currentVarModality < nodeVarMap_[currentNodeId]->domainSize();
316  ++currentVarModality) {
317  removeNode_(nodeSonsMap_[currentNodeId][currentVarModality]);
318  }
319 
320  // We suppress the old sons map and remap to the new one
321  SOA_DEALLOCATE(nodeSonsMap_[currentNodeId],
322  sizeof(NodeId) * nodeVarMap_[currentNodeId]->domainSize());
323  nodeSonsMap_[currentNodeId] = sonsMap;
324 
325  chgNodeBoundVar_(currentNodeId, desiredVar);
326  }
virtual void removeNode_(NodeId removedNodeId)
Removes a node from the internal graph.
#define SOA_DEALLOCATE(x, y)
virtual NodeId insertInternalNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
inserts a new internal node in internal graph
virtual void transpose_(NodeId, const DiscreteVariable *)
Installs given variable to the given node, ensuring that the variable is not present in its subtree...
Idx _branchObs_(const Observation *obs, const DiscreteVariable *var)
Seek modality assumed in obs for given var.
virtual void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Changes the associated variable of a node.
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> nodeId2Database_
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
Set< const DiscreteVariable *> setOfVars_
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, Set< const Observation *> *> leafDatabase_
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
HashTable< NodeId, const DiscreteVariable *> nodeVarMap_
Gives for any node its associated variable.
virtual NodeId insertLeafNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
inserts a new leaf node in internal graohs
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
#define SOA_ALLOCATE(x)
+ Here is the call graph for this function:

◆ 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 308 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

308  {
309  // if( _lg_.needsUpdate() || this->needUpdate_ ){
311  this->needUpdate_ = false;
312  // }
313  }
void _rebuildFunctionGraph_()
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:320
+ 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 118 of file imddi_tpl.h.

References gum::Set< Key, Alloc >::emplace().

118  {
119  _varOrder_.clear();
120 
121  // First xe initialize the node set which will give us the scores
122  Set< NodeId > currentNodeSet;
123  currentNodeSet.insert(this->root_);
124 
125  // Then we initialize the pool of variables to consider
126  VariableSelector vs(this->setOfVars_);
127  for (vs.begin(); vs.hasNext(); vs.next()) {
128  _updateScore_(vs.current(), this->root_, vs);
129  }
130 
131  // Then, until there's no node remaining
132  while (!vs.isEmpty()) {
133  // We select the best var
134  const DiscreteVariable* selectedVar = vs.select();
135  _varOrder_.insert(selectedVar);
136 
137  // Then we decide if we update each node according to this var
138  _updateNodeSet_(currentNodeSet, selectedVar, vs);
139  }
140 
141  // If there are remaining node that are not leaves after we establish the
142  // var order
143  // these nodes are turned into leaf.
144  for (SetIteratorSafe< NodeId > nodeIter = currentNodeSet.beginSafe();
145  nodeIter != currentNodeSet.endSafe();
146  ++nodeIter)
147  this->convertNode2Leaf_(*nodeIter);
148 
149 
150  if (_lg_.needsUpdate()) _lg_.update();
151  }
void _updateScore_(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:168
virtual void convertNode2Leaf_(NodeId)
Turns the given node into a leaf if not already so.
LeafAggregator _lg_
Definition: imddi.h:166
NodeId root_
The root of the ordered tree.
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Definition: set_tpl.h:483
Sequence< const DiscreteVariable *> _varOrder_
Definition: imddi.h:164
Set< const DiscreteVariable *> setOfVars_
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
Definition: set_tpl.h:470
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
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call 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 169 of file incrementalGraphLearner_tpl.h.

References gum::Set< Key, Alloc >::emplace().

171  {
172  // If this node has no interesting variable, we turn it into a leaf
173  if (varsOfInterest.empty()) {
174  convertNode2Leaf_(updatedNode);
175  return;
176  }
177 
178  // If this node has already one of the best variable intalled as test, we
179  // move on
180  if (nodeVarMap_.exists(updatedNode) && varsOfInterest.exists(nodeVarMap_[updatedNode])) {
181  return;
182  }
183 
184  // In any other case we have to install variable as best test
185  Idx randy = (Idx)(std::rand() / RAND_MAX) * varsOfInterest.size(), basc = 0;
186  SetConstIteratorSafe< const DiscreteVariable* > varIter;
187  for (varIter = varsOfInterest.cbeginSafe(), basc = 0;
188  varIter != varsOfInterest.cendSafe() && basc < randy;
189  ++varIter, basc++)
190  ;
191 
192  transpose_(updatedNode, *varIter);
193  }
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...
HashTable< NodeId, const DiscreteVariable *> nodeVarMap_
Gives for any node its associated variable.
Size Idx
Type for indexes.
Definition: types.h:52
+ Here is the call 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::Set< Key, Alloc >::emplace().

106  {
108  newObs,
109  currentNodeId);
110  if (this->nodeVarMap_[currentNodeId] == this->value_) _lg_.updateLeaf(_leafMap_[currentNodeId]);
111  }
LeafAggregator _lg_
Definition: imddi.h:166
virtual void updateNodeWithObservation_(const Observation *newObs, NodeId currentNodeId)
Will update internal graph&#39;s NodeDatabase of given node with the new observation. ...
HashTable< NodeId, const DiscreteVariable *> nodeVarMap_
Gives for any node its associated variable.
HashTable< NodeId, AbstractLeaf *> _leafMap_
Definition: imddi.h:168
bool updateLeaf(AbstractLeaf *)
+ 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 147 of file incrementalGraphLearner_tpl.h.

References gum::Set< Key, Alloc >::emplace().

148  {
149  Link< NodeId >* nodIter = var2Node_[var]->list();
150  Link< NodeId >* nni = nullptr;
151  while (nodIter) {
152  nni = nodIter->nextLink();
153  convertNode2Leaf_(nodIter->element());
154  nodIter = nni;
155  }
156  }
virtual void convertNode2Leaf_(NodeId)
Turns the given node into a leaf if not already so.
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> var2Node_
Associates to any variable the list of all nodes associated to this variable.
+ Here is the call 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 174 of file imddi.h.

◆ _leafMap_

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, AbstractLeaf* > gum::IMDDI< AttributeSelection, isScalar >::_leafMap_
private

Definition at line 168 of file imddi.h.

◆ _lg_

template<TESTNAME AttributeSelection, bool isScalar = false>
LeafAggregator gum::IMDDI< AttributeSelection, isScalar >::_lg_
private

Definition at line 166 of file imddi.h.

◆ _nbTotalObservation_

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

The total number of observation added to this tree.

Definition at line 171 of file imddi.h.

◆ _varOrder_

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

Definition at line 164 of file imddi.h.

◆ leafDatabase_

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, Set< const Observation* >* > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::leafDatabase_
protectedinherited

This hashtable binds to every leaf an associated set of all hte observations compatible with it.

Definition at line 379 of file incrementalGraphLearner.h.

◆ model_

template<TESTNAME AttributeSelection, bool isScalar = false>
NodeGraphPart gum::IncrementalGraphLearner< AttributeSelection, isScalar >::model_
protectedinherited

The source of nodeId.

Definition at line 345 of file incrementalGraphLearner.h.

◆ needUpdate_

template<TESTNAME AttributeSelection, bool isScalar = false>
bool gum::IncrementalGraphLearner< AttributeSelection, isScalar >::needUpdate_
protectedinherited

Definition at line 392 of file incrementalGraphLearner.h.

◆ nodeId2Database_

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar >* > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeId2Database_
protectedinherited

This hashtable binds every node to an associated NodeDatabase which handles every observation that concerns that node.

Definition at line 373 of file incrementalGraphLearner.h.

◆ nodeSonsMap_

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

A table giving for any node a table mapping to its son idx is the modality of associated variable.

Definition at line 361 of file incrementalGraphLearner.h.

◆ nodeVarMap_

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

Gives for any node its associated variable.

Definition at line 355 of file incrementalGraphLearner.h.

◆ root_

template<TESTNAME AttributeSelection, bool isScalar = false>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::root_
protectedinherited

The root of the ordered tree.

Definition at line 350 of file incrementalGraphLearner.h.

◆ setOfVars_

template<TESTNAME AttributeSelection, bool isScalar = false>
Set< const DiscreteVariable* > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::setOfVars_
protectedinherited

Definition at line 387 of file incrementalGraphLearner.h.

◆ target_

template<TESTNAME AttributeSelection, bool isScalar = false>
MultiDimFunctionGraph< double >* gum::IncrementalGraphLearner< AttributeSelection, isScalar >::target_
protectedinherited

The final diagram we're building.

Definition at line 385 of file incrementalGraphLearner.h.

◆ value_

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

Definition at line 389 of file incrementalGraphLearner.h.

◆ valueAssumed_

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

Definition at line 390 of file incrementalGraphLearner.h.

◆ var2Node_

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

Associates to any variable the list of all nodes associated to this variable.

Definition at line 367 of file incrementalGraphLearner.h.


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