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

<agrum/FMDP/learning/datastructure/incrementalGraphLearner> More...

#include <incrementalGraphLearner.h>

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

Public Member Functions

Function Graph Updating methods
virtual void updateFunctionGraph ()=0
 Updates target to currently learned graph structure.
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 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 = typename ValueSelect< isScalar, double, Idx >::type

Constructor & destructor.

 IncrementalGraphLearner (MultiDimFunctionGraph< double > *target, gum::VariableSet attributesSet, const DiscreteVariable *learnVariable)
 Default constructor.
 ~IncrementalGraphLearner () override
 Default destructor.
void _clearValue_ ()
 Template function dispatcher.
void _clearValue_ (Int2Type< true >)
 In the case where we're learning a function of real values this has to be wiped out upon destruction (to be deprecated).
void _clearValue_ (Int2Type< false >)
 In case where we're learning function of variable behaviour, this should do nothing.

New Observation insertion methods

virtual void addObservation (const Observation *obs)
 Inserts a new observation.
void _assumeValue_ (const Observation *obs)
 Get value assumed by studied variable for current observation.
void _assumeValue_ (const Observation *obs, Int2Type< true >)
 Inserts a new observation.
void _assumeValue_ (const Observation *obs, Int2Type< false >)
 Inserts a new observation.
Idx _branchObs_ (const Observation *obs, const DiscreteVariable *var)
 Seek modality assumed in obs for given var.
Idx _branchObs_ (const Observation *obs, const DiscreteVariable *var, Int2Type< true >)
 Inserts a new observation.
Idx _branchObs_ (const Observation *obs, const DiscreteVariable *var, Int2Type< false >)
 Inserts a new observation.
virtual void updateNodeWithObservation_ (const Observation *newObs, NodeId currentNodeId)
 Will update internal graph's NodeDatabase of given node with the new observation.

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.
virtual void updateGraph ()=0
 Updates the tree after a new observation has been added.
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
virtual NodeId insertLeafNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
 inserts a new leaf node in internal graohs
virtual void chgNodeBoundVar_ (NodeId chgedNodeId, const DiscreteVariable *desiredVar)
 Changes the associated variable of a node.
virtual void removeNode_ (NodeId removedNodeId)
 Removes a node from the internal graph.

Detailed Description

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

<agrum/FMDP/learning/datastructure/incrementalGraphLearner>

Abstract class for incrementally learn a graphical representation of a function. Can handle both function of real values, and function explaining the behaviour of a variable given set of other variables (as typically in conditional probabilities)

Maintains two graph in memory, one which is incrementally updated and the other one which is updated on demand and is usable by the outside.

Definition at line 83 of file incrementalGraphLearner.h.

Member Typedef Documentation

◆ ValueType

template<TESTNAME AttributeSelection, bool isScalar = false>
using gum::IncrementalGraphLearner< AttributeSelection, isScalar >::ValueType = typename ValueSelect< isScalar, double, Idx >::type
private

Definition at line 84 of file incrementalGraphLearner.h.

Constructor & Destructor Documentation

◆ IncrementalGraphLearner()

template<TESTNAME AttributeSelection, bool isScalar>
gum::IncrementalGraphLearner< AttributeSelection, isScalar >::IncrementalGraphLearner ( MultiDimFunctionGraph< double > * target,
gum::VariableSet varList,
const DiscreteVariable * value )

Default constructor.

Parameters
target: the output diagram usable by the outside
attributesSet: set of variables from which we try to describe the learned function
learnVariable: if we tried to learn a the behaviour of a variable given variable given another set of variables, this is the one. If we are learning a function of real value, this is just a computationnal trick (and is to be deprecated)

Definition at line 86 of file incrementalGraphLearner_tpl.h.

