aGrUM  0.16.0
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 66 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 67 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 61 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().

64  :
65  _target(target),
66  _setOfVars(varList), _value(value) {
67  GUM_CONSTRUCTOR(IncrementalGraphLearner);
68 
69  for (auto varIter = _setOfVars.cbeginSafe(); varIter != _setOfVars.cendSafe();
70  ++varIter)
71  _var2Node.insert(*varIter, new LinkedList< NodeId >());
72  _var2Node.insert(_value, new LinkedList< NodeId >());
73 
74  _model.addNode();
75  this->_root = _insertLeafNode(
76  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value),
77  _value,
78  new Set< const Observation* >());
79  }
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 87 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.

87  {
88  for (auto nodeIter = _nodeId2Database.beginSafe();
89  nodeIter != _nodeId2Database.endSafe();
90  ++nodeIter)
91  delete nodeIter.val();
92 
93  for (auto nodeIter = _nodeSonsMap.beginSafe();
94  nodeIter != _nodeSonsMap.endSafe();
95  ++nodeIter)
96  SOA_DEALLOCATE(nodeIter.val(),
97  sizeof(NodeId) * _nodeVarMap[nodeIter.key()]->domainSize());
98 
99  for (auto varIter = _var2Node.beginSafe(); varIter != _var2Node.endSafe();
100  ++varIter)
101  delete varIter.val();
102 
103  for (auto nodeIter = _leafDatabase.beginSafe();
104  nodeIter != _leafDatabase.endSafe();
105  ++nodeIter)
106  delete nodeIter.val();
107 
108  __clearValue();
109 
110  GUM_DESTRUCTOR(IncrementalGraphLearner);
111  }
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:98
+ 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 135 of file incrementalGraphLearner.h.

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

135  {
136  __assumeValue(obs, Int2Type< isScalar >());
137  }
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 138 of file incrementalGraphLearner.h.

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

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

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

141  {
142  if (!_valueAssumed.exists(obs->modality(_value)))
143  _valueAssumed << obs->modality(_value);
144  }
+ 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 152 of file incrementalGraphLearner.h.

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

152  {
153  return __branchObs(obs, var, Int2Type< isScalar >());
154  }
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 155 of file incrementalGraphLearner.h.

References gum::Observation::rModality().

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

References gum::Observation::modality().

162  {
163  return obs->modality(var);
164  }
+ 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 100 of file incrementalGraphLearner.h.

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

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

