aGrUM 2.3.2
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
Size size ()
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 ()
 Default destructor.
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.
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 *)
 Adds a new observation to the structure.
void updateGraph ()
 Updates the tree after a new observation has been added.
void updateNodeWithObservation_ (const Observation *newObs, NodeId currentNodeId)
 Adds a new observation to the structure.
NodeId insertLeafNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *sonsMap)
 Adds a new observation to the structure.
void chgNodeBoundVar_ (NodeId chgedNodeId, const DiscreteVariable *desiredVar)
 Adds a new observation to the structure.
void removeNode_ (NodeId removedNodeId)
 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 ()
 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 74 of file imddi_tpl.h.

78 :
83 _addLeaf_(this->root_);
84 }
void _addLeaf_(NodeId)
Adds a new observation to the structure.
Definition imddi_tpl.h:297
Idx _nbTotalObservation_
The total number of observation added to this tree.
Definition imddi.h:189
IMDDI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, double pairSelectionThreshold, gum::VariableSet attributeListe, const DiscreteVariable *learnedValue)
Variable Learner constructor.
Definition imddi_tpl.h:74
LeafAggregator _lg_
Definition imddi.h:184
double _attributeSelectionThreshold_
The threshold above which we consider variables to be dependant.
Definition imddi.h:192
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 ( )

Default destructor.

Definition at line 108 of file imddi_tpl.h.

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

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

297 {
298 _leafMap_.insert(
302 &(this->valueAssumed_)));
303 _lg_.addLeaf(_leafMap_[currentNodeId]);
304 }
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)
inlineprivateinherited

Get value assumed by studied variable for current observation.

Definition at line 153 of file incrementalGraphLearner.h.

<agrum/FMDP/learning/datastructure/incrementalGraphLearner>

◆ _branchObs_()

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

Seek modality assumed in obs for given var.

Definition at line 168 of file incrementalGraphLearner.h.

168 {
170 }
Idx _branchObs_(const Observation *obs, const DiscreteVariable *var)

Referenced by addObservation(), and insertLeafNode_().

Here is the caller graph for this function:

◆ _clearValue_()

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

Template function dispatcher.

Definition at line 117 of file incrementalGraphLearner.h.

Referenced by ~IncrementalGraphLearner().

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

202 {
203 if (!this->nodeId2Database_[nody]->isTestRelevant(var)) return;
206 vs.downdateScore(var,
209 }

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

403 {
405 = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * this->value_->domainSize()));
406 for (Idx modality = 0; modality < this->value_->domainSize(); ++modality) {
407 double newVal = 0.0;
408 if (leaf->total()) newVal = (double)leaf->effectif(modality) / (double)leaf->total();
409 sonsMap[modality] = this->target_->manager()->addTerminalNode(newVal);
410 }
411 return this->target_->manager()->addInternalNode(this->value_, sonsMap);
412 }
#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 388 of file imddi_tpl.h.

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

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

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

310 {
311 _lg_.removeLeaf(_leafMap_[currentNodeId]);
312 delete _leafMap_[currentNodeId];
314 }

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

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

190 {
191 if (!this->nodeId2Database_[nody]->isTestRelevant(var)) return;
194 vs.updateScore(var,
197 }

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

Adds a new observation to the structure.

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

Definition at line 121 of file imddi_tpl.h.

121 {
124 }
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 )
protectedvirtual

Adds a new observation to the structure.

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

Definition at line 274 of file imddi_tpl.h.

275 {
277
279 desiredVar);
280
282 }
void _removeLeaf_(NodeId)
Adds a new observation to the structure.
Definition imddi_tpl.h:310
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 230 of file incrementalGraphLearner_tpl.h.

References chgNodeBoundVar_(), nodeSonsMap_, nodeVarMap_, and value_.

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

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

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

References setOfVars_, 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 )
protectedvirtual

Adds a new observation to the structure.

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

Definition at line 256 of file imddi_tpl.h.

259 {
262 boundVar,
263 obsSet);
264
266
267 return currentNodeId;
268 }
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 246 of file incrementalGraphLearner_tpl.h.

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

References nodeVarMap_.

◆ insertSetOfVars()

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

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

Definition at line 174 of file imddi.h.

174 {
176 varIter != _varOrder_.endSafe();
177 ++varIter)
178 ret->add(**varIter);
179 }

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

Here is the call graph for this function:

◆ isTerminal()

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

Implements gum::IVisitableGraphLearner.

Definition at line 329 of file incrementalGraphLearner.h.

329{ return !this->nodeSonsMap_.exists(ni); }

◆ nodeNbObservation()

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

Implements gum::IVisitableGraphLearner.

Definition at line 344 of file incrementalGraphLearner.h.

344{ return this->nodeId2Database_[ni]->nbObservation(); }

◆ nodeSon()

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

Implements gum::IVisitableGraphLearner.

Definition at line 339 of file incrementalGraphLearner.h.

339{ return this->nodeSonsMap_[ni][modality]; }

◆ nodeVar()

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

Implements gum::IVisitableGraphLearner.

Definition at line 334 of file incrementalGraphLearner.h.

334{ return this->nodeVarMap_[ni]; }

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

Definition at line 288 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
inlinevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 324 of file incrementalGraphLearner.h.

324{ return this->root_; }

◆ size()

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

Definition at line 313 of file incrementalGraphLearner.h.

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

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

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

Here is the caller 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, false >.

Definition at line 321 of file imddi_tpl.h.

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

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 ( )
virtual

Updates the tree after a new observation has been added.

Implements gum::IncrementalGraphLearner< AttributeSelection, false >.

Definition at line 139 of file imddi_tpl.h.

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

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

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

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

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

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

◆ updateNodeWithObservation_()

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

Adds a new observation to the structure.

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

Definition at line 127 of file imddi_tpl.h.

128 {
130 newObs,
132 if (this->nodeVarMap_[currentNodeId] == this->value_) _lg_.updateLeaf(_leafMap_[currentNodeId]);
133 }
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 207 of file incrementalGraphLearner_tpl.h.

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

References transpose_().

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 192 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 186 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 189 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 182 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 403 of file incrementalGraphLearner.h.

Referenced by ~IncrementalGraphLearner(), insertLeafNode_(), and updateNode_().

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

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


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