91
92 for (auto varIter = setOfVars_.cbeginSafe(); varIter != setOfVars_.cendSafe(); ++varIter)
95
96 model_.addNode();
99 value_,
101 }
<agrum/FMDP/learning/datastructure/incrementalGraphLearner>
virtual NodeId insertLeafNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
inserts a new leaf node in internal graohs
HashTable< const DiscreteVariable *, LinkedList< NodeId > * > var2Node_
Associates to any variable the list of all nodes associated to this variable.
NodeGraphPart model_
The source of nodeId.
NodeId root_
The root of the ordered tree.
MultiDimFunctionGraph< double > * target_
The final diagram we're building.
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, gum::VariableSet attributesSet, const DiscreteVariable *learnVariable)
Default constructor.

References IncrementalGraphLearner(), insertLeafNode_(), model_, root_, setOfVars_, target_, value_, and var2Node_.

Referenced by IncrementalGraphLearner().

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

◆ ~IncrementalGraphLearner()

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

Default destructor.

Definition at line 107 of file incrementalGraphLearner_tpl.h.

107 {
108 for (auto nodeIter = nodeId2Database_.beginSafe(); nodeIter != nodeId2Database_.endSafe();
109 ++nodeIter)
110 delete nodeIter.val();
111
112 for (auto nodeIter = nodeSonsMap_.beginSafe(); nodeIter != nodeSonsMap_.endSafe(); ++nodeIter)
113 SOA_DEALLOCATE(nodeIter.val(), sizeof(NodeId) * nodeVarMap_[nodeIter.key()]->domainSize());
114
115 for (auto varIter = var2Node_.beginSafe(); varIter != var2Node_.endSafe(); ++varIter)
116 delete varIter.val();
117
118 for (auto nodeIter = leafDatabase_.beginSafe(); nodeIter != leafDatabase_.endSafe(); ++nodeIter)
119 delete nodeIter.val();
120
121 _clearValue_();
122
124 }
HashTable< NodeId, NodeId * > nodeSonsMap_
A table giving for any node a table mapping to its son idx is the modality of associated variable.
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > * > nodeId2Database_
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
HashTable< NodeId, Set< const Observation * > * > leafDatabase_
This hashtable binds to every leaf an associated set of all hte observations compatible with it.
void _clearValue_()
Template function dispatcher.
HashTable< NodeId, const DiscreteVariable * > nodeVarMap_
Gives for any node its associated variable.
#define SOA_DEALLOCATE(x, y)

References nodeId2Database_.

Member Function Documentation

◆ _assumeValue_() [1/3]

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_assumeValue_ ( const Observation * obs)
private

Get value assumed by studied variable for current observation.

Definition at line 482 of file incrementalGraphLearner_tpl.h.

483 {
485 }
void _assumeValue_(const Observation *obs)
Get value assumed by studied variable for current observation.

References _assumeValue_().

Referenced by _assumeValue_(), and addObservation().

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

◆ _assumeValue_() [2/3]

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_assumeValue_ ( const Observation * obs,
Int2Type< false >  )
private

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 496 of file incrementalGraphLearner_tpl.h.

497 {
498 if (!valueAssumed_.exists(obs->modality(value_))) valueAssumed_ << obs->modality(value_);
499 }

References gum::Observation::modality(), value_, and valueAssumed_.

Here is the call graph for this function:

◆ _assumeValue_() [3/3]

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_assumeValue_ ( const Observation * obs,
Int2Type< true >  )
private

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 489 of file incrementalGraphLearner_tpl.h.

490 {
491 if (!valueAssumed_.exists(obs->reward())) valueAssumed_ << obs->reward();
492 }

References gum::Observation::reward(), and valueAssumed_.

Here is the call graph for this function:

◆ _branchObs_() [1/3]

template<TESTNAME AttributeSelection, bool isScalar>
Idx gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_branchObs_ ( const Observation * obs,
const DiscreteVariable * var )
private

Seek modality assumed in obs for given var.

Definition at line 502 of file incrementalGraphLearner_tpl.h.

504 {
506 }
Idx _branchObs_(const Observation *obs, const DiscreteVariable *var)
Seek modality assumed in obs for given var.

References _branchObs_().

Referenced by _branchObs_().

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

◆ _branchObs_() [2/3]

template<TESTNAME AttributeSelection, bool isScalar>
Idx gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_branchObs_ ( const Observation * obs,
const DiscreteVariable * var,
Int2Type< false >  )
private

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 517 of file incrementalGraphLearner_tpl.h.

520 {
521 return obs->modality(var);
522 }

References gum::Observation::modality().

Here is the call graph for this function:

◆ _branchObs_() [3/3]

template<TESTNAME AttributeSelection, bool isScalar>
Idx gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_branchObs_ ( const Observation * obs,
const DiscreteVariable * var,
Int2Type< true >  )
private

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 509 of file incrementalGraphLearner_tpl.h.

512 {
513 return obs->rModality(var);
514 }

References gum::Observation::rModality().

Here is the call graph for this function:

◆ _clearValue_() [1/3]

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_clearValue_ ( )
private

Template function dispatcher.

Definition at line 469 of file incrementalGraphLearner_tpl.h.

469 {
471 }

References _clearValue_().

Referenced by _clearValue_().

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

◆ _clearValue_() [2/3]

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_clearValue_ ( Int2Type< false > )
private

In case where we're learning function of variable behaviour, this should do nothing.

Definition at line 479 of file incrementalGraphLearner_tpl.h.

479{}

◆ _clearValue_() [3/3]

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_clearValue_ ( Int2Type< true > )
private

In the case where we're learning a function of real values this has to be wiped out upon destruction (to be deprecated).

Definition at line 474 of file incrementalGraphLearner_tpl.h.

474 {
475 delete value_;
476 }

References value_.

◆ addObservation()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::addObservation ( const Observation * newObs)
virtual

Inserts a new observation.

Parameters
thenew observation to learn

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

Definition at line 137 of file incrementalGraphLearner_tpl.h.

138 {
140
141 // The we go across the tree
143
144 while (nodeSonsMap_.exists(currentNodeId)) {
145 // On each encountered node, we update the database
147
148 // The we select the next to go throught
150 }
151
152 // On final insertion into the leave we reach
155 }
virtual void updateNodeWithObservation_(const Observation *newObs, NodeId currentNodeId)
Will update internal graph's NodeDatabase of given node with the new observation.

References _assumeValue_(), nodeSonsMap_, and root_.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::addObservation(), and gum::ITI< AttributeSelection, isScalar >::addObservation().

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

◆ chgNodeBoundVar_()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< 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 in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.

Definition at line 413 of file incrementalGraphLearner_tpl.h.

References leafDatabase_, needUpdate_, nodeVarMap_, value_, and var2Node_.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::chgNodeBoundVar_(), and gum::ITI< AttributeSelection, isScalar >::chgNodeBoundVar_().

Here is the caller graph for this function:

◆ convertNode2Leaf_()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::convertNode2Leaf_ ( NodeId currentNodeId)
protectedvirtual

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

Definition at line 218 of file incrementalGraphLearner_tpl.h.

219 {
222
223 // Resolving tensor sons issue
224 for (Idx modality = 0; modality < nodeVarMap_[currentNodeId]->domainSize(); ++modality) {
229 }
230
234
236 }
237 }
virtual void convertNode2Leaf_(NodeId)
Turns the given node into a leaf if not already so.
virtual void removeNode_(NodeId removedNodeId)
Removes a node from the internal graph.
virtual void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
Changes the associated variable of a node.

References leafDatabase_, nodeVarMap_, and value_.

Referenced by updateNode_(), and updateVar().

Here is the caller graph for this function:

◆ insertInternalNode_()

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::insertInternalNode_ ( NodeDatabase< AttributeSelection, isScalar > * nDB,
const DiscreteVariable * boundVar,
NodeId * sonsMap )
protectedvirtual

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

380 {
383 return newNodeId;
384 }
virtual NodeId insertNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
inserts a new node in internal graph

References insertNode_(), and nodeSonsMap_.

Here is the call graph for this function:

◆ insertLeafNode_()

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

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

399 {
402 return newNodeId;
403 }

References insertNode_(), and leafDatabase_.

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

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

◆ insertNode_()

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

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

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

References model_, needUpdate_, nodeId2Database_, nodeVarMap_, and var2Node_.

Referenced by insertInternalNode_(), insertLeafNode_(), and gum::ITI< AttributeSelection, isScalar >::insertNode_().

Here is the caller graph for this function:

◆ insertSetOfVars()

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

Implements gum::IVisitableGraphLearner.

Definition at line 564 of file incrementalGraphLearner_tpl.h.

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

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

Here is the call graph for this function:

◆ isTerminal()

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

Implements gum::IVisitableGraphLearner.

Definition at line 535 of file incrementalGraphLearner_tpl.h.

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

References nodeSonsMap_.

◆ nodeNbObservation()

template<TESTNAME AttributeSelection, bool isScalar>
Idx gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeNbObservation ( NodeId ni) const
overridevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 552 of file incrementalGraphLearner_tpl.h.

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

References nodeId2Database_.

◆ nodeSon()

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeSon ( NodeId ni,
Idx modality ) const
overridevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 546 of file incrementalGraphLearner_tpl.h.

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

References nodeSonsMap_.

◆ nodeVar()

template<TESTNAME AttributeSelection, bool isScalar>
const DiscreteVariable * gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeVar ( NodeId ni) const
overridevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 541 of file incrementalGraphLearner_tpl.h.

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

References nodeVarMap_.

◆ removeNode_()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::removeNode_ ( NodeId currentNodeId)
protectedvirtual

Removes a node from the internal graph.

Parameters
removedNodeId: the node to remove

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

Definition at line 441 of file incrementalGraphLearner_tpl.h.

441 {
442 // Retriat de l'id
443 model_.eraseNode(currentNodeId);
444
445 // Retrait du vecteur fils
446 if (nodeSonsMap_.exists(currentNodeId)) {
450 }
451
452 if (leafDatabase_.exists(currentNodeId)) {
455 }
456
457 // Retrait de la variable
458 var2Node_[nodeVarMap_[currentNodeId]]->searchAndRemoveLink(currentNodeId);
460
461 // Retrait du NodeDatabase
464
465 needUpdate_ = true;
466 }

References leafDatabase_, model_, needUpdate_, nodeId2Database_, nodeSonsMap_, nodeVarMap_, SOA_DEALLOCATE, and var2Node_.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::removeNode_(), and gum::ITI< AttributeSelection, isScalar >::removeNode_().

Here is the caller graph for this function:

◆ root()

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::root ( ) const
overridevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 530 of file incrementalGraphLearner_tpl.h.

530 {
531 return this->root_;
532 }

References root_.

◆ size()

template<TESTNAME AttributeSelection, bool isScalar>
Size gum::IncrementalGraphLearner< AttributeSelection, isScalar >::size ( )

Definition at line 525 of file incrementalGraphLearner_tpl.h.

525 {
526 return nodeVarMap_.size();
527 }

References nodeVarMap_.

◆ transpose_()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::transpose_ ( NodeId currentNodeId,
const DiscreteVariable * desiredVar )
protectedvirtual

Installs given variable to the given node, ensuring that the variable is not present in its subtree.

Definition at line 244 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 *)
Installs given variable to the given node, ensuring that the variable is not present in its subtree.
virtual void addObservation(const Observation *obs)
Inserts a new observation.
virtual NodeId insertInternalNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
inserts a new internal node in internal graph
#define SOA_ALLOCATE(x)

◆ updateFunctionGraph()

template<TESTNAME AttributeSelection, bool isScalar = false>
virtual void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateFunctionGraph ( )
pure virtual

Updates target to currently learned graph structure.

Implemented in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.

◆ updateGraph()

template<TESTNAME AttributeSelection, bool isScalar = false>
virtual void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateGraph ( )
pure virtual

Updates the tree after a new observation has been added.

Implemented in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.

