aGrUM 2.3.2
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

Size size ()
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 ()
 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
virtual void insertSetOfVars (MultiDimFunctionGraph< double > *ret) const

Protected Member Functions

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)
 Inserts a new observation.
void updateNodeWithObservation_ (const Observation *newObs, NodeId currentNodeId)
 Will update internal graph's NodeDatabase of given node with the new observation.

Graph Structure update methods

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

Function Graph Updating methods

void updateFunctionGraph ()
 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 84 of file iti_tpl.h.

87 :
91 _staleTable_.insert(this->root_, false);
92 }
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:282
HashTable< NodeId, bool > _staleTable_
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition iti.h:276
Idx _nbTotalObservation_
The total number of observation added to this tree.
Definition iti.h:279
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:84
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 107 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 = false>
gum::ITI< AttributeSelection, isScalar >::~ITI ( )
inline

Default destructor.

Definition at line 122 of file iti.h.

122 {
124 ;
125 }

References ITI().

Here is the call graph for this function:

Member Function Documentation

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

◆ _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 279 of file iti_tpl.h.

279 {
280 if (this->nodeVarMap_[currentNodeId] == this->value_) {
282 return nody;
283 }
284
285 if (!this->target_->variablesSequence().exists(this->nodeVarMap_[currentNodeId])) {
286 this->target_->add(*(this->nodeVarMap_[currentNodeId]));
287 }
288
289 NodeId nody = this->target_->manager()->addInternalNode(this->nodeVarMap_[currentNodeId]);
290 for (Idx moda = 0; moda < this->nodeVarMap_[currentNodeId]->domainSize(); ++moda) {
292 this->target_->manager()->setSon(nody, moda, son);
293 }
294
295 return nody;
296 }
NodeId _insertTerminalNode_(NodeId src)
Insert a terminal node in the target.
Definition iti.h:229
NodeId _insertNodeInFunctionGraph_(NodeId src)
Inserts an internal node in the target.
Definition iti_tpl.h:279
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 = false>
NodeId gum::ITI< AttributeSelection, isScalar >::_insertTerminalNode_ ( NodeId src)
inlineprivate

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 229 of file iti.h.

229 {
231 }

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

309 {
310 if (!this->target_->variablesSequence().exists(this->value_))
311 this->target_->add(*(this->value_));
312
313 Size tot = this->nodeId2Database_[currentNodeId]->nbObservation();
314 if (tot == Size(0)) return this->target_->manager()->addTerminalNode(0.0);
315
317 = static_cast< NodeId* >(SOA_ALLOCATE(sizeof(NodeId) * this->value_->domainSize()));
318 for (Idx modality = 0; modality < this->value_->domainSize(); ++modality) {
319 double newVal = 0.0;
321 sonsMap[modality] = this->target_->manager()->addTerminalNode(newVal);
322 }
323 NodeId nody = this->target_->manager()->addInternalNode(this->value_, sonsMap);
324 return nody;
325 }
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 337 of file iti_tpl.h.

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

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

Inserts a new observation.

Parameters
obsthe new observation to learn
thenew observation to learn

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

Definition at line 130 of file iti_tpl.h.

130 {
133 }
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 )
protectedvirtual

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 237 of file iti_tpl.h.

238 {
239 if (this->nodeVarMap_[currentNodeId] != desiredVar) {
242 desiredVar);
243 }
244 }
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 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_()

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

398 {
401 return newNodeId;
402 }

References _branchObs_(), gum::NodeDatabase< AttributeSelection, isScalar >::addObservation(), and leafDatabase_.

Referenced by chgNodeBoundVar_().

Here is the call graph for this function:
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 )
protectedvirtual

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 221 of file iti_tpl.h.

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

Here is the call graph for this function:

◆ insertSetOfVars()

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

Implements gum::IVisitableGraphLearner.

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

Definition at line 349 of file incrementalGraphLearner.h.

349 {
351 varIter != setOfVars_.endSafe();
352 ++varIter)
353 ret->add(**varIter);
354 }

◆ insertSetOfVars_()

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

insertSetOfVars_

Parameters
ret

Definition at line 265 of file iti.h.

265 {
268 ++varIter)
269 ret->add(**varIter);
270 }
const iterator_safe & endSafe() const noexcept
The usual safe end iterator to parse the set.
Definition set_tpl.h:426

References gum::MultiDimFunctionGraph< GUM_SCALAR, 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
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::ITI< AttributeSelection, isScalar >::removeNode_ ( NodeId currentNodeId)
protectedvirtual

Removes a node from the internal graph.

Parameters
removedNodeId: the node to remove

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

Definition at line 253 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
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 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)

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::ITI< AttributeSelection, isScalar >::updateFunctionGraph ( )
virtual

Updates target to currently learned graph structure.

Implements gum::IncrementalGraphLearner< AttributeSelection, false >.

Definition at line 266 of file iti_tpl.h.

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

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

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

Implements gum::IncrementalGraphLearner< AttributeSelection, false >.

Definition at line 160 of file iti_tpl.h.

160 {
162 filo.push_back(this->root_);
164 tensorVars.insert(this->root_, new gum::VariableSet(this->setOfVars_));
165
166
167 while (!filo.empty()) {
168 NodeId currentNodeId = filo.back();
169 filo.pop_back();
170
171 // First we look for the best var to install on the node
174
176 varIter != tensorVars[currentNodeId]->cendSafe();
177 ++varIter)
179 double varValue = this->nodeId2Database_[currentNodeId]->testValue(*varIter);
180 if (varValue >= bestValue) {
181 if (varValue > bestValue) {
183 bestVars.clear();
184 }
185 bestVars.insert(*varIter);
186 }
187 }
188
189 // Then We installed Variable a test on that node
191
192 // The we move on the children if needed
193 if (this->nodeVarMap_[currentNodeId] != this->value_) {
194 for (Idx moda = 0; moda < this->nodeVarMap_[currentNodeId]->domainSize(); moda++) {
198 if (_staleTable_[sonId]) {
199 filo.push_back(sonId);
201 }
202 }
203 }
204 }
205
207 nodeIter != tensorVars.endSafe();
208 ++nodeIter)
209 delete nodeIter.val();
210 }
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 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::ITI< AttributeSelection, isScalar >::updateNodeWithObservation_ ( const Observation * newObs,
NodeId currentNodeId )
protectedvirtual

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 144 of file iti_tpl.h.

145 {
147 newObs,
150 }
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 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::ITI< AttributeSelection, isScalar >::_attributeSelectionThreshold_
private

The threshold above which we consider variables to be dependant.

Definition at line 282 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 279 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 276 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 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:
  • agrum/FMDP/learning/datastructure/iti.h
  • agrum/FMDP/learning/datastructure/iti_tpl.h