aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
gum::IMDDI< AttributeSelection, isScalar > Class Template Referencefinal

#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 override
Constructor & destructor.
 IMDDI (MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, gum::VariableSet attributeListe, const DiscreteVariable *learnedValue)
 Variable Learner constructor.
 IMDDI (MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, gum::VariableSet attributeListe)
 Reward Learner constructor.
 ~IMDDI () override
 Default destructor.
Visit Methods
Size size ()
NodeId root () const override
bool isTerminal (NodeId ni) const override
const DiscreteVariablenodeVar (NodeId ni) const override
NodeId nodeSon (NodeId ni, Idx modality) const override
Idx nodeNbObservation (NodeId ni) const override

Protected Attributes

MultiDimFunctionGraph< double > * target_
 The final diagram we're building.
gum::VariableSet setOfVars_
const DiscreteVariablevalue_
Sequence< ValueTypevalueAssumed_
bool needUpdate_
Model handling datastructures
NodeGraphPart model_
 The source of nodeId.
NodeId root_
 The root of the ordered tree.
HashTable< NodeId, const DiscreteVariable * > nodeVarMap_
 Gives for any node its associated variable.
HashTable< NodeId, NodeId * > nodeSonsMap_
 A table giving for any node a table mapping to its son idx is the modality of associated variable.
HashTable< const DiscreteVariable *, LinkedList< NodeId > * > var2Node_
 Associates to any variable the list of all nodes associated to this variable.
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > * > nodeId2Database_
 This hashtable binds every node to an associated NodeDatabase which handles every observation that concerns that node.
HashTable< NodeId, Set< const Observation * > * > leafDatabase_
 This hashtable binds to every leaf an associated set of all hte observations compatible with it.

Private Types

using ValueType

Private Member Functions

Constructor & destructor.
void _clearValue_ ()
 Template function dispatcher.
New Observation insertion methods
void _assumeValue_ (const Observation *obs)
 Get value assumed by studied variable for current observation.
Idx _branchObs_ (const Observation *obs, const DiscreteVariable *var)
 Seek modality assumed in obs for given var.

Private Attributes

Sequence< const DiscreteVariable * > _varOrder_
LeafAggregator _lg_
HashTable< NodeId, AbstractLeaf * > _leafMap_
Idx _nbTotalObservation_
 The total number of observation added to this tree.
double _attributeSelectionThreshold_
 The threshold above which we consider variables to be dependant.

Incrementals methods

void addObservation (const Observation *) override
 Adds a new observation to the structure.
void updateGraph () override
 Updates the tree after a new observation has been added.
void updateNodeWithObservation_ (const Observation *newObs, NodeId currentNodeId) override
 Adds a new observation to the structure.
NodeId insertLeafNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *sonsMap) override
 Adds a new observation to the structure.
void chgNodeBoundVar_ (NodeId chgedNodeId, const DiscreteVariable *desiredVar) override
 Adds a new observation to the structure.
void removeNode_ (NodeId removedNodeId) override
 Adds a new observation to the structure.
void _addLeaf_ (NodeId)
 Adds a new observation to the structure.
void _removeLeaf_ (NodeId)
 Adds a new observation to the structure.

Updating private methods

void updateFunctionGraph () override
 Computes the score of the given variables for the given node.
void _updateScore_ (const DiscreteVariable *, NodeId, VariableSelector &vs)
 Computes the score of the given variables for the given node.
void _downdateScore_ (const DiscreteVariable *, NodeId, VariableSelector &vs)
 Computes the score of the given variables for the given node.
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.
void _rebuildFunctionGraph_ ()
 Computes the score of the given variables for the given node.
NodeId _insertLeafInFunctionGraph_ (AbstractLeaf *, Int2Type< true >)
 Computes the score of the given variables for the given node.
