aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::ITI< AttributeSelection, isScalar > Class Template Reference

Learn a graphical representation of a function as a decision tree. More...

#include <agrum/FMDP/planning/FunctionGraph/iti.h>

Inheritance diagram for gum::ITI< AttributeSelection, isScalar >:
Collaboration diagram for gum::ITI< AttributeSelection, isScalar >:

Public Member Functions

Constructor & destructor.
 ITI (MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, gum::VariableSet attributeListe, const DiscreteVariable *learnedValue)
 ITI constructor for functions describing the behaviour of one variable according to a set of other variable such as conditionnal probabilities.
 ITI (MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, gum::VariableSet attributeListe)
 ITI constructeur for real functions.
 ~ITI () 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
void insertSetOfVars (MultiDimFunctionGraph< double > *ret) const override

Protected Member Functions

Function Graph Updating methods
void insertSetOfVars_ (MultiDimFunctionGraph< double > *ret)
 insertSetOfVars_

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

HashTable< NodeId, bool_staleTable_
 Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpose) The aim is not if we have revise the installed variable on that node.
Idx _nbTotalObservation_
 The total number of observation added to this tree.
double _attributeSelectionThreshold_
 The threshold above which we consider variables to be dependant.

New Observation insertion methods

void addObservation (const Observation *obs) override
 Inserts a new observation.
void updateNodeWithObservation_ (const Observation *newObs, NodeId currentNodeId) override
 Will update internal graph's NodeDatabase of given node with the new observation.

Graph Structure update methods

void updateGraph () override
 Updates the internal graph after a new observation has been added.
NodeId insertNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar) override
 inserts a new node in internal graph
void chgNodeBoundVar_ (NodeId chgedNodeId, const DiscreteVariable *desiredVar) override
 Changes the associated variable of a node.
void removeNode_ (NodeId removedNodeId) override
 Removes a node from the internal graph.

Function Graph Updating methods

void updateFunctionGraph () override
 Updates target to currently learned graph structure.
NodeId _insertNodeInFunctionGraph_ (NodeId src)
 Inserts an internal node in the target.
NodeId _insertTerminalNode_ (NodeId src)
 Insert a terminal node in the target.
NodeId _insertTerminalNode_ (NodeId src, Int2Type< true >)
 Insert a terminal node in the target.
NodeId _insertTerminalNode_ (NodeId src, Int2Type< false >)
 Insert a terminal node in the target.

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 insertInternalNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
 inserts a new internal node in internal graph
virtual NodeId insertLeafNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
 inserts a new leaf node in internal graohs

Detailed Description

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

Learn a graphical representation of a function as a decision tree.

This learning is done incrementaly. Hence first observation are add to the structure and then the structure is updated. Maintains two graph function : one internal for the learning and a target which is updated on demand.

Definition at line 79 of file iti.h.

Member Typedef Documentation

◆ ValueType

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

Definition at line 84 of file incrementalGraphLearner.h.

Constructor & Destructor Documentation

◆ ITI() [1/2]

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

ITI constructor for functions describing the behaviour of one variable according to a set of other variable such as conditionnal probabilities.

Parameters
target: the MultiDimFunctionGraph in which we load the structure
attributeSelectionThreshold: threshold under which a node is not installed (pe-pruning)
attributeListe: Set of vars on which we rely to explain the behaviour of learned variable
learnedValue: the variable from which we try to learn the behaviour
target: the MultiDimFunctionGraph in which we load the structure
attributeSelectionThreshold: threshold under which a node is not installed (pe-pruning)
temporaryAPIfix: Issue in API in regard to IMDDI
attributeListe: Set of vars on which we rely to explain the behaviour of learned variable
learnedValue: the variable from which we try to learn the behaviour

Definition at line 85 of file iti_tpl.h.

88 :
92 _staleTable_.insert(this->root_, false);
93 }
Learn a graphical representation of a function as a decision tree.
Definition iti.h:79
double _attributeSelectionThreshold_
The threshold above which we consider variables to be dependant.
Definition iti.h:272
HashTable< NodeId, bool > _staleTable_
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition iti.h:266
Idx _nbTotalObservation_
The total number of observation added to this tree.
Definition iti.h:269
ITI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, gum::VariableSet attributeListe, const DiscreteVariable *learnedValue)
ITI constructor for functions describing the behaviour of one variable according to a set of other va...
Definition iti_tpl.h:85
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, gum::VariableSet attributesSet, const DiscreteVariable *learnVariable)

References gum::IncrementalGraphLearner< AttributeSelection, false >::IncrementalGraphLearner(), ITI(), _attributeSelectionThreshold_, _nbTotalObservation_, _staleTable_, and gum::IncrementalGraphLearner< AttributeSelection, false >::root_.

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

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

◆ ITI() [2/2]

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

ITI constructeur for real functions.

We try to predict the output of a function f given a set of variable

Parameters
target: the MultiDimFunctionGraph in which we load the structure
attributeSelectionThreshold: threshold under which a node is not installed (pe-pruning)
attributeListe: Set of vars on which we rely to explain the behaviour of learned function

We try to predict the output of a function f given a set of variable

Parameters
target: the MultiDimFunctionGraph in which we load the structure
attributeSelectionThreshold: threshold under which a node is not installed (pe-pruning)
temporaryAPIfix: Issue in API in regard to IMDDI
attributeListeSetof vars on which we rely to explain the behaviour of learned function

Definition at line 108 of file iti_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, false >::IncrementalGraphLearner(), ITI(), _attributeSelectionThreshold_, _nbTotalObservation_, _staleTable_, and gum::IncrementalGraphLearner< AttributeSelection, false >::root_.

Here is the call graph for this function:

◆ ~ITI()

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

Default destructor.

Definition at line 353 of file iti_tpl.h.

353 {
355 ;
356 }

References ITI().

Here is the call graph for this function:

Member Function Documentation

◆ _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:

◆ _insertNodeInFunctionGraph_()

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::ITI< AttributeSelection, isScalar >::_insertNodeInFunctionGraph_ ( NodeId currentNodeId)
private

Inserts an internal node in the target.

Parameters
srcthe source node in internal graph
Returns
the mathcing node id in the target
Parameters
thesource node in internal graph
Returns
the mathcing node id in the target

Definition at line 280 of file iti_tpl.h.

280 {
281 if (this->nodeVarMap_[currentNodeId] == this->value_) {
283 return nody;
284 }
285
286 if (!this->target_->variablesSequence().exists(this->nodeVarMap_[currentNodeId])) {
287 this->target_->add(*(this->nodeVarMap_[currentNodeId]));
288 }
289
290 NodeId nody = this->target_->manager()->addInternalNode(this->nodeVarMap_[currentNodeId]);
291 for (Idx moda = 0; moda < this->nodeVarMap_[currentNodeId]->domainSize(); ++moda) {
293 this->target_->manager()->setSon(nody, moda, son);
294 }
295
296 return nody;
297 }
NodeId _insertTerminalNode_(NodeId src)
Insert a terminal node in the target.
Definition iti_tpl.h:359
NodeId _insertNodeInFunctionGraph_(NodeId src)
Inserts an internal node in the target.
Definition iti_tpl.h:280
HashTable< NodeId, const DiscreteVariable * > nodeVarMap_

References _insertNodeInFunctionGraph_(), _insertTerminalNode_(), gum::IncrementalGraphLearner< AttributeSelection, false >::nodeSonsMap_, gum::IncrementalGraphLearner< AttributeSelection, false >::nodeVarMap_, gum::IncrementalGraphLearner< AttributeSelection, false >::target_, and gum::IncrementalGraphLearner< AttributeSelection, false >::value_.

Referenced by _insertNodeInFunctionGraph_(), and updateFunctionGraph().

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

◆ _insertTerminalNode_() [1/3]

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::ITI< AttributeSelection, isScalar >::_insertTerminalNode_ ( NodeId src)
private

Insert a terminal node in the target.

This function is a dispatcher that will call the right function according to the value of the template isScalar

Parameters
srcthe source node in the learned graph
Returns
the matching node in the target

Definition at line 359 of file iti_tpl.h.

359 {
361 }

References _insertTerminalNode_().

Referenced by _insertNodeInFunctionGraph_(), and _insertTerminalNode_().

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

◆ _insertTerminalNode_() [2/3]

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::ITI< AttributeSelection, isScalar >::_insertTerminalNode_ ( NodeId currentNodeId,
Int2Type< false >  )
private

Insert a terminal node in the target.

This function is called if we're learning the behaviour of a variable. Inserts then this variable and the relevant value beneath into target.

Parameters
srcthe source node in the learned graph
Returns
the matching node in the target

This function is called if we're learning a real value function. Inserts then a single value in target.

Parameters
thesource node in the learned graph
Returns
the matching node in the target

Definition at line 309 of file iti_tpl.h.

310 {
311 if (!this->target_->variablesSequence().exists(this->value_))
312 this->target_->add(*(this->value_));
313
314 Size tot = this->nodeId2Database_[currentNodeId]->nbObservation();
315 if (tot == Size(0)) return this->target_->manager()->addTerminalNode(0.0);
316
318 = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * this->value_->domainSize()));
319 for (Idx modality = 0; modality < this->value_->domainSize(); ++modality) {
320 double newVal = 0.0;
322 sonsMap[modality] = this->target_->manager()->addTerminalNode(newVal);
323 }
324 NodeId nody = this->target_->manager()->addInternalNode(this->value_, sonsMap);
325 return nody;
326 }
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > * > nodeId2Database_
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
#define SOA_ALLOCATE(x)

References gum::IncrementalGraphLearner< AttributeSelection, false >::nodeId2Database_, SOA_ALLOCATE, gum::IncrementalGraphLearner< AttributeSelection, false >::target_, and gum::IncrementalGraphLearner< AttributeSelection, false >::value_.

◆ _insertTerminalNode_() [3/3]

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::ITI< AttributeSelection, isScalar >::_insertTerminalNode_ ( NodeId currentNodeId,
Int2Type< true >  )
private

Insert a terminal node in the target.

This function is called if we're learning a real value function. Inserts then a single value in target.

Parameters
srcthe source node in the learned graph
Returns
the matching node in the target

This function is called if we're learning the behaviour of a variable. Inserts then this variable and the relevant value beneath into target.

Parameters
thesource node in the learned graph
Returns
the matching node in the target

Definition at line 338 of file iti_tpl.h.

339 {
340 double value = 0.0;
342 valIter != this->nodeId2Database_[currentNodeId]->cendValues();
343 ++valIter) {
344 value += (double)valIter.key() * valIter.val();
345 }
348 NodeId nody = this->target_->manager()->addTerminalNode(value);
349 return nody;
350 }

References gum::IncrementalGraphLearner< AttributeSelection, false >::nodeId2Database_, and gum::IncrementalGraphLearner< AttributeSelection, false >::target_.

◆ addObservation()

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

Inserts a new observation.

Parameters
obsthe new observation to learn
thenew observation to learn

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

Definition at line 131 of file iti_tpl.h.

131 {
134 }
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::ITI< AttributeSelection, isScalar >::chgNodeBoundVar_ ( NodeId currentNodeId,
const DiscreteVariable * desiredVar )
overrideprotectedvirtual

Changes the associated variable of a node.

Parameters
chgedNodeId: the node to change
desiredVar: its new associated variable

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

Definition at line 238 of file iti_tpl.h.

239 {
240 if (this->nodeVarMap_[currentNodeId] != desiredVar) {
243 desiredVar);
244 }
245 }
virtual void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Changes the associated variable of a node.

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

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

NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::insertLeafNode_ ( NodeDatabase< AttributeSelection, isScalar > * nDB,
const DiscreteVariable * boundVar,
Set< const Observation * > * obsSet )
protectedvirtualinherited

inserts a new leaf node in internal graohs

Parameters
nDB: the associated database
boundVar: the associated variable
obsSet: the set of observation this leaf retains
Returns
the newly created node's id

Reimplemented in gum::IMDDI< AttributeSelection, isScalar >.

Definition at line 259 of file incrementalGraphLearner_tpl.h.

399 {
402 return newNodeId;
403 }

References setOfVars_, and value_.

Referenced by removeNode_().

Here is the caller graph for this function:

◆ insertNode_()

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::ITI< AttributeSelection, isScalar >::insertNode_ ( NodeDatabase< AttributeSelection, isScalar > * nDB,
const DiscreteVariable * boundVar )
overrideprotectedvirtual

inserts a new node in internal graph

inserts a new node in internal graohs

Parameters
nDB: the associated database
boundVar: the associated variable
Returns
the newly created node's id

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

Definition at line 222 of file iti_tpl.h.

References _staleTable_, and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::insertNode_().

Here is the call graph for this function:

◆ insertSetOfVars()

void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::insertSetOfVars ( MultiDimFunctionGraph< double > * ret) const
overridevirtualinherited

Implements gum::IVisitableGraphLearner.

Definition at line 315 of file incrementalGraphLearner_tpl.h.

565 {
567 varIter != setOfVars_.endSafe();
568 ++varIter)
569 ret->add(**varIter);
570 }

References nodeId2Database_, nodeSonsMap_, nodeVarMap_, setOfVars_, and value_.

◆ insertSetOfVars_()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::ITI< AttributeSelection, isScalar >::insertSetOfVars_ ( MultiDimFunctionGraph< double > * ret)
protected

insertSetOfVars_

Parameters
ret

Definition at line 364 of file iti_tpl.h.

364 {
367 ++varIter)
368 ret->add(**varIter);
369 }
static const iterator_safe & endSafe() noexcept
The usual safe end iterator to parse the set.
Definition set_tpl.h:397

References gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::add(), and gum::IncrementalGraphLearner< AttributeSelection, false >::setOfVars_.

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::ITI< AttributeSelection, isScalar >::removeNode_ ( NodeId currentNodeId)
overrideprotectedvirtual

Removes a node from the internal graph.

Parameters
removedNodeId: the node to remove

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

Definition at line 254 of file iti_tpl.h.

References _staleTable_, and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::removeNode_().

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 void transpose_(NodeId, const DiscreteVariable *)
virtual NodeId insertLeafNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
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::ITI< AttributeSelection, isScalar >::updateFunctionGraph ( )
overridevirtual

Updates target to currently learned graph structure.

Implements gum::IncrementalGraphLearner< AttributeSelection, false >.

Definition at line 267 of file iti_tpl.h.

267 {
268 this->target_->clear();
269 this->target_->manager()->setRootNode(this->_insertNodeInFunctionGraph_(this->root_));
270 }

References _insertNodeInFunctionGraph_(), gum::IncrementalGraphLearner< AttributeSelection, false >::root_, and gum::IncrementalGraphLearner< AttributeSelection, false >::target_.

Here is the call graph for this function:

◆ updateGraph()

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

Updates the internal graph after a new observation has been added.

Implements gum::IncrementalGraphLearner< AttributeSelection, false >.

Definition at line 161 of file iti_tpl.h.

161 {
163 filo.push_back(this->root_);
165 tensorVars.insert(this->root_, new gum::VariableSet(this->setOfVars_));
166
167
168 while (!filo.empty()) {
169 NodeId currentNodeId = filo.back();
170 filo.pop_back();
171
172 // First we look for the best var to install on the node
175
177 varIter != tensorVars[currentNodeId]->cendSafe();
178 ++varIter)
180 double varValue = this->nodeId2Database_[currentNodeId]->testValue(*varIter);
181 if (varValue >= bestValue) {
182 if (varValue > bestValue) {
184 bestVars.clear();
185 }
186 bestVars.insert(*varIter);
187 }
188 }
189
190 // Then We installed Variable a test on that node
192
193 // The we move on the children if needed
194 if (this->nodeVarMap_[currentNodeId] != this->value_) {
195 for (Idx moda = 0; moda < this->nodeVarMap_[currentNodeId]->domainSize(); moda++) {
199 if (_staleTable_[sonId]) {
200 filo.push_back(sonId);
202 }
203 }
204 }
205 }
206
208 nodeIter != tensorVars.endSafe();
209 ++nodeIter)
210 delete nodeIter.val();
211 }
Set< const DiscreteVariable * > VariableSet

References _attributeSelectionThreshold_, _staleTable_, gum::HashTable< Key, Val >::beginSafe(), gum::HashTable< Key, Val >::cendSafe(), gum::Set< Key >::clear(), gum::HashTable< Key, Val >::endSafe(), gum::Set< Key >::erase(), gum::HashTable< Key, Val >::insert(), gum::Set< Key >::insert(), gum::IncrementalGraphLearner< AttributeSelection, false >::nodeId2Database_, gum::IncrementalGraphLearner< AttributeSelection, false >::nodeSonsMap_, gum::IncrementalGraphLearner< AttributeSelection, false >::nodeVarMap_, gum::IncrementalGraphLearner< AttributeSelection, false >::root_, gum::IncrementalGraphLearner< AttributeSelection, false >::setOfVars_, gum::IncrementalGraphLearner< AttributeSelection, false >::updateNode_(), and gum::IncrementalGraphLearner< AttributeSelection, false >::value_.

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::ITI< AttributeSelection, isScalar >::updateNodeWithObservation_ ( const Observation * newObs,
NodeId currentNodeId )
overrideprotectedvirtual

Will update internal graph's NodeDatabase of given node with the new observation.

Parameters
newObs
currentNodeId

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

Definition at line 145 of file iti_tpl.h.

146 {
148 newObs,
151 }
virtual void updateNodeWithObservation_(const Observation *newObs, NodeId currentNodeId)
Will update internal graph's NodeDatabase of given node with the new observation.

References _staleTable_, and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateNodeWithObservation_().

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::ITI< AttributeSelection, isScalar >::_attributeSelectionThreshold_
private

The threshold above which we consider variables to be dependant.

Definition at line 272 of file iti.h.

Referenced by ITI(), ITI(), and updateGraph().

◆ _nbTotalObservation_

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

The total number of observation added to this tree.

Definition at line 269 of file iti.h.

Referenced by ITI(), ITI(), and addObservation().

◆ _staleTable_

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, bool > gum::ITI< AttributeSelection, isScalar >::_staleTable_
private

Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpose) The aim is not if we have revise the installed variable on that node.

Definition at line 266 of file iti.h.

Referenced by ITI(), ITI(), chgNodeBoundVar_(), insertNode_(), removeNode_(), updateGraph(), and updateNodeWithObservation_().

◆ 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:
  • agrum/FMDP/learning/datastructure/iti.h
  • agrum/FMDP/learning/datastructure/iti_tpl.h