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

Size size ()
Function Graph Updating methods
virtual void updateFunctionGraph ()=0
 Updates target to currently learned graph structure.
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 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.
virtual ~IncrementalGraphLearner ()
 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 85 of file incrementalGraphLearner_tpl.h.

90
91 for (auto varIter = setOfVars_.cbeginSafe(); varIter != setOfVars_.cendSafe(); ++varIter)
94
95 model_.addNode();
98 value_,
100 }
<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 ( )
virtual

Default destructor.

Definition at line 106 of file incrementalGraphLearner_tpl.h.

106 {
107 for (auto nodeIter = nodeId2Database_.beginSafe(); nodeIter != nodeId2Database_.endSafe();
108 ++nodeIter)
109 delete nodeIter.val();
110
111 for (auto nodeIter = nodeSonsMap_.beginSafe(); nodeIter != nodeSonsMap_.endSafe(); ++nodeIter)
112 SOA_DEALLOCATE(nodeIter.val(), sizeof(NodeId) * nodeVarMap_[nodeIter.key()]->domainSize());
113
114 for (auto varIter = var2Node_.beginSafe(); varIter != var2Node_.endSafe(); ++varIter)
115 delete varIter.val();
116
117 for (auto nodeIter = leafDatabase_.beginSafe(); nodeIter != leafDatabase_.endSafe(); ++nodeIter)
118 delete nodeIter.val();
119
120 _clearValue_();
121
123 }
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 = false>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_assumeValue_ ( const Observation * obs)
inlineprivate

Get value assumed by studied variable for current observation.

Definition at line 153 of file incrementalGraphLearner.h.

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 = false>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_assumeValue_ ( const Observation * obs,
Int2Type< false >  )
inlineprivate

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 159 of file incrementalGraphLearner.h.

159 {
160 if (!valueAssumed_.exists(obs->modality(value_))) valueAssumed_ << obs->modality(value_);
161 }

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

Here is the call graph for this function:

◆ _assumeValue_() [3/3]

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

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 155 of file incrementalGraphLearner.h.

155 {
156 if (!valueAssumed_.exists(obs->reward())) valueAssumed_ << obs->reward();
157 }

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

Here is the call graph for this function:

◆ _branchObs_() [1/3]

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

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)
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 = false>
Idx gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_branchObs_ ( const Observation * obs,
const DiscreteVariable * var,
Int2Type< false >  )
inlineprivate

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 176 of file incrementalGraphLearner.h.

176 {
177 return obs->modality(var);
178 }

References gum::Observation::modality().

Here is the call graph for this function:

◆ _branchObs_() [3/3]

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

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 172 of file incrementalGraphLearner.h.

172 {
173 return obs->rModality(var);
174 }

References gum::Observation::rModality().

Here is the call graph for this function:

◆ _clearValue_() [1/3]

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

Template function dispatcher.

Definition at line 117 of file incrementalGraphLearner.h.

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 = false>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_clearValue_ ( Int2Type< false > )
inlineprivate

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

Definition at line 129 of file incrementalGraphLearner.h.

129{}

◆ _clearValue_() [3/3]

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

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

123{ delete value_; }

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

137 {
139
140 // The we go across the tree
142
143 while (nodeSonsMap_.exists(currentNodeId)) {
144 // On each encountered node, we update the database
146
147 // The we select the next to go throught
149 }
150
151 // On final insertion into the leave we reach
154 }
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 412 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 217 of file incrementalGraphLearner_tpl.h.

218 {
221
222 // Resolving tensor sons issue
223 for (Idx modality = 0; modality < nodeVarMap_[currentNodeId]->domainSize(); ++modality) {
228 }
229
233
235 }
236 }
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_, nodeSonsMap_, 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 376 of file incrementalGraphLearner_tpl.h.

379 {
382 return newNodeId;
383 }
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 395 of file incrementalGraphLearner_tpl.h.

398 {
401 return newNodeId;
402 }

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

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

References 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 = false>
virtual void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::insertSetOfVars ( MultiDimFunctionGraph< double > * ret) const
inlinevirtual

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 }

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

Here is the call graph for this function:

◆ isTerminal()

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

Implements gum::IVisitableGraphLearner.

Definition at line 329 of file incrementalGraphLearner.h.

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

References nodeSonsMap_.

◆ nodeNbObservation()

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

Implements gum::IVisitableGraphLearner.

Definition at line 344 of file incrementalGraphLearner.h.

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

References nodeId2Database_.

◆ nodeSon()

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

Implements gum::IVisitableGraphLearner.

Definition at line 339 of file incrementalGraphLearner.h.

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

References nodeSonsMap_.

◆ nodeVar()

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

Implements gum::IVisitableGraphLearner.

Definition at line 334 of file incrementalGraphLearner.h.

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

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

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

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 = false>
NodeId gum::IncrementalGraphLearner< AttributeSelection, isScalar >::root ( ) const
inlinevirtual

Implements gum::IVisitableGraphLearner.

Definition at line 324 of file incrementalGraphLearner.h.

324{ return this->root_; }

References root_.

◆ size()

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

Definition at line 313 of file incrementalGraphLearner.h.

313{ return nodeVarMap_.size(); }

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 243 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 *)
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 187 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 gum::Set< Key >::cbeginSafe(), gum::Set< Key >::cendSafe(), convertNode2Leaf_(), gum::Set< Key >::empty(), gum::Set< Key >::exists(), nodeVarMap_, gum::randomValue(), and gum::Set< Key >::size().

Here is the call graph for this function:

◆ updateNodeWithObservation_()

template<TESTNAME AttributeSelection, bool isScalar = false>
virtual void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateNodeWithObservation_ ( const Observation * newObs,
NodeId currentNodeId )
inlineprotectedvirtual

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

189 {
190 nodeId2Database_[currentNodeId]->addObservation(newObs);
191 }

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 166 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 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 403 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 369 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 416 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 397 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 385 of file incrementalGraphLearner.h.

Referenced by addObservation(), convertNode2Leaf_(), 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 379 of file incrementalGraphLearner.h.

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

◆ root_

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

The root of the ordered tree.

Definition at line 374 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 411 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 409 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 414 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 391 of file incrementalGraphLearner.h.

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


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