◆ updateNode_()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateNode_ ( NodeId updatedNode,
gum::VariableSet & varsOfInterest )
protected

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 188 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.

References convertNode2Leaf_(), and gum::Set< Key >::empty().

Here is the call graph for this function:

◆ updateNodeWithObservation_()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< 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 in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.

Definition at line 557 of file incrementalGraphLearner_tpl.h.

559 {
560 nodeId2Database_[currentNodeId]->addObservation(newObs);
561 }

References nodeId2Database_.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::updateNodeWithObservation_(), and gum::ITI< AttributeSelection, isScalar >::updateNodeWithObservation_().

Here is the caller graph for this function:

◆ updateVar()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateVar ( const DiscreteVariable * var)
virtual

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 167 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 }

References convertNode2Leaf_(), gum::Link< T >::element(), gum::Link< T >::nextLink(), and var2Node_.

Here is the call graph for this function:

Member Data Documentation

◆ leafDatabase_

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, Set< const Observation* >* > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::leafDatabase_
protected

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 chgNodeBoundVar_(), convertNode2Leaf_(), insertLeafNode_(), and removeNode_().

◆ model_

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

The source of nodeId.

Definition at line 330 of file incrementalGraphLearner.h.

Referenced by IncrementalGraphLearner(), insertNode_(), and removeNode_().

◆ needUpdate_

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

Definition at line 377 of file incrementalGraphLearner.h.

Referenced by chgNodeBoundVar_(), insertNode_(), and removeNode_().

◆ nodeId2Database_

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar >* > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeId2Database_
protected

This hashtable binds every node to an associated NodeDatabase which handles every observation that concerns that node.

Definition at line 358 of file incrementalGraphLearner.h.

Referenced by ~IncrementalGraphLearner(), insertNode_(), nodeNbObservation(), removeNode_(), and updateNodeWithObservation_().

◆ nodeSonsMap_

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, NodeId* > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeSonsMap_
protected

A table giving for any node a table mapping to its son idx is the modality of associated variable.

Definition at line 346 of file incrementalGraphLearner.h.

Referenced by addObservation(), insertInternalNode_(), isTerminal(), nodeSon(), and removeNode_().

◆ nodeVarMap_

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, const DiscreteVariable* > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::nodeVarMap_
protected

Gives for any node its associated variable.

Definition at line 340 of file incrementalGraphLearner.h.

Referenced by chgNodeBoundVar_(), convertNode2Leaf_(), insertNode_(), nodeVar(), removeNode_(), and size().

◆ root_

template<TESTNAME AttributeSelection, bool isScalar = false>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::root_
protected

The root of the ordered tree.

Definition at line 335 of file incrementalGraphLearner.h.

Referenced by IncrementalGraphLearner(), addObservation(), and root().

◆ setOfVars_

template<TESTNAME AttributeSelection, bool isScalar = false>
gum::VariableSet gum::IncrementalGraphLearner< AttributeSelection, isScalar >::setOfVars_
protected

Definition at line 372 of file incrementalGraphLearner.h.

Referenced by IncrementalGraphLearner(), and insertSetOfVars().

◆ target_

template<TESTNAME AttributeSelection, bool isScalar = false>
MultiDimFunctionGraph< double >* gum::IncrementalGraphLearner< AttributeSelection, isScalar >::target_
protected

The final diagram we're building.

Definition at line 370 of file incrementalGraphLearner.h.

Referenced by IncrementalGraphLearner().

◆ value_

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

◆ valueAssumed_

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

Definition at line 375 of file incrementalGraphLearner.h.

Referenced by _assumeValue_(), and _assumeValue_().

◆ var2Node_

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< const DiscreteVariable*, LinkedList< NodeId >* > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::var2Node_
protected

Associates to any variable the list of all nodes associated to this variable.

Definition at line 352 of file incrementalGraphLearner.h.

Referenced by IncrementalGraphLearner(), chgNodeBoundVar_(), insertNode_(), removeNode_(), and updateVar().


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