NodeId _insertLeafInFunctionGraph_ (AbstractLeaf *, Int2Type< false >)
 Computes the score of the given variables for the given node.

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.
void updateNode_ (NodeId nody, gum::VariableSet &bestVars)
 From the given sets of node, selects randomly one and installs it on given node.
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.
virtual NodeId insertNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
 inserts a new node in internal graph
virtual NodeId insertInternalNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
 inserts a new internal node in internal graph

Detailed Description

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

Definition at line 74 of file imddi.h.

Member Typedef Documentation

◆ ValueType

using gum::IncrementalGraphLearner< AttributeSelection, isScalar >::ValueType
privateinherited

Definition at line 84 of file incrementalGraphLearner.h.

Constructor & Destructor Documentation

◆ IMDDI() [1/2]

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

Variable Learner constructor.

Definition at line 75 of file imddi_tpl.h.

79 :
84 _addLeaf_(this->root_);
85 }
void _addLeaf_(NodeId)
Adds a new observation to the structure.
Definition imddi_tpl.h:298
Idx _nbTotalObservation_
The total number of observation added to this tree.
Definition imddi.h:184
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, gum::VariableSet attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition imddi_tpl.h:75
LeafAggregator _lg_
Definition imddi.h:179
double _attributeSelectionThreshold_
The threshold above which we consider variables to be dependant.
Definition imddi.h:187
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, gum::VariableSet attributesSet, const DiscreteVariable *learnVariable)

References IMDDI(), gum::IncrementalGraphLearner< AttributeSelection, false >::IncrementalGraphLearner(), _addLeaf_(), _attributeSelectionThreshold_, _lg_, _nbTotalObservation_, gum::IncrementalGraphLearner< AttributeSelection, false >::model_, and gum::IncrementalGraphLearner< AttributeSelection, false >::root_.

Referenced by IMDDI(), IMDDI(), and ~IMDDI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IMDDI() [2/2]

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

◆ ~IMDDI()

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

Default destructor.

Definition at line 109 of file imddi_tpl.h.

109 {
112 leafIter != _leafMap_.endSafe();
113 ++leafIter)
114 delete leafIter.val();
115 }
HashTable< NodeId, AbstractLeaf * > _leafMap_
Definition imddi.h:181

References IMDDI(), and _leafMap_.

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

298 {
299 _leafMap_.insert(
303 &(this->valueAssumed_)));
304 _lg_.addLeaf(_leafMap_[currentNodeId]);
305 }
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > * > nodeId2Database_

References _leafMap_, _lg_, gum::IncrementalGraphLearner< AttributeSelection, false >::nodeId2Database_, and gum::IncrementalGraphLearner< AttributeSelection, false >::valueAssumed_.

Referenced by IMDDI(), IMDDI(), chgNodeBoundVar_(), and insertLeafNode_().

Here is the caller graph for this function:

◆ _assumeValue_()

void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_assumeValue_ ( const Observation * obs)
privateinherited

Get value assumed by studied variable for current observation.

Definition at line 153 of file incrementalGraphLearner_tpl.h.

483 {
485 }
<agrum/FMDP/learning/datastructure/incrementalGraphLearner>

References leafDatabase_, and updateNodeWithObservation_().

Here is the call graph for this function:

◆ _branchObs_()

Idx gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_branchObs_ ( const Observation * obs,
const DiscreteVariable * var )
privateinherited

Seek modality assumed in obs for given var.

Definition at line 164 of file incrementalGraphLearner_tpl.h.

504 {
506 }
Idx _branchObs_(const Observation *obs, const DiscreteVariable *var)

Referenced by addObservation().

Here is the caller graph for this function:

◆ _clearValue_()

void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_clearValue_ ( )
privateinherited

Template function dispatcher.

Definition at line 117 of file incrementalGraphLearner_tpl.h.

References IncrementalGraphLearner(), _clearValue_(), and leafDatabase_.

Referenced by _clearValue_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _downdateScore_()

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

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

Definition at line 201 of file imddi_tpl.h.

203 {
204 if (!this->nodeId2Database_[nody]->isTestRelevant(var)) return;
207 vs.downdateScore(var,
210 }

References _nbTotalObservation_, gum::VariableSelector::downdateScore(), and gum::IncrementalGraphLearner< AttributeSelection, false >::nodeId2Database_.

Referenced by _updateNodeSet_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _insertLeafInFunctionGraph_() [1/2]

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

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

Definition at line 403 of file imddi_tpl.h.

404 {
406 = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * this->value_->domainSize()));
407 for (Idx modality = 0; modality < this->value_->domainSize(); ++modality) {
408 double newVal = 0.0;
409 if (leaf->total()) newVal = (double)leaf->effectif(modality) / (double)leaf->total();
410 sonsMap[modality] = this->target_->manager()->addTerminalNode(newVal);
411 }
412 return this->target_->manager()->addInternalNode(this->value_, sonsMap);
413 }
#define SOA_ALLOCATE(x)

References gum::AbstractLeaf::effectif(), SOA_ALLOCATE, gum::IncrementalGraphLearner< AttributeSelection, false >::target_, gum::AbstractLeaf::total(), and gum::IncrementalGraphLearner< AttributeSelection, false >::value_.

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< true >  )
private

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

Definition at line 389 of file imddi_tpl.h.

390 {
391 double value = 0.0;
392 for (Idx moda = 0; moda < leaf->nbModa(); moda++) {
393 value += (double)leaf->effectif(moda) * this->valueAssumed_.atPos(moda);
394 }
395 if (leaf->total()) value /= (double)leaf->total();
396 return this->target_->manager()->addTerminalNode(value);
397 }

References gum::AbstractLeaf::effectif(), gum::AbstractLeaf::nbModa(), gum::IncrementalGraphLearner< AttributeSelection, false >::target_, gum::AbstractLeaf::total(), and gum::IncrementalGraphLearner< AttributeSelection, false >::valueAssumed_.

Referenced by _rebuildFunctionGraph_().

Here is the call graph for this function:
Here is the caller 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 333 of file imddi_tpl.h.

333 {
334 // *******************************************************************************************************
335 // Mise à jour de l'aggregateur de feuille
336 _lg_.update();
337
338 // *******************************************************************************************************
339 // Reinitialisation du Graphe de Décision
340 this->target_->clear();
341 for (auto varIter = _varOrder_.beginSafe(); varIter != _varOrder_.endSafe(); ++varIter)
342 this->target_->add(**varIter);
343 this->target_->add(*this->value_);
344
346
347 // *******************************************************************************************************
348 // Insertion des feuilles
352 = treeNode2leaf.cbeginSafe();
353 treeNodeIter != treeNode2leaf.cendSafe();
354 ++treeNodeIter) {
355 if (!leaf2DGNode.exists(treeNodeIter.val()))
356 leaf2DGNode.insert(treeNodeIter.val(),
358
359 toTarget.insert(treeNodeIter.key(), leaf2DGNode[treeNodeIter.val()]);
360 }
361
362 // *******************************************************************************************************
363 // Insertion des noeuds internes (avec vérification des possibilités de
364 // fusion)
366 varIter != _varOrder_.rendSafe();
367 --varIter) {
369 curNodeIter = curNodeIter->nextLink()) {
371 = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * (*varIter)->domainSize()));
372 for (Idx modality = 0; modality < (*varIter)->domainSize(); ++modality)
374 toTarget.insert(curNodeIter->element(),
376 }
377 }
378
379 // *******************************************************************************************************
380 // Polish
381 this->target_->manager()->setRootNode(toTarget[this->root_]);
382 this->target_->manager()->clean();
383 }
NodeId _insertLeafInFunctionGraph_(AbstractLeaf *, Int2Type< true >)
Computes the score of the given variables for the given node.
Definition imddi_tpl.h:389
Sequence< const DiscreteVariable * > _varOrder_
Definition imddi.h:177
HashTable< const DiscreteVariable *, LinkedList< NodeId > * > var2Node_
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
MultiDimFunctionGraphManager< GUM_ELEMENT, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.

References _insertLeafInFunctionGraph_(), _lg_, _varOrder_, gum::HashTable< Key, Val >::cbeginSafe(), gum::HashTable< Key, Val >::cendSafe(), gum::HashTable< Key, Val >::exists(), gum::HashTable< Key, Val >::insert(), gum::IncrementalGraphLearner< AttributeSelection, false >::nodeSonsMap_, gum::IncrementalGraphLearner< AttributeSelection, false >::root_, SOA_ALLOCATE, gum::IncrementalGraphLearner< AttributeSelection, false >::target_, gum::IncrementalGraphLearner< AttributeSelection, false >::value_, and gum::IncrementalGraphLearner< AttributeSelection, false >::var2Node_.

Referenced by updateFunctionGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _removeLeaf_()

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

Adds a new observation to the structure.

Definition at line 311 of file imddi_tpl.h.

311 {
312 _lg_.removeLeaf(_leafMap_[currentNodeId]);
313 delete _leafMap_[currentNodeId];
315 }

References _leafMap_, and _lg_.

Referenced by chgNodeBoundVar_(), and removeNode_().

Here is the caller graph for this function:

◆ _updateNodeSet_()

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

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

Definition at line 218 of file imddi_tpl.h.

220 {
222 nodeSet.clear();
224 nodeIter != oldNodeSet.endSafe();
225 ++nodeIter) {
230
231 // Then we subtract the from the score given to each variables the
232 // quantity given by this node
233 for (vs.begin(); vs.hasNext(); vs.next()) {
234 _downdateScore_(vs.current(), *nodeIter, vs);
235 }
236
237 // And finally we add all its child to the new set of nodes
238 // and updates the remaining var's score
239 for (Idx modality = 0; modality < this->nodeVarMap_[*nodeIter]->domainSize(); ++modality) {
241 nodeSet << sonId;
242
243 for (vs.begin(); vs.hasNext(); vs.next()) {
244 _updateScore_(vs.current(), sonId, vs);
245 }
246 }
247 } else {
248 nodeSet << *nodeIter;
249 }
250 }
251 }
void _updateScore_(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition imddi_tpl.h:189
void _downdateScore_(const DiscreteVariable *, NodeId, VariableSelector &vs)
Computes the score of the given variables for the given node.
Definition imddi_tpl.h:201
virtual void transpose_(NodeId, const DiscreteVariable *)
HashTable< NodeId, const DiscreteVariable * > nodeVarMap_

References _attributeSelectionThreshold_, _downdateScore_(), _updateScore_(), gum::VariableSelector::begin(), gum::Set< Key >::beginSafe(), gum::Set< Key >::clear(), gum::VariableSelector::current(), gum::Set< Key >::endSafe(), gum::VariableSelector::hasNext(), gum::VariableSelector::next(), gum::IncrementalGraphLearner< AttributeSelection, false >::nodeId2Database_, gum::IncrementalGraphLearner< AttributeSelection, false >::nodeSonsMap_, gum::IncrementalGraphLearner< AttributeSelection, false >::nodeVarMap_, and gum::IncrementalGraphLearner< AttributeSelection, false >::transpose_().

Referenced by updateGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _updateScore_()

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

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

Definition at line 189 of file imddi_tpl.h.

191 {
192 if (!this->nodeId2Database_[nody]->isTestRelevant(var)) return;
195 vs.updateScore(var,
198 }

References _nbTotalObservation_, gum::IncrementalGraphLearner< AttributeSelection, false >::nodeId2Database_, and gum::VariableSelector::updateScore().

Referenced by _updateNodeSet_(), and updateGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addObservation()

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

Adds a new observation to the structure.

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

Definition at line 122 of file imddi_tpl.h.

122 {
125 }
virtual void addObservation(const Observation *obs)
Inserts a new observation.

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

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 )
overrideprotectedvirtual

Adds a new observation to the structure.

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

Definition at line 275 of file imddi_tpl.h.

276 {
278
280 desiredVar);
281
283 }
void _removeLeaf_(NodeId)
Adds a new observation to the structure.
Definition imddi_tpl.h:311
virtual void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Changes the associated variable of a node.

