aGrUM  0.14.2
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. More...
 
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. More...
 
Set< const DiscreteVariable *> _setOfVars
 
const DiscreteVariable_value
 
Sequence< ValueType_valueAssumed
 
bool _needUpdate
 
Model handling datastructures
NodeGraphPart _model
 The source of nodeId. More...
 
NodeId _root
 The root of the ordered tree. More...
 
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
 Gives for any node its associated variable. More...
 
HashTable< NodeId, NodeId *> _nodeSonsMap
 A table giving for any node a table mapping to its son idx is the modality of associated variable. More...
 
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> _var2Node
 Associates to any variable the list of all nodes associated to this variable. More...
 
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
 This hashtable binds every node to an associated NodeDatabase which handles every observation that concerns that node. More...
 
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
 This hashtable binds to every leaf an associated set of all hte observations compatible with it. More...
 

Constructor & destructor.

 IncrementalGraphLearner (MultiDimFunctionGraph< double > *target, Set< const DiscreteVariable * > attributesSet, const DiscreteVariable *learnVariable)
 Default constructor. More...
 
virtual ~IncrementalGraphLearner ()
 Default destructor. More...
 
void __clearValue ()
 Template function dispatcher. More...
 
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) More...
 
void __clearValue (Int2Type< false >)
 In case where we're learning function of variable behaviour, this should do nothing. More...
 

New Observation insertion methods

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

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. More...
 
virtual void updateGraph ()=0
 Updates the tree after a new observation has been added. More...
 
void _updateNode (NodeId nody, Set< const DiscreteVariable * > &bestVars)
 From the given sets of node, selects randomly one and installs it on given node. More...
 
virtual void _convertNode2Leaf (NodeId)
 Turns the given node into a leaf if not already so. More...
 
virtual void _transpose (NodeId, const DiscreteVariable *)
 Installs given variable to the given node, ensuring that the variable is not present in its subtree. More...
 
virtual NodeId _insertNode (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
 inserts a new node in internal graph More...
 
virtual NodeId _insertInternalNode (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
 inserts a new internal node in internal graph More...
 
virtual NodeId _insertLeafNode (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
 inserts a new leaf node in internal graohs More...
 
virtual void _chgNodeBoundVar (NodeId chgedNodeId, const DiscreteVariable *desiredVar)
 Changes the associated variable of a node. More...
 
virtual void _removeNode (NodeId removedNodeId)
 Removes a node from the internal graph. More...
 

Detailed Description

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

<agrum/FMDP/learning/datastructure/incrementalGraphLearner>

Abstract class for incrementaly 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 conditionnal probabilities)

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

Definition at line 63 of file incrementalGraphLearner.h.

Member Typedef Documentation

◆ ValueType

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

Definition at line 64 of file incrementalGraphLearner.h.

Constructor & Destructor Documentation

◆ IncrementalGraphLearner()

template<TESTNAME AttributeSelection, bool isScalar>
gum::IncrementalGraphLearner< AttributeSelection, isScalar >::IncrementalGraphLearner ( MultiDimFunctionGraph< double > *  target,
Set< const DiscreteVariable * >  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 58 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertLeafNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_model, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_setOfVars, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_var2Node, and gum::NodeGraphPart::addNode().

61  :
62  _target(target),
63  _setOfVars(varList), _value(value) {
64  GUM_CONSTRUCTOR(IncrementalGraphLearner);
65 
66  for (auto varIter = _setOfVars.cbeginSafe(); varIter != _setOfVars.cendSafe();
67  ++varIter)
68  _var2Node.insert(*varIter, new LinkedList< NodeId >());
69  _var2Node.insert(_value, new LinkedList< NodeId >());
70 
71  _model.addNode();
72  this->_root = _insertLeafNode(
73  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value),
74  _value,
75  new Set< const Observation* >());
76  }
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> _var2Node
Associates to any variable the list of all nodes associated to this variable.
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, Set< const DiscreteVariable * > attributesSet, const DiscreteVariable *learnVariable)
Default constructor.
Set< const DiscreteVariable *> _setOfVars
MultiDimFunctionGraph< double > * _target
The final diagram we&#39;re building.
virtual NodeId _insertLeafNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
inserts a new leaf node in internal graohs
virtual NodeId addNode()
insert a new node and return its id
NodeId _root
The root of the ordered tree.
NodeGraphPart _model
The source of nodeId.
+ Here is the call graph for this function:

◆ ~IncrementalGraphLearner()

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

Default destructor.

Definition at line 84 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::__clearValue(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_leafDatabase, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_var2Node, gum::HashTable< Key, Val, Alloc >::beginSafe(), gum::HashTable< Key, Val, Alloc >::endSafe(), and SOA_DEALLOCATE.

84  {
85  for (auto nodeIter = _nodeId2Database.beginSafe();
86  nodeIter != _nodeId2Database.endSafe();
87  ++nodeIter)
88  delete nodeIter.val();
89 
90  for (auto nodeIter = _nodeSonsMap.beginSafe();
91  nodeIter != _nodeSonsMap.endSafe();
92  ++nodeIter)
93  SOA_DEALLOCATE(nodeIter.val(),
94  sizeof(NodeId) * _nodeVarMap[nodeIter.key()]->domainSize());
95 
96  for (auto varIter = _var2Node.beginSafe(); varIter != _var2Node.endSafe();
97  ++varIter)
98  delete varIter.val();
99 
100  for (auto nodeIter = _leafDatabase.beginSafe();
101  nodeIter != _leafDatabase.endSafe();
102  ++nodeIter)
103  delete nodeIter.val();
104 
105  __clearValue();
106 
107  GUM_DESTRUCTOR(IncrementalGraphLearner);
108  }
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.
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, Set< const DiscreteVariable * > attributesSet, const DiscreteVariable *learnVariable)
Default constructor.
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
const iterator_safe & endSafe() noexcept
Returns the safe iterator pointing to the end of the hashtable.
#define SOA_DEALLOCATE(x, y)
void __clearValue()
Template function dispatcher.
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
iterator_safe beginSafe()
Returns the safe iterator pointing to the beginning of the hashtable.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

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

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::addObservation().

132  {
133  __assumeValue(obs, Int2Type< isScalar >());
134  }
void __assumeValue(const Observation *obs)
Get value assumed by studied variable for current observation.
+ 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< true >   
)
inlineprivate

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 135 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_valueAssumed, and gum::Observation::reward().

135  {
136  if (!_valueAssumed.exists(obs->reward())) _valueAssumed << obs->reward();
137  }
+ 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< false >   
)
inlineprivate

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 138 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_valueAssumed, and gum::Observation::modality().

138  {
139  if (!_valueAssumed.exists(obs->modality(_value)))
140  _valueAssumed << obs->modality(_value);
141  }
+ 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 149 of file incrementalGraphLearner.h.

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::addObservation().

149  {
150  return __branchObs(obs, var, Int2Type< isScalar >());
151  }
Idx __branchObs(const Observation *obs, const DiscreteVariable *var)
Seek modality assumed in obs for given var.
+ 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< true >   
)
inlineprivate

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 152 of file incrementalGraphLearner.h.

References gum::Observation::rModality().

154  {
155  return obs->rModality(var);
156  }
+ 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< false >   
)
inlineprivate

Inserts a new observation.

Parameters
thenew observation to learn

Definition at line 157 of file incrementalGraphLearner.h.

References gum::Observation::modality().

159  {
160  return obs->modality(var);
161  }
+ 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 97 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::__clearValue().

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

97 { __clearValue(Int2Type< isScalar >()); }
void __clearValue()
Template function dispatcher.
+ 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< 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 103 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value.

103 { delete _value; }

◆ __clearValue() [3/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 109 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::addObservation().

109 {}
+ Here is the call 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::ITI< AttributeSelection, isScalar >, and gum::IMDDI< AttributeSelection, isScalar >.

Definition at line 418 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_leafDatabase, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_needUpdate, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_var2Node.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::ITI< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_convertNode2Leaf(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

419  {
420  if (_nodeVarMap[currentNodeId] == desiredVar) return;
421 
422  _var2Node[_nodeVarMap[currentNodeId]]->searchAndRemoveLink(currentNodeId);
423  _var2Node[desiredVar]->addLink(currentNodeId);
424  _nodeVarMap[currentNodeId] = desiredVar;
425 
426  if (_nodeVarMap[currentNodeId] != _value
427  && _leafDatabase.exists(currentNodeId)) {
428  delete _leafDatabase[currentNodeId];
429  _leafDatabase.erase(currentNodeId);
430  }
431 
432  if (_nodeVarMap[currentNodeId] == _value
433  && !_leafDatabase.exists(currentNodeId)) {
434  _leafDatabase.insert(currentNodeId, new Set< const Observation* >());
435  }
436 
437  _needUpdate = true;
438  }
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> _var2Node
Associates to any variable the list of all nodes associated to this variable.
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
+ 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 208 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_leafDatabase, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_removeNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::HashTable< Key, Val, Alloc >::erase(), and SOA_DEALLOCATE.

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation(), gum::IMDDI< AttributeSelection, isScalar >::updateGraph(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateVar().

209  {
210  if (_nodeVarMap[currentNodeId] != _value) {
211  _leafDatabase.insert(currentNodeId, new Set< const Observation* >());
212 
213  // Resolving potential sons issue
214  for (Idx modality = 0; modality < _nodeVarMap[currentNodeId]->domainSize();
215  ++modality) {
216  NodeId sonId = _nodeSonsMap[currentNodeId][modality];
217  _convertNode2Leaf(sonId);
218  (*_leafDatabase[currentNodeId]) =
219  (*_leafDatabase[currentNodeId]) + *(_leafDatabase[sonId]);
220  _removeNode(sonId);
221  }
222 
223  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
224  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
225  _nodeSonsMap.erase(currentNodeId);
226 
227  _chgNodeBoundVar(currentNodeId, _value);
228  }
229  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
void erase(const Key &key)
Removes a given element from the hash table.
#define SOA_DEALLOCATE(x, y)
virtual void _convertNode2Leaf(NodeId)
Turns the given node into a leaf if not already so.
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
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.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ 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 380 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, and gum::HashTable< Key, Val, Alloc >::insert().

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

383  {
384  NodeId newNodeId = this->_insertNode(nDB, boundVar);
385  _nodeSonsMap.insert(newNodeId, sonsMap);
386  return newNodeId;
387  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
virtual NodeId _insertNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
inserts a new node in internal graph
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller 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 400 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertNode(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_leafDatabase.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::_insertLeafNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::IncrementalGraphLearner().

403  {
404  NodeId newNodeId = this->_insertNode(nDB, boundVar);
405  _leafDatabase.insert(newNodeId, obsSet);
406  return newNodeId;
407  }
virtual NodeId _insertNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
inserts a new node in internal graph
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ 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 355 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_model, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_needUpdate, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_var2Node, and gum::NodeGraphPart::addNode().

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertInternalNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertLeafNode(), gum::ITI< AttributeSelection, isScalar >::_insertNode(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

357  {
358  NodeId newNodeId = _model.addNode();
359  _nodeVarMap.insert(newNodeId, boundVar);
360  _nodeId2Database.insert(newNodeId, nDB);
361  _var2Node[boundVar]->addLink(newNodeId);
362 
363  _needUpdate = true;
364 
365  return newNodeId;
366  }
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 co...
virtual NodeId addNode()
insert a new node and return its id
NodeGraphPart _model
The source of nodeId.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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::ITI< AttributeSelection, isScalar >, and gum::IMDDI< AttributeSelection, isScalar >.

Definition at line 448 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_leafDatabase, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_model, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_needUpdate, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_var2Node, gum::HashTable< Key, Val, Alloc >::erase(), gum::NodeGraphPart::eraseNode(), gum::HashTable< Key, Val, Alloc >::exists(), and SOA_DEALLOCATE.

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_convertNode2Leaf(), gum::IMDDI< AttributeSelection, isScalar >::_removeNode(), gum::ITI< AttributeSelection, isScalar >::_removeNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

449  {
450  // Retriat de l'id
451  _model.eraseNode(currentNodeId);
452 
453  // Retrait du vecteur fils
454  if (_nodeSonsMap.exists(currentNodeId)) {
455  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
456  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
457  _nodeSonsMap.erase(currentNodeId);
458  }
459 
460  if (_leafDatabase.exists(currentNodeId)) {
461  delete _leafDatabase[currentNodeId];
462  _leafDatabase.erase(currentNodeId);
463  }
464 
465  // Retrait de la variable
466  _var2Node[_nodeVarMap[currentNodeId]]->searchAndRemoveLink(currentNodeId);
467  _nodeVarMap.erase(currentNodeId);
468 
469  // Retrait du NodeDatabase
470  delete _nodeId2Database[currentNodeId];
471  _nodeId2Database.erase(currentNodeId);
472 
473  _needUpdate = true;
474  }
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 co...
void erase(const Key &key)
Removes a given element from the hash table.
#define SOA_DEALLOCATE(x, y)
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
NodeGraphPart _model
The source of nodeId.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
virtual void eraseNode(const NodeId id)
erase the node with the given id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::__branchObs(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertInternalNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertLeafNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_leafDatabase, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_removeNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_setOfVars, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::NodeDatabase< AttributeSelection, isScalar >::addObservation(), gum::DiscreteVariable::domainSize(), gum::Set< Key, Alloc >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), SOA_ALLOCATE, and SOA_DEALLOCATE.

Referenced by gum::IMDDI< AttributeSelection, isScalar >::__updateNodeSet(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

238  {
239  // **************************************************************************************
240  // Si le noeud courant contient déjà la variable qu'on souhaite lui amener
241  // Il n'y a rien à faire
242  if (_nodeVarMap[currentNodeId] == desiredVar) { return; }
243 
244  // **************************************************************************************
245  // Si le noeud courant est terminal,
246  // Il faut artificiellement insérer un noeud liant à la variable
247  if (_nodeVarMap[currentNodeId] == _value) {
248  // We turned this leaf into an internal node.
249  // This mean that we'll need to install children leaves for each value of
250  // desiredVar
251 
252  // First We must prepare these new leaves NodeDatabases and Sets<const
253  // Observation*>
254  NodeDatabase< AttributeSelection, isScalar >** dbMap =
255  static_cast< NodeDatabase< AttributeSelection, isScalar >** >(
256  SOA_ALLOCATE(sizeof(NodeDatabase< AttributeSelection, isScalar >*)
257  * desiredVar->domainSize()));
258  Set< const Observation* >** obsetMap =
259  static_cast< Set< const Observation* >** >(SOA_ALLOCATE(
260  sizeof(Set< const Observation* >*) * desiredVar->domainSize()));
261  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality) {
262  dbMap[modality] =
263  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value);
264  obsetMap[modality] = new Set< const Observation* >();
265  }
266  for (SetIteratorSafe< const Observation* > obsIter =
267  _leafDatabase[currentNodeId]->beginSafe();
268  _leafDatabase[currentNodeId]->endSafe() != obsIter;
269  ++obsIter) {
270  dbMap[__branchObs(*obsIter, desiredVar)]->addObservation(*obsIter);
271  obsetMap[__branchObs(*obsIter, desiredVar)]->insert(*obsIter);
272  }
273 
274  // Then we can install each new leaves (and put in place the sonsMap)
275  NodeId* sonsMap = static_cast< NodeId* >(
276  SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
277  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality)
278  sonsMap[modality] =
279  _insertLeafNode(dbMap[modality], _value, obsetMap[modality]);
280 
281  // Some necessary clean up
282  SOA_DEALLOCATE(dbMap,
283  sizeof(NodeDatabase< AttributeSelection, isScalar >*)
284  * desiredVar->domainSize());
286  obsetMap, sizeof(Set< const Observation* >*) * desiredVar->domainSize());
287 
288  // And finally we can turn the node into an internal node associated to
289  // desiredVar
290  _chgNodeBoundVar(currentNodeId, desiredVar);
291  _nodeSonsMap.insert(currentNodeId, sonsMap);
292 
293  return;
294  }
295 
296  // *************************************************************************************
297  // Remains the general case where currentNodeId is an internal node.
298 
299  // First we ensure that children node use desiredVar as variable
300  for (Idx modality = 0; modality < _nodeVarMap[currentNodeId]->domainSize();
301  ++modality)
302  _transpose(_nodeSonsMap[currentNodeId][modality], desiredVar);
303 
304  // Sequence<NodeDatabase<AttributeSelection, isScalar>*>
305  // sonsNodeDatabase =
306  // _nodeId2Database[currentNodeId]->splitOnVar(desiredVar);
307  NodeId* sonsMap = static_cast< NodeId* >(
308  SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
309 
310  // Then we create the new mapping
311  for (Idx desiredVarModality = 0; desiredVarModality < desiredVar->domainSize();
312  ++desiredVarModality) {
313  NodeId* grandSonsMap = static_cast< NodeId* >(
314  SOA_ALLOCATE(sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize()));
315  NodeDatabase< AttributeSelection, isScalar >* sonDB =
316  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value);
317  for (Idx currentVarModality = 0;
318  currentVarModality < _nodeVarMap[currentNodeId]->domainSize();
319  ++currentVarModality) {
320  grandSonsMap[currentVarModality] =
321  _nodeSonsMap[_nodeSonsMap[currentNodeId][currentVarModality]]
322  [desiredVarModality];
323  sonDB->operator+=((*_nodeId2Database[grandSonsMap[currentVarModality]]));
324  }
325 
326  sonsMap[desiredVarModality] =
327  _insertInternalNode(sonDB, _nodeVarMap[currentNodeId], grandSonsMap);
328  }
329 
330  // Finally we clean the old remaining nodes
331  for (Idx currentVarModality = 0;
332  currentVarModality < _nodeVarMap[currentNodeId]->domainSize();
333  ++currentVarModality) {
334  _removeNode(_nodeSonsMap[currentNodeId][currentVarModality]);
335  }
336 
337  // We suppress the old sons map and remap to the new one
338  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
339  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
340  _nodeSonsMap[currentNodeId] = sonsMap;
341 
342  _chgNodeBoundVar(currentNodeId, desiredVar);
343  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
Set< const DiscreteVariable *> _setOfVars
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
virtual NodeId _insertInternalNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
inserts a new internal node in internal graph
Idx __branchObs(const Observation *obs, const DiscreteVariable *var)
Seek modality assumed in obs for given var.
#define SOA_DEALLOCATE(x, y)
virtual NodeId _insertLeafNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
inserts a new leaf node in internal graohs
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
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 _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.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define SOA_ALLOCATE(x)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _updateNode()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode ( NodeId  updatedNode,
Set< const DiscreteVariable * > &  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 177 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_convertNode2Leaf(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), gum::Set< Key, Alloc >::cbeginSafe(), gum::Set< Key, Alloc >::cendSafe(), gum::Set< Key, Alloc >::empty(), gum::Set< Key, Alloc >::exists(), and gum::Set< Key, Alloc >::size().

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

178  {
179  // If this node has no interesting variable, we turn it into a leaf
180  if (varsOfInterest.empty()) {
181  _convertNode2Leaf(updatedNode);
182  return;
183  }
184 
185  // If this node has already one of the best variable intalled as test, we
186  // move on
187  if (_nodeVarMap.exists(updatedNode)
188  && varsOfInterest.exists(_nodeVarMap[updatedNode])) {
189  return;
190  }
191 
192  // In any other case we have to install variable as best test
193  Idx randy = (Idx)(std::rand() / RAND_MAX) * varsOfInterest.size(), basc = 0;
194  SetConstIteratorSafe< const DiscreteVariable* > varIter;
195  for (varIter = varsOfInterest.cbeginSafe(), basc = 0;
196  varIter != varsOfInterest.cendSafe() && basc < randy;
197  ++varIter, basc++)
198  ;
199 
200  _transpose(updatedNode, *varIter);
201  }
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...
Size Idx
Type for indexes.
Definition: types.h:50
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
+ Here is the call graph for this function:
+ Here is the caller 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::ITI< AttributeSelection, isScalar >, and gum::IMDDI< AttributeSelection, isScalar >.

Definition at line 172 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_convertNode2Leaf(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertInternalNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertLeafNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_insertNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_removeNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_transpose(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateFunctionGraph(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateGraph(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::updateVar().

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::addObservation().

173  {
174  _nodeId2Database[currentNodeId]->addObservation(newObs);
175  }
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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::ITI< AttributeSelection, isScalar >, and gum::IMDDI< AttributeSelection, isScalar >.

Definition at line 122 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::__assumeValue(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::__branchObs(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_leafDatabase, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation(), and gum::HashTable< Key, Val, Alloc >::exists().

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

123  {
124  __assumeValue(newObs);
125 
126  // The we go across the tree
127  NodeId currentNodeId = _root;
128 
129  while (_nodeSonsMap.exists(currentNodeId)) {
130  // On each encountered node, we update the database
131  _updateNodeWithObservation(newObs, currentNodeId);
132 
133  // The we select the next to go throught
134  currentNodeId =
135  _nodeSonsMap[currentNodeId]
136  [__branchObs(newObs, _nodeVarMap[currentNodeId])];
137  }
138 
139  // On final insertion into the leave we reach
140  _updateNodeWithObservation(newObs, currentNodeId);
141  _leafDatabase[currentNodeId]->insert(newObs);
142  }
void __assumeValue(const Observation *obs)
Get value assumed by studied variable for current observation.
virtual void _updateNodeWithObservation(const Observation *newObs, NodeId currentNodeId)
Will update internal graph&#39;s NodeDatabase of given node with the new observation. ...
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
Idx __branchObs(const Observation *obs, const DiscreteVariable *var)
Seek modality assumed in obs for given var.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< NodeId, Set< const Observation *> *> _leafDatabase
This hashtable binds to every leaf an associated set of all hte observations compatible with it...
NodeId _root
The root of the ordered tree.
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ 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 341 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_setOfVars, and gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::add().

341  {
342  for (SetIteratorSafe< const DiscreteVariable* > varIter =
343  _setOfVars.beginSafe();
344  varIter != _setOfVars.endSafe();
345  ++varIter)
346  ret->add(**varIter);
347  }
Set< const DiscreteVariable *> _setOfVars
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
+ 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 315 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, and gum::HashTable< Key, Val, Alloc >::exists().

315 { return !this->_nodeSonsMap.exists(ni); }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
+ Here is the call graph for this function:

◆ nodeNbObservation()

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

Implements gum::IVisitableGraphLearner.

Definition at line 334 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database.

334  {
335  return this->_nodeId2Database[ni]->nbObservation();
336  }
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...

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

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap.

327  {
328  return this->_nodeSonsMap[ni][modality];
329  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...

◆ nodeVar()

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

Implements gum::IVisitableGraphLearner.

Definition at line 320 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap.

320  {
321  return this->_nodeVarMap[ni];
322  }
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.

◆ root()

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

Implements gum::IVisitableGraphLearner.

Definition at line 310 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root.

310 { return this->_root; }
NodeId _root
The root of the ordered tree.

◆ size()

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

Definition at line 299 of file incrementalGraphLearner.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap.

299 { return _nodeVarMap.size(); }
HashTable< NodeId, const DiscreteVariable *> _nodeVarMap
Gives for any node its associated variable.

◆ 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::ITI< AttributeSelection, isScalar >, and gum::IMDDI< AttributeSelection, isScalar >.

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

+ Here is the caller graph for this function:

◆ 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::ITI< AttributeSelection, isScalar >, and gum::IMDDI< AttributeSelection, isScalar >.

Referenced by gum::IncrementalGraphLearner< 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 155 of file incrementalGraphLearner_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_convertNode2Leaf(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_var2Node, gum::Link< T >::element(), and gum::Link< T >::nextLink().

Referenced by gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNodeWithObservation().

156  {
157  Link< NodeId >* nodIter = _var2Node[var]->list();
158  Link< NodeId >* nni = nullptr;
159  while (nodIter) {
160  nni = nodIter->nextLink();
161  _convertNode2Leaf(nodIter->element());
162  nodIter = nni;
163  }
164  }
HashTable< const DiscreteVariable *, LinkedList< NodeId > *> _var2Node
Associates to any variable the list of all nodes associated to this variable.
virtual void _convertNode2Leaf(NodeId)
Turns the given node into a leaf if not already so.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _leafDatabase

◆ _model

◆ _needUpdate

◆ _nodeId2Database

◆ _nodeSonsMap

◆ _nodeVarMap

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

◆ _root

◆ _setOfVars

◆ _target

◆ _value

◆ _valueAssumed

◆ _var2Node


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