aGrUM  0.20.2
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().

56  :
57  IncrementalGraphLearner< AttributeSelection, isScalar >(target,
58  attributeListe,
59  learnedValue),
60  lg__(&(this->model_), pairSelectionThreshold), nbTotalObservation__(0),
61  attributeSelectionThreshold__(attributeSelectionThreshold) {
62  GUM_CONSTRUCTOR(IMDDI);
63  addLeaf__(this->root_);
64  }
double attributeSelectionThreshold__
The threshold above which we consider variables to be dependant.
Definition: imddi.h:177
NodeId root_
The root of the ordered tree.
LeafAggregator lg__
Definition: imddi.h:169
void addLeaf__(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:302
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
Idx nbTotalObservation__
The total number of observation added to this tree.
Definition: imddi.h:174
+ 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 70 of file imddi_tpl.h.

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

74  :
75  IncrementalGraphLearner< AttributeSelection, isScalar >(
76  target,
77  attributeListe,
78  new LabelizedVariable("Reward", "", 2)),
79  lg__(&(this->model_), pairSelectionThreshold), nbTotalObservation__(0),
80  attributeSelectionThreshold__(attributeSelectionThreshold) {
81  GUM_CONSTRUCTOR(IMDDI);
82  addLeaf__(this->root_);
83  }
double attributeSelectionThreshold__
The threshold above which we consider variables to be dependant.
Definition: imddi.h:177
NodeId root_
The root of the ordered tree.
LeafAggregator lg__
Definition: imddi.h:169
void addLeaf__(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:302
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
Idx nbTotalObservation__
The total number of observation added to this tree.
Definition: imddi.h:174
+ Here is the call graph for this function:

◆ ~IMDDI()

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

Default destructor.

Definition at line 89 of file imddi_tpl.h.

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

89  {
90  GUM_DESTRUCTOR(IMDDI);
91  for (HashTableIteratorSafe< NodeId, AbstractLeaf* > leafIter
92  = leafMap__.beginSafe();
93  leafIter != leafMap__.endSafe();
94  ++leafIter)
95  delete leafIter.val();
96  }
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:171
+ 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 302 of file imddi_tpl.h.

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

302  {
303  leafMap__.insert(currentNodeId,
304  new ConcreteLeaf< AttributeSelection, isScalar >(
305  currentNodeId,
306  this->nodeId2Database_[currentNodeId],
307  &(this->valueAssumed_)));
308  lg__.addLeaf(leafMap__[currentNodeId]);
309  }
LeafAggregator lg__
Definition: imddi.h:169
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:171
void addLeaf(AbstractLeaf *)
+ 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 104 of file imddi_tpl.h.

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

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

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

274  {
275  if (this->nodeVarMap_[currentNodeId] == this->value_)
276  removeLeaf__(currentNodeId);
277 
279  currentNodeId,
280  desiredVar);
281 
282  if (desiredVar == this->value_) addLeaf__(currentNodeId);
283  }
virtual void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Changes the associated variable of a node.
void addLeaf__(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:302
void removeLeaf__(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:316
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 212 of file incrementalGraphLearner_tpl.h.

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

213  {
214  if (nodeVarMap_[currentNodeId] != value_) {
215  leafDatabase_.insert(currentNodeId, new Set< const Observation* >());
216 
217  // Resolving potential sons issue
218  for (Idx modality = 0; modality < nodeVarMap_[currentNodeId]->domainSize();
219  ++modality) {
220  NodeId sonId = nodeSonsMap_[currentNodeId][modality];
221  convertNode2Leaf_(sonId);
222  (*leafDatabase_[currentNodeId])
223  = (*leafDatabase_[currentNodeId]) + *(leafDatabase_[sonId]);
224  removeNode_(sonId);
225  }
226 
227  SOA_DEALLOCATE(nodeSonsMap_[currentNodeId],
228  sizeof(NodeId) * nodeVarMap_[currentNodeId]->domainSize());
229  nodeSonsMap_.erase(currentNodeId);
230 
231  chgNodeBoundVar_(currentNodeId, value_);
232  }
233  }
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:

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

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

192  {
193  if (!this->nodeId2Database_[nody]->isTestRelevant(var)) return;
194  double weight = (double)this->nodeId2Database_[nody]->nbObservation()
195  / (double)this->nbTotalObservation__;
196  vs.downdateScore(var,
197  weight * this->nodeId2Database_[nody]->testValue(var),
198  weight
199  * this->nodeId2Database_[nody]->testOtherCriterion(var));
200  }
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:174
+ 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 386 of file incrementalGraphLearner_tpl.h.

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

389  {
390  NodeId newNodeId = this->insertNode_(nDB, boundVar);
391  nodeSonsMap_.insert(newNodeId, sonsMap);
392  return newNodeId;
393  }
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:

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

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

405  {
406  double value = 0.0;
407  for (Idx moda = 0; moda < leaf->nbModa(); moda++) {
408  value += (double)leaf->effectif(moda) * this->valueAssumed_.atPos(moda);
409  }
410  if (leaf->total()) value /= (double)leaf->total();
411  return this->target_->manager()->addTerminalNode(value);
412  }
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 419 of file imddi_tpl.h.

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

421  {
422  NodeId* sonsMap = static_cast< NodeId* >(
423  SOA_ALLOCATE(sizeof(NodeId) * this->value_->domainSize()));
424  for (Idx modality = 0; modality < this->value_->domainSize(); ++modality) {
425  double newVal = 0.0;
426  if (leaf->total())
427  newVal = (double)leaf->effectif(modality) / (double)leaf->total();
428  sonsMap[modality] = this->target_->manager()->addTerminalNode(newVal);
429  }
430  return this->target_->manager()->addInternalNode(this->value_, sonsMap);
431  }
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:

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

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

255  {
256  NodeId currentNodeId
258  nDB,
259  boundVar,
260  obsSet);
261 
262  addLeaf__(currentNodeId);
263 
264  return currentNodeId;
265  }
void addLeaf__(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:302
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 361 of file incrementalGraphLearner_tpl.h.

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

363  {
364  NodeId newNodeId = model_.addNode();
365  nodeVarMap_.insert(newNodeId, boundVar);
366  nodeId2Database_.insert(newNodeId, nDB);
367  var2Node_[boundVar]->addLink(newNodeId);
368 
369  needUpdate_ = true;
370 
371  return newNodeId;
372  }
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 158 of file imddi.h.

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

◆ isTerminal()

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

Implements gum::IVisitableGraphLearner.

Definition at line 317 of file incrementalGraphLearner.h.

317 { 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 336 of file incrementalGraphLearner.h.

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

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

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

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

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

340  {
341  // *******************************************************************************************************
342  // Mise à jour de l'aggregateur de feuille
343  lg__.update();
344 
345  // *******************************************************************************************************
346  // Reinitialisation du Graphe de Décision
347  this->target_->clear();
348  for (auto varIter = varOrder__.beginSafe(); varIter != varOrder__.endSafe();
349  ++varIter)
350  this->target_->add(**varIter);
351  this->target_->add(*this->value_);
352 
354 
355  // *******************************************************************************************************
356  // Insertion des feuilles
357  HashTable< NodeId, AbstractLeaf* > treeNode2leaf = lg__.leavesMap();
358  HashTable< AbstractLeaf*, NodeId > leaf2DGNode;
359  for (HashTableConstIteratorSafe< NodeId, AbstractLeaf* > treeNodeIter
360  = treeNode2leaf.cbeginSafe();
361  treeNodeIter != treeNode2leaf.cendSafe();
362  ++treeNodeIter) {
363  if (!leaf2DGNode.exists(treeNodeIter.val()))
364  leaf2DGNode.insert(treeNodeIter.val(),
365  insertLeafInFunctionGraph__(treeNodeIter.val(),
366  Int2Type< isScalar >()));
367 
368  toTarget.insert(treeNodeIter.key(), leaf2DGNode[treeNodeIter.val()]);
369  }
370 
371  // *******************************************************************************************************
372  // Insertion des noeuds internes (avec vérification des possibilités de
373  // fusion)
374  for (SequenceIteratorSafe< const DiscreteVariable* > varIter
375  = varOrder__.rbeginSafe();
376  varIter != varOrder__.rendSafe();
377  --varIter) {
378  for (Link< NodeId >* curNodeIter = this->var2Node_[*varIter]->list();
379  curNodeIter;
380  curNodeIter = curNodeIter->nextLink()) {
381  NodeId* sonsMap = static_cast< NodeId* >(
382  SOA_ALLOCATE(sizeof(NodeId) * (*varIter)->domainSize()));
383  for (Idx modality = 0; modality < (*varIter)->domainSize(); ++modality)
384  sonsMap[modality]
385  = toTarget[this->nodeSonsMap_[curNodeIter->element()][modality]];
386  toTarget.insert(
387  curNodeIter->element(),
388  this->target_->manager()->addInternalNode(*varIter, sonsMap));
389  }
390  }
391 
392  // *******************************************************************************************************
393  // Polish
394  this->target_->manager()->setRootNode(toTarget[this->root_]);
395  this->target_->manager()->clean();
396  }
Sequence< const DiscreteVariable *> varOrder__
Definition: imddi.h:167
NodeId insertLeafInFunctionGraph__(AbstractLeaf *, Int2Type< true >)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:403
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.
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.
LeafAggregator lg__
Definition: imddi.h:169
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()
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 316 of file imddi_tpl.h.

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

316  {
317  lg__.removeLeaf(leafMap__[currentNodeId]);
318  delete leafMap__[currentNodeId];
319  leafMap__.erase(currentNodeId);
320  }
LeafAggregator lg__
Definition: imddi.h:169
HashTable< NodeId, AbstractLeaf *> leafMap__
Definition: imddi.h:171
void removeLeaf(AbstractLeaf *)
+ Here is the call 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 290 of file imddi_tpl.h.

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

290  {
291  if (this->nodeVarMap_[currentNodeId] == this->value_)
292  removeLeaf__(currentNodeId);
294  currentNodeId);
295  }
virtual void removeNode_(NodeId removedNodeId)
Removes a node from the internal graph.
void removeLeaf__(NodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:316
HashTable< NodeId, const DiscreteVariable *> nodeVarMap_
Gives for any node its associated variable.
+ 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 312 of file incrementalGraphLearner.h.

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

301 { 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 241 of file incrementalGraphLearner_tpl.h.

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

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

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

328  {
329  // if( lg__.needsUpdate() || this->needUpdate_ ){
331  this->needUpdate_ = false;
332  // }
333  }
void rebuildFunctionGraph__()
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:340
+ 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 126 of file imddi_tpl.h.

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

126  {
127  varOrder__.clear();
128 
129  // First xe initialize the node set which will give us the scores
130  Set< NodeId > currentNodeSet;
131  currentNodeSet.insert(this->root_);
132 
133  // Then we initialize the pool of variables to consider
134  VariableSelector vs(this->setOfVars_);
135  for (vs.begin(); vs.hasNext(); vs.next()) {
136  updateScore__(vs.current(), this->root_, vs);
137  }
138 
139  // Then, until there's no node remaining
140  while (!vs.isEmpty()) {
141  // We select the best var
142  const DiscreteVariable* selectedVar = vs.select();
143  varOrder__.insert(selectedVar);
144 
145  // Then we decide if we update each node according to this var
146  updateNodeSet__(currentNodeSet, selectedVar, vs);
147  }
148 
149  // If there are remaining node that are not leaves after we establish the
150  // var order
151  // these nodes are turned into leaf.
152  for (SetIteratorSafe< NodeId > nodeIter = currentNodeSet.beginSafe();
153  nodeIter != currentNodeSet.endSafe();
154  ++nodeIter)
155  this->convertNode2Leaf_(*nodeIter);
156 
157 
158  if (lg__.needsUpdate()) lg__.update();
159  }
Sequence< const DiscreteVariable *> varOrder__
Definition: imddi.h:167
virtual void convertNode2Leaf_(NodeId)
Turns the given node into a leaf if not already so.
NodeId root_
The root of the ordered tree.
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:209
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Definition: set_tpl.h:501
LeafAggregator lg__
Definition: imddi.h:169
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:176
iterator_safe beginSafe() const
The usual safe begin iterator to parse the set.
Definition: set_tpl.h:487
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:632
+ 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 180 of file incrementalGraphLearner_tpl.h.

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

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

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

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

212  {
213  Set< NodeId > oldNodeSet(nodeSet);
214  nodeSet.clear();
215  for (SetIteratorSafe< NodeId > nodeIter = oldNodeSet.beginSafe();
216  nodeIter != oldNodeSet.endSafe();
217  ++nodeIter) {
218  if (this->nodeId2Database_[*nodeIter]->isTestRelevant(selectedVar)
219  && this->nodeId2Database_[*nodeIter]->testValue(selectedVar)
221  this->transpose_(*nodeIter, selectedVar);
222 
223  // Then we subtract the from the score given to each variables the
224  // quantity given by this node
225  for (vs.begin(); vs.hasNext(); vs.next()) {
226  downdateScore__(vs.current(), *nodeIter, vs);
227  }
228 
229  // And finally we add all its child to the new set of nodes
230  // and updates the remaining var's score
231  for (Idx modality = 0;
232  modality < this->nodeVarMap_[*nodeIter]->domainSize();
233  ++modality) {
234  NodeId sonId = this->nodeSonsMap_[*nodeIter][modality];
235  nodeSet << sonId;
236 
237  for (vs.begin(); vs.hasNext(); vs.next()) {
238  updateScore__(vs.current(), sonId, vs);
239  }
240  }
241  } else {
242  nodeSet << *nodeIter;
243  }
244  }
245  }
double attributeSelectionThreshold__
The threshold above which we consider variables to be dependant.
Definition: imddi.h:177
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:189
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 updateScore__(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition: imddi_tpl.h:176
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:374
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ 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 111 of file imddi_tpl.h.

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

113  {
114  IncrementalGraphLearner< AttributeSelection,
115  isScalar >::updateNodeWithObservation_(newObs,
116  currentNodeId);
117  if (this->nodeVarMap_[currentNodeId] == this->value_)
118  lg__.updateLeaf(leafMap__[currentNodeId]);
119  }
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, Set< const DiscreteVariable * > attributesSet, const DiscreteVariable *learnVariable)
Default constructor.
LeafAggregator lg__
Definition: imddi.h:169
HashTable< NodeId, AbstractLeaf *> leafMap__
Definition: imddi.h:171
void updateNodeWithObservation_(const Observation *newObs, NodeId currentNodeId)
Adds a new observation to the structure.
Definition: imddi_tpl.h:111
HashTable< NodeId, const DiscreteVariable *> nodeVarMap_
Gives for any node its associated variable.
bool updateLeaf(AbstractLeaf *)
+ 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 176 of file imddi_tpl.h.

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

179  {
180  if (!this->nodeId2Database_[nody]->isTestRelevant(var)) return;
181  double weight = (double)this->nodeId2Database_[nody]->nbObservation()
182  / (double)this->nbTotalObservation__;
183  vs.updateScore(var,
184  weight * this->nodeId2Database_[nody]->testValue(var),
185  weight * this->nodeId2Database_[nody]->testOtherCriterion(var));
186  }
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:174
+ 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::Set< Key, Alloc >::emplace().

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  }
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 177 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 398 of file incrementalGraphLearner.h.

◆ leafMap__

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

Definition at line 171 of file imddi.h.

◆ lg__

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

Definition at line 169 of file imddi.h.

◆ model_

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

The source of nodeId.

Definition at line 363 of file incrementalGraphLearner.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 174 of file imddi.h.

◆ needUpdate_

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

Definition at line 411 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 392 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 379 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 373 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 368 of file incrementalGraphLearner.h.

◆ setOfVars_

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

Definition at line 406 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 404 of file incrementalGraphLearner.h.

◆ value_

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

Definition at line 408 of file incrementalGraphLearner.h.

◆ valueAssumed_

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

Definition at line 409 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 385 of file incrementalGraphLearner.h.

◆ varOrder__

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

Definition at line 167 of file imddi.h.


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