References _addLeaf_(), _removeLeaf_(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::chgNodeBoundVar_(), gum::IncrementalGraphLearner< AttributeSelection, false >::nodeVarMap_, and gum::IncrementalGraphLearner< AttributeSelection, false >::value_.

Here is the call graph for this function:

◆ convertNode2Leaf_()

void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::convertNode2Leaf_ ( NodeId currentNodeId)
protectedvirtualinherited

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

Definition at line 218 of file incrementalGraphLearner_tpl.h.

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

Here is the caller graph for this function:

◆ insertInternalNode_()

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

380 {
383 return newNodeId;
384 }
virtual NodeId insertNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)

References nodeVarMap_, and value_.

◆ insertLeafNode_()

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

Adds a new observation to the structure.

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

Definition at line 257 of file imddi_tpl.h.

260 {
263 boundVar,
264 obsSet);
265
267
268 return currentNodeId;
269 }
virtual NodeId insertLeafNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
inserts a new leaf node in internal graohs

References _addLeaf_(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::insertLeafNode_().

Here is the call graph for this function:

◆ insertNode_()

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

356 {
357 NodeId newNodeId = model_.addNode();
360 var2Node_[boundVar]->addLink(newNodeId);
361
362 needUpdate_ = true;
363
364 return newNodeId;
365 }

References chgNodeBoundVar_(), and value_.

Here is the call graph for this function:

◆ insertSetOfVars()

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

Implements gum::IVisitableGraphLearner.

Definition at line 416 of file imddi_tpl.h.

417 {
419 varIter != _varOrder_.endSafe();
420 ++varIter)
421 ret->add(**varIter);
422 }

References _varOrder_, and gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::add().

Here is the call graph for this function:

◆ isTerminal()

bool gum::IncrementalGraphLearner< AttributeSelection, isScalar >::isTerminal ( NodeId ni) const
overridevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 307 of file incrementalGraphLearner_tpl.h.

535 {
536 return !this->nodeSonsMap_.exists(ni);
537 }

◆ nodeNbObservation()

Idx gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeNbObservation ( NodeId ni) const
overridevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 313 of file incrementalGraphLearner_tpl.h.

552 {
553 return this->nodeId2Database_[ni]->nbObservation();
554 }

◆ nodeSon()

NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeSon ( NodeId ni,
Idx modality ) const
overridevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 311 of file incrementalGraphLearner_tpl.h.

547 {
548 return this->nodeSonsMap_[ni][modality];
549 }

◆ nodeVar()

const DiscreteVariable * gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeVar ( NodeId ni) const
overridevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 309 of file incrementalGraphLearner_tpl.h.

541 {
542 return this->nodeVarMap_[ni];
543 }

◆ removeNode_()

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

Adds a new observation to the structure.

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

Definition at line 289 of file imddi_tpl.h.

References _removeLeaf_(), gum::IncrementalGraphLearner< AttributeSelection, false >::nodeVarMap_, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::removeNode_(), and gum::IncrementalGraphLearner< AttributeSelection, false >::value_.

Here is the call graph for this function:

◆ root()

NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::root ( ) const
overridevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 305 of file incrementalGraphLearner_tpl.h.

530 {
531 return this->root_;
532 }

◆ size()

Size gum::IncrementalGraphLearner< AttributeSelection, isScalar >::size ( )
inherited

Definition at line 303 of file incrementalGraphLearner_tpl.h.

References nodeSonsMap_, nodeVarMap_, and transpose_().

Here is the call graph for this function:

◆ transpose_()

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

246 {
247 // **************************************************************************************
248 // Si le noeud courant contient déjà la variable qu'on souhaite lui amener
249 // Il n'y a rien à faire
250 if (nodeVarMap_[currentNodeId] == desiredVar) { return; }
251
252 // **************************************************************************************
253 // Si le noeud courant est terminal,
254 // Il faut artificiellement insérer un noeud liant à la variable
256 // We turned this leaf into an internal node.
257 // This mean that we'll need to install children leaves for each value of
258 // desiredVar
259
260 // First We must prepare these new leaves NodeDatabases and Sets<const
261 // Observation*>
266 SOA_ALLOCATE(sizeof(Set< const Observation* >*) * desiredVar->domainSize()));
267 for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality) {
270 }
273 leafDatabase_[currentNodeId]->endSafe() != obsIter;
274 ++obsIter) {
277 }
278
279 // Then we can install each new leaves (and put in place the sonsMap)
281 = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
282 for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality)
284
285 // Some necessary clean up
288 * desiredVar->domainSize());
290
291 // And finally we can turn the node into an internal node associated to
292 // desiredVar
295
296 return;
297 }
298
299 // *************************************************************************************
300 // Remains the general case where currentNodeId is an internal node.
301
302 // First we ensure that children node use desiredVar as variable
303 for (Idx modality = 0; modality < nodeVarMap_[currentNodeId]->domainSize(); ++modality)
305
306 // Sequence<NodeDatabase<AttributeSelection, isScalar>*>
307 // sonsNodeDatabase =
308 // nodeId2Database_[currentNodeId]->splitOnVar(desiredVar);
310 = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
311
312 // Then we create the new mapping
313 for (Idx desiredVarModality = 0; desiredVarModality < desiredVar->domainSize();
315 NodeId* grandSonsMap = static_cast< NodeId* >(
319 for (Idx currentVarModality = 0;
325 }
326
329 }
330
331 // Finally we clean the old remaining nodes
335 }
336
337 // We suppress the old sons map and remap to the new one
341
343 }
virtual NodeId insertInternalNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)

References convertNode2Leaf_(), leafDatabase_, nodeSonsMap_, nodeVarMap_, and removeNode_().

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_updateNodeSet_(), and size().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateFunctionGraph()

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

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

Implements gum::IncrementalGraphLearner< AttributeSelection, false >.

Definition at line 322 of file imddi_tpl.h.

322 {
323 // if( _lg_.needsUpdate() || this->needUpdate_ ){
325 this->needUpdate_ = false;
326 // }
327 }
void _rebuildFunctionGraph_()
Computes the score of the given variables for the given node.
Definition imddi_tpl.h:333

References _rebuildFunctionGraph_(), and gum::IncrementalGraphLearner< AttributeSelection, false >::needUpdate_.

Here is the call graph for this function:

◆ updateGraph()

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

Updates the tree after a new observation has been added.

Implements gum::IncrementalGraphLearner< AttributeSelection, false >.

Definition at line 140 of file imddi_tpl.h.

140 {
141 _varOrder_.clear();
142
143 // First xe initialize the node set which will give us the scores
145 currentNodeSet.insert(this->root_);
146
147 // Then we initialize the pool of variables to consider
149 for (vs.begin(); vs.hasNext(); vs.next()) {
150 _updateScore_(vs.current(), this->root_, vs);
151 }
152
153 // Then, until there's no node remaining
154 while (!vs.isEmpty()) {
155 // We select the best var
156 const DiscreteVariable* selectedVar = vs.select();
157 _varOrder_.insert(selectedVar);
158
159 // Then we decide if we update each node according to this var
161 }
162
163 // If there are remaining node that are not leaves after we establish the
164 // var order
165 // these nodes are turned into leaf.
167 nodeIter != currentNodeSet.endSafe();
168 ++nodeIter)
170
171
172 if (_lg_.needsUpdate()) _lg_.update();
173 }
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:218

References _lg_, _updateNodeSet_(), _updateScore_(), _varOrder_, gum::VariableSelector::begin(), gum::Set< Key >::beginSafe(), gum::IncrementalGraphLearner< AttributeSelection, false >::convertNode2Leaf_(), gum::VariableSelector::current(), gum::Set< Key >::endSafe(), gum::VariableSelector::hasNext(), gum::Set< Key >::insert(), gum::VariableSelector::isEmpty(), gum::VariableSelector::next(), gum::IncrementalGraphLearner< AttributeSelection, false >::root_, gum::VariableSelector::select(), and gum::IncrementalGraphLearner< AttributeSelection, false >::setOfVars_.

Here is the call graph for this function:

◆ updateNode_()

void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateNode_ ( NodeId updatedNode,
gum::VariableSet & 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 213 of file incrementalGraphLearner_tpl.h.

190 {
191 // If this node has no interesting variable, we turn it into a leaf
192 if (varsOfInterest.empty()) {
194 return;
195 }
196
197 // If this node has already one of the best variable intalled as test, we
198 // move on
200 return;
201 }
202
203 // In any other case we have to install variable as best test
206 for (varIter = varsOfInterest.cbeginSafe(), basc = 0;
207 varIter != varsOfInterest.cendSafe() && basc < randy;
208 ++varIter, basc++)
209 ;
210
212 }
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.

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

Here is the caller graph for this function:

◆ updateNodeWithObservation_()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IMDDI< AttributeSelection, isScalar >::updateNodeWithObservation_ ( const Observation * newObs,
NodeId currentNodeId )
overrideprotectedvirtual

Adds a new observation to the structure.

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

Definition at line 128 of file imddi_tpl.h.

129 {
131 newObs,
133 if (this->nodeVarMap_[currentNodeId] == this->value_) _lg_.updateLeaf(_leafMap_[currentNodeId]);
134 }
virtual void updateNodeWithObservation_(const Observation *newObs, NodeId currentNodeId)
Will update internal graph's NodeDatabase of given node with the new observation.

References _leafMap_, _lg_, gum::IncrementalGraphLearner< AttributeSelection, false >::nodeVarMap_, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateNodeWithObservation_(), and gum::IncrementalGraphLearner< AttributeSelection, false >::value_.

Here is the call graph for this function:

◆ updateVar()

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

168 {
170 Link< NodeId >* nni = nullptr;
171 while (nodIter) {
172 nni = nodIter->nextLink();
173 convertNode2Leaf_(nodIter->element());
174 nodIter = nni;
175 }
176 }

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 187 of file imddi.h.

Referenced by IMDDI(), IMDDI(), and _updateNodeSet_().

◆ _leafMap_

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

Definition at line 181 of file imddi.h.

Referenced by ~IMDDI(), _addLeaf_(), _removeLeaf_(), and updateNodeWithObservation_().

◆ _lg_

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

◆ _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 184 of file imddi.h.

Referenced by IMDDI(), IMDDI(), _downdateScore_(), _updateScore_(), and addObservation().

◆ _varOrder_

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

Definition at line 177 of file imddi.h.

Referenced by _rebuildFunctionGraph_(), insertSetOfVars(), and updateGraph().

◆ leafDatabase_

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 364 of file incrementalGraphLearner.h.

Referenced by _assumeValue_(), _clearValue_(), and transpose_().

◆ model_

NodeGraphPart gum::IncrementalGraphLearner< AttributeSelection, isScalar >::model_
protectedinherited

◆ needUpdate_

bool gum::IncrementalGraphLearner< AttributeSelection, isScalar >::needUpdate_
protectedinherited

◆ nodeId2Database_

◆ nodeSonsMap_

◆ nodeVarMap_

◆ root_

◆ setOfVars_

◆ target_

◆ value_

◆ valueAssumed_

◆ var2Node_

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 352 of file incrementalGraphLearner.h.

Referenced by ~IncrementalGraphLearner(), and gum::IMDDI< AttributeSelection, isScalar >::_rebuildFunctionGraph_().


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