100 { __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 106 of file incrementalGraphLearner.h.

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

106 { 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 112 of file incrementalGraphLearner.h.

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

112 {}
+ 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 421 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().

422  {
423  if (_nodeVarMap[currentNodeId] == desiredVar) return;
424 
425  _var2Node[_nodeVarMap[currentNodeId]]->searchAndRemoveLink(currentNodeId);
426  _var2Node[desiredVar]->addLink(currentNodeId);
427  _nodeVarMap[currentNodeId] = desiredVar;
428 
429  if (_nodeVarMap[currentNodeId] != _value
430  && _leafDatabase.exists(currentNodeId)) {
431  delete _leafDatabase[currentNodeId];
432  _leafDatabase.erase(currentNodeId);
433  }
434 
435  if (_nodeVarMap[currentNodeId] == _value
436  && !_leafDatabase.exists(currentNodeId)) {
437  _leafDatabase.insert(currentNodeId, new Set< const Observation* >());
438  }
439 
440  _needUpdate = true;
441  }
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 211 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().

212  {
213  if (_nodeVarMap[currentNodeId] != _value) {
214  _leafDatabase.insert(currentNodeId, new Set< const Observation* >());
215 
216  // Resolving potential sons issue
217  for (Idx modality = 0; modality < _nodeVarMap[currentNodeId]->domainSize();
218  ++modality) {
219  NodeId sonId = _nodeSonsMap[currentNodeId][modality];
220  _convertNode2Leaf(sonId);
221  (*_leafDatabase[currentNodeId]) =
222  (*_leafDatabase[currentNodeId]) + *(_leafDatabase[sonId]);
223  _removeNode(sonId);
224  }
225 
226  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
227  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
228  _nodeSonsMap.erase(currentNodeId);
229 
230  _chgNodeBoundVar(currentNodeId, _value);
231  }
232  }
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:98
+ 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 383 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().

386  {
387  NodeId newNodeId = this->_insertNode(nDB, boundVar);
388  _nodeSonsMap.insert(newNodeId, sonsMap);
389  return newNodeId;
390  }
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:98
+ 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 403 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().

406  {
407  NodeId newNodeId = this->_insertNode(nDB, boundVar);
408  _leafDatabase.insert(newNodeId, obsSet);
409  return newNodeId;
410  }
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:98
+ 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 358 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().

360  {
361  NodeId newNodeId = _model.addNode();
362  _nodeVarMap.insert(newNodeId, boundVar);
363  _nodeId2Database.insert(newNodeId, nDB);
364  _var2Node[boundVar]->addLink(newNodeId);
365 
366  _needUpdate = true;
367 
368  return newNodeId;
369  }
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:98
+ 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 451 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().

452  {
453  // Retriat de l'id
454  _model.eraseNode(currentNodeId);
455 
456  // Retrait du vecteur fils
457  if (_nodeSonsMap.exists(currentNodeId)) {
458  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
459  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
460  _nodeSonsMap.erase(currentNodeId);
461  }
462 
463  if (_leafDatabase.exists(currentNodeId)) {
464  delete _leafDatabase[currentNodeId];
465  _leafDatabase.erase(currentNodeId);
466  }
467 
468  // Retrait de la variable
469  _var2Node[_nodeVarMap[currentNodeId]]->searchAndRemoveLink(currentNodeId);
470  _nodeVarMap.erase(currentNodeId);
471 
472  // Retrait du NodeDatabase
473  delete _nodeId2Database[currentNodeId];
474  _nodeId2Database.erase(currentNodeId);
475 
476  _needUpdate = true;
477  }
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:98
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 240 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().

241  {
242  // **************************************************************************************
243  // Si le noeud courant contient déjà la variable qu'on souhaite lui amener
244  // Il n'y a rien à faire
245  if (_nodeVarMap[currentNodeId] == desiredVar) { return; }
246 
247  // **************************************************************************************
248  // Si le noeud courant est terminal,
249  // Il faut artificiellement insérer un noeud liant à la variable
250  if (_nodeVarMap[currentNodeId] == _value) {
251  // We turned this leaf into an internal node.
252  // This mean that we'll need to install children leaves for each value of
253  // desiredVar
254 
255  // First We must prepare these new leaves NodeDatabases and Sets<const
256  // Observation*>
257  NodeDatabase< AttributeSelection, isScalar >** dbMap =
258  static_cast< NodeDatabase< AttributeSelection, isScalar >** >(
259  SOA_ALLOCATE(sizeof(NodeDatabase< AttributeSelection, isScalar >*)
260  * desiredVar->domainSize()));
261  Set< const Observation* >** obsetMap =
262  static_cast< Set< const Observation* >** >(SOA_ALLOCATE(
263  sizeof(Set< const Observation* >*) * desiredVar->domainSize()));
264  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality) {
265  dbMap[modality] =
266  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value);
267  obsetMap[modality] = new Set< const Observation* >();
268  }
269  for (SetIteratorSafe< const Observation* > obsIter =
270  _leafDatabase[currentNodeId]->beginSafe();
271  _leafDatabase[currentNodeId]->endSafe() != obsIter;
272  ++obsIter) {
273  dbMap[__branchObs(*obsIter, desiredVar)]->addObservation(*obsIter);
274  obsetMap[__branchObs(*obsIter, desiredVar)]->insert(*obsIter);
275  }
276 
277  // Then we can install each new leaves (and put in place the sonsMap)
278  NodeId* sonsMap = static_cast< NodeId* >(
279  SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
280  for (Idx modality = 0; modality < desiredVar->domainSize(); ++modality)
281  sonsMap[modality] =
282  _insertLeafNode(dbMap[modality], _value, obsetMap[modality]);
283 
284  // Some necessary clean up
285  SOA_DEALLOCATE(dbMap,
286  sizeof(NodeDatabase< AttributeSelection, isScalar >*)
287  * desiredVar->domainSize());
289  obsetMap, sizeof(Set< const Observation* >*) * desiredVar->domainSize());
290 
291  // And finally we can turn the node into an internal node associated to
292  // desiredVar
293  _chgNodeBoundVar(currentNodeId, desiredVar);
294  _nodeSonsMap.insert(currentNodeId, sonsMap);
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();
304  ++modality)
305  _transpose(_nodeSonsMap[currentNodeId][modality], desiredVar);
306 
307  // Sequence<NodeDatabase<AttributeSelection, isScalar>*>
308  // sonsNodeDatabase =
309  // _nodeId2Database[currentNodeId]->splitOnVar(desiredVar);
310  NodeId* sonsMap = static_cast< NodeId* >(
311  SOA_ALLOCATE(sizeof(NodeId) * desiredVar->domainSize()));
312 
313  // Then we create the new mapping
314  for (Idx desiredVarModality = 0; desiredVarModality < desiredVar->domainSize();
315  ++desiredVarModality) {
316  NodeId* grandSonsMap = static_cast< NodeId* >(
317  SOA_ALLOCATE(sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize()));
318  NodeDatabase< AttributeSelection, isScalar >* sonDB =
319  new NodeDatabase< AttributeSelection, isScalar >(&_setOfVars, _value);
320  for (Idx currentVarModality = 0;
321  currentVarModality < _nodeVarMap[currentNodeId]->domainSize();
322  ++currentVarModality) {
323  grandSonsMap[currentVarModality] =
324  _nodeSonsMap[_nodeSonsMap[currentNodeId][currentVarModality]]
325  [desiredVarModality];
326  sonDB->operator+=((*_nodeId2Database[grandSonsMap[currentVarModality]]));
327  }
328 
329  sonsMap[desiredVarModality] =
330  _insertInternalNode(sonDB, _nodeVarMap[currentNodeId], grandSonsMap);
331  }
332 
333  // Finally we clean the old remaining nodes
334  for (Idx currentVarModality = 0;
335  currentVarModality < _nodeVarMap[currentNodeId]->domainSize();
336  ++currentVarModality) {
337  _removeNode(_nodeSonsMap[currentNodeId][currentVarModality]);
338  }
339 
340  // We suppress the old sons map and remap to the new one
341  SOA_DEALLOCATE(_nodeSonsMap[currentNodeId],
342  sizeof(NodeId) * _nodeVarMap[currentNodeId]->domainSize());
343  _nodeSonsMap[currentNodeId] = sonsMap;
344 
345  _chgNodeBoundVar(currentNodeId, desiredVar);
346  }
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:98
#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 180 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().

181  {
182  // If this node has no interesting variable, we turn it into a leaf
183  if (varsOfInterest.empty()) {
184  _convertNode2Leaf(updatedNode);
185  return;
186  }
187 
188  // If this node has already one of the best variable intalled as test, we
189  // move on
190  if (_nodeVarMap.exists(updatedNode)
191  && varsOfInterest.exists(_nodeVarMap[updatedNode])) {
192  return;
193  }
194 
195  // In any other case we have to install variable as best test
196  Idx randy = (Idx)(std::rand() / RAND_MAX) * varsOfInterest.size(), basc = 0;
197  SetConstIteratorSafe< const DiscreteVariable* > varIter;
198  for (varIter = varsOfInterest.cbeginSafe(), basc = 0;
199  varIter != varsOfInterest.cendSafe() && basc < randy;
200  ++varIter, basc++)
201  ;
202 
203  _transpose(updatedNode, *varIter);
204  }
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:53
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 175 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().

176  {
177  _nodeId2Database[currentNodeId]->addObservation(newObs);
178  }
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 125 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().

126  {
127  __assumeValue(newObs);
128 
129  // The we go across the tree
130  NodeId currentNodeId = _root;
131 
132  while (_nodeSonsMap.exists(currentNodeId)) {
133  // On each encountered node, we update the database
134  _updateNodeWithObservation(newObs, currentNodeId);
135 
136  // The we select the next to go throught
137  currentNodeId =
138  _nodeSonsMap[currentNodeId]
139  [__branchObs(newObs, _nodeVarMap[currentNodeId])];
140  }
141 
142  // On final insertion into the leave we reach
143  _updateNodeWithObservation(newObs, currentNodeId);
144  _leafDatabase[currentNodeId]->insert(newObs);
145  }
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:98
+ 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 344 of file incrementalGraphLearner.h.

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

344  {
345  for (SetIteratorSafe< const DiscreteVariable* > varIter =
346  _setOfVars.beginSafe();
347  varIter != _setOfVars.endSafe();
348  ++varIter)
349  ret->add(**varIter);
350  }
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 318 of file incrementalGraphLearner.h.

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

318 { 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 337 of file incrementalGraphLearner.h.

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

337  {
338  return this->_nodeId2Database[ni]->nbObservation();
339  }
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 330 of file incrementalGraphLearner.h.

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

330  {
331  return this->_nodeSonsMap[ni][modality];
332  }
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 323 of file incrementalGraphLearner.h.

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

323  {
324  return this->_nodeVarMap[ni];
325  }
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 313 of file incrementalGraphLearner.h.

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

313 { 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 302 of file incrementalGraphLearner.h.

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

302 { 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 158 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().

159  {
160  Link< NodeId >* nodIter = _var2Node[var]->list();
161  Link< NodeId >* nni = nullptr;
162  while (nodIter) {
163  nni = nodIter->nextLink();
164  _convertNode2Leaf(nodIter->element());
165  nodIter = nni;
166  }
167  }
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: