aGrUM  0.14.2
gum::ITI< AttributeSelection, isScalar > Class Template Reference

Learn a graphical representation of a function as a decision tree. More...

#include <agrum/FMDP/planning/FunctionGraph/iti.h>

+ Inheritance diagram for gum::ITI< AttributeSelection, isScalar >:
+ Collaboration diagram for gum::ITI< AttributeSelection, isScalar >:

Public Member Functions

Size size ()
 
Constructor & destructor.
 ITI (MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
 ITI constructor for functions describing the behaviour of one variable according to a set of other variable such as conditionnal probabilities. More...
 
 ITI (MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, Set< const DiscreteVariable * > attributeListe)
 ITI constructeur for real functions. More...
 
 ~ITI ()
 Default destructor. 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...
 

Protected Member Functions

void _insertSetOfVars (MultiDimFunctionGraph< double > *ret)
 _insertSetOfVars 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...
 
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 _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...
 

New Observation insertion methods

void addObservation (const Observation *obs)
 Inserts a new observation. More...
 
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

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

Function Graph Updating methods

void updateFunctionGraph ()
 Updates target to currently learned graph structure. More...
 
NodeId __insertNodeInFunctionGraph (NodeId src)
 Inserts an internal node in the target. More...
 
NodeId __insertTerminalNode (NodeId src)
 Insert a terminal node in the target. More...
 
NodeId __insertTerminalNode (NodeId src, Int2Type< true >)
 Insert a terminal node in the target. More...
 
NodeId __insertTerminalNode (NodeId src, Int2Type< false >)
 Insert a terminal node in the target. More...
 

Detailed Description

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

Learn a graphical representation of a function as a decision tree.

This learning is done incrementaly. Hence first observation are add to the structure and then the structure is updated. Maintains two graph function : one internal for the learning and a target which is updated on demand.

Definition at line 59 of file iti.h.

Constructor & Destructor Documentation

◆ ITI() [1/2]

template<TESTNAME AttributeSelection, bool isScalar>
gum::ITI< AttributeSelection, isScalar >::ITI ( MultiDimFunctionGraph< double > *  target,
double  attributeSelectionThreshold,
Set< const DiscreteVariable * >  attributeListe,
const DiscreteVariable learnedValue 
)

ITI constructor for functions describing the behaviour of one variable according to a set of other variable such as conditionnal probabilities.

Parameters
target: the MultiDimFunctionGraph in which we load the structure
attributeSelectionThreshold: threshold under which a node is not installed (pe-pruning)
attributeListe: Set of vars on which we rely to explain the behaviour of learned variable
learnedValue: the variable from which we try to learn the behaviour
target: the MultiDimFunctionGraph in which we load the structure
attributeSelectionThreshold: threshold under which a node is not installed (pe-pruning)
temporaryAPIfix: Issue in API in regard to IMDDI
attributeListe: Set of vars on which we rely to explain the behaviour of learned variable
learnedValue: the variable from which we try to learn the behaviour

Definition at line 58 of file iti_tpl.h.

References gum::ITI< AttributeSelection, isScalar >::__staleTable, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root, and gum::HashTable< Key, Val, Alloc >::insert().

62  :
63  IncrementalGraphLearner< AttributeSelection, isScalar >(
64  target, attributeListe, learnedValue),
66  __attributeSelectionThreshold(attributeSelectionThreshold) {
67  GUM_CONSTRUCTOR(ITI);
68  __staleTable.insert(this->_root, false);
69  }
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: iti.h:259
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:253
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: iti.h:256
ITI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
ITI constructor for functions describing the behaviour of one variable according to a set of other va...
Definition: iti_tpl.h:58
NodeId _root
The root of the ordered tree.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
+ Here is the call graph for this function:

◆ ITI() [2/2]

template<TESTNAME AttributeSelection, bool isScalar>
gum::ITI< AttributeSelection, isScalar >::ITI ( MultiDimFunctionGraph< double > *  target,
double  attributeSelectionThreshold,
Set< const DiscreteVariable * >  attributeListe 
)

ITI constructeur for real functions.

We try to predict the output of a function f given a set of variable

Parameters
target: the MultiDimFunctionGraph in which we load the structure
attributeSelectionThreshold: threshold under which a node is not installed (pe-pruning)
attributeListe: Set of vars on which we rely to explain the behaviour of learned function

We try to predict the output of a function f given a set of variable

Parameters
target: the MultiDimFunctionGraph in which we load the structure
attributeSelectionThreshold: threshold under which a node is not installed (pe-pruning)
temporaryAPIfix: Issue in API in regard to IMDDI
attributeListeSetof vars on which we rely to explain the behaviour of learned function

Definition at line 84 of file iti_tpl.h.

References gum::ITI< AttributeSelection, isScalar >::__staleTable, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root, and gum::HashTable< Key, Val, Alloc >::insert().

87  :
88  IncrementalGraphLearner< AttributeSelection, isScalar >(
89  target, attributeListe, new LabelizedVariable("Reward", "", 2)),
91  __attributeSelectionThreshold(attributeSelectionThreshold) {
92  GUM_CONSTRUCTOR(ITI);
93  __staleTable.insert(this->_root, false);
94  }
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: iti.h:259
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:253
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: iti.h:256
ITI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
ITI constructor for functions describing the behaviour of one variable according to a set of other va...
Definition: iti_tpl.h:58
NodeId _root
The root of the ordered tree.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
+ Here is the call graph for this function:

◆ ~ITI()

template<TESTNAME AttributeSelection, bool isScalar = false>
gum::ITI< AttributeSelection, isScalar >::~ITI ( )
inline

Default destructor.

Definition at line 102 of file iti.h.

References gum::ITI< AttributeSelection, isScalar >::__insertNodeInFunctionGraph(), gum::ITI< AttributeSelection, isScalar >::_chgNodeBoundVar(), gum::ITI< AttributeSelection, isScalar >::_insertNode(), gum::ITI< AttributeSelection, isScalar >::_removeNode(), gum::ITI< AttributeSelection, isScalar >::_updateNodeWithObservation(), gum::ITI< AttributeSelection, isScalar >::addObservation(), gum::ITI< AttributeSelection, isScalar >::updateFunctionGraph(), and gum::ITI< AttributeSelection, isScalar >::updateGraph().

102 { GUM_DESTRUCTOR(ITI); }
ITI(MultiDimFunctionGraph< double > *target, double attributeSelectionThreshold, Set< const DiscreteVariable * > attributeListe, const DiscreteVariable *learnedValue)
ITI constructor for functions describing the behaviour of one variable according to a set of other va...
Definition: iti_tpl.h:58
+ Here is the call graph for this function:

Member Function Documentation

◆ __insertNodeInFunctionGraph()

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::ITI< AttributeSelection, isScalar >::__insertNodeInFunctionGraph ( NodeId  currentNodeId)
private

Inserts an internal node in the target.

Parameters
srcthe source node in internal graph
Returns
the mathcing node id in the target
Parameters
thesource node in internal graph
Returns
the mathcing node id in the target

Definition at line 273 of file iti_tpl.h.

References gum::ITI< AttributeSelection, isScalar >::__insertTerminalNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_target, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::add(), gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::manager(), gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::setSon(), and gum::MultiDimImplementation< GUM_SCALAR >::variablesSequence().

Referenced by gum::ITI< AttributeSelection, isScalar >::updateFunctionGraph(), and gum::ITI< AttributeSelection, isScalar >::~ITI().

274  {
275  if (this->_nodeVarMap[currentNodeId] == this->_value) {
276  NodeId nody = __insertTerminalNode(currentNodeId);
277  return nody;
278  }
279 
280  if (!this->_target->variablesSequence().exists(
281  this->_nodeVarMap[currentNodeId])) {
282  this->_target->add(*(this->_nodeVarMap[currentNodeId]));
283  }
284 
285  NodeId nody =
286  this->_target->manager()->addInternalNode(this->_nodeVarMap[currentNodeId]);
287  for (Idx moda = 0; moda < this->_nodeVarMap[currentNodeId]->domainSize();
288  ++moda) {
290  this->_nodeSonsMap[currentNodeId][moda]);
291  this->_target->manager()->setSon(nody, moda, son);
292  }
293 
294  return nody;
295  }
HashTable< NodeId, NodeId *> _nodeSonsMap
A table giving for any node a table mapping to its son idx is the modality of associated variable...
void setSon(const NodeId &node, const Idx &modality, const NodeId &sonNode)
Sets nodes son for given modality to designated son node.
NodeId __insertNodeInFunctionGraph(NodeId src)
Inserts an internal node in the target.
Definition: iti_tpl.h:273
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
MultiDimFunctionGraph< double > * _target
The final diagram we&#39;re building.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
NodeId __insertTerminalNode(NodeId src)
Insert a terminal node in the target.
Definition: iti.h:205
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
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:

◆ __insertTerminalNode() [1/3]

template<TESTNAME AttributeSelection, bool isScalar = false>
NodeId gum::ITI< AttributeSelection, isScalar >::__insertTerminalNode ( NodeId  src)
inlineprivate

Insert a terminal node in the target.

This function is a dispatcher that will call the right function according to the value of the template isScalar

Parameters
srcthe source node in the learned graph
Returns
the matching node in the target

Definition at line 205 of file iti.h.

Referenced by gum::ITI< AttributeSelection, isScalar >::__insertNodeInFunctionGraph().

205  {
206  return __insertTerminalNode(src, Int2Type< isScalar >());
207  }
NodeId __insertTerminalNode(NodeId src)
Insert a terminal node in the target.
Definition: iti.h:205
+ Here is the caller graph for this function:

◆ __insertTerminalNode() [2/3]

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::ITI< AttributeSelection, isScalar >::__insertTerminalNode ( NodeId  currentNodeId,
Int2Type< true >   
)
private

Insert a terminal node in the target.

This function is called if we're learning a real value function. Inserts then a single value in target.

Parameters
srcthe source node in the learned graph
Returns
the matching node in the target

This function is called if we're learning the behaviour of a variable. Inserts then this variable and the relevant value beneath into target.

Parameters
thesource node in the learned graph
Returns
the matching node in the target

Definition at line 339 of file iti_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_target, gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addTerminalNode(), and gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::manager().

340  {
341  double value = 0.0;
342  for (auto valIter = this->_nodeId2Database[currentNodeId]->cbeginValues();
343  valIter != this->_nodeId2Database[currentNodeId]->cendValues();
344  ++valIter) {
345  value += (double)valIter.key() * valIter.val();
346  }
347  if (this->_nodeId2Database[currentNodeId]->nbObservation())
348  value /= (double)this->_nodeId2Database[currentNodeId]->nbObservation();
349  NodeId nody = this->_target->manager()->addTerminalNode(value);
350  return nody;
351  }
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
MultiDimFunctionGraph< double > * _target
The final diagram we&#39;re building.
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ __insertTerminalNode() [3/3]

template<TESTNAME AttributeSelection, bool isScalar>
NodeId gum::ITI< AttributeSelection, isScalar >::__insertTerminalNode ( NodeId  currentNodeId,
Int2Type< false >   
)
private

Insert a terminal node in the target.

This function is called if we're learning the behaviour of a variable. Inserts then this variable and the relevant value beneath into target.

Parameters
srcthe source node in the learned graph
Returns
the matching node in the target

This function is called if we're learning a real value function. Inserts then a single value in target.

Parameters
thesource node in the learned graph
Returns
the matching node in the target

Definition at line 308 of file iti_tpl.h.

References gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_target, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::add(), gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addInternalNode(), gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::addTerminalNode(), gum::DiscreteVariable::domainSize(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::manager(), SOA_ALLOCATE, and gum::MultiDimImplementation< GUM_SCALAR >::variablesSequence().

309  {
310  if (!this->_target->variablesSequence().exists(this->_value))
311  this->_target->add(*(this->_value));
312 
313  Size tot = this->_nodeId2Database[currentNodeId]->nbObservation();
314  if (tot == Size(0)) return this->_target->manager()->addTerminalNode(0.0);
315 
316  NodeId* sonsMap = static_cast< NodeId* >(
317  SOA_ALLOCATE(sizeof(NodeId) * this->_value->domainSize()));
318  for (Idx modality = 0; modality < this->_value->domainSize(); ++modality) {
319  double newVal = 0.0;
320  newVal = (double)this->_nodeId2Database[currentNodeId]->effectif(modality)
321  / (double)tot;
322  sonsMap[modality] = this->_target->manager()->addTerminalNode(newVal);
323  }
324  NodeId nody = this->_target->manager()->addInternalNode(this->_value, sonsMap);
325  return nody;
326  }
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > *> _nodeId2Database
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
NodeId addInternalNode(const DiscreteVariable *var)
Inserts a new non terminal node in graph.
MultiDimFunctionGraph< double > * _target
The final diagram we&#39;re building.
virtual Size domainSize() const =0
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
NodeId addTerminalNode(const GUM_SCALAR &value)
Adds a value to the MultiDimFunctionGraph.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define SOA_ALLOCATE(x)
+ Here is the call graph for this function:

◆ _chgNodeBoundVar()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::ITI< AttributeSelection, isScalar >::_chgNodeBoundVar ( NodeId  currentNodeId,
const DiscreteVariable desiredVar 
)
protectedvirtual

Changes the associated variable of a node.

Parameters
chgedNodeId: the node to change
desiredVar: its new associated variable

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

Definition at line 226 of file iti_tpl.h.

References gum::ITI< AttributeSelection, isScalar >::__staleTable, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_chgNodeBoundVar(), and gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap.

Referenced by gum::ITI< AttributeSelection, isScalar >::~ITI().

227  {
228  if (this->_nodeVarMap[currentNodeId] != desiredVar) {
229  __staleTable[currentNodeId] = true;
231  currentNodeId, desiredVar);
232  }
233  }
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:253
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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _convertNode2Leaf()

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

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

inserts a new internal node in internal graph

Parameters
nDB: the associated database
boundVar: the associated variable
sonsMap: a table giving node's sons node
Returns
the newly created node's id

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

inserts a new leaf node in internal graohs

Parameters
nDB: the associated database
boundVar: the associated variable
obsSet: the set of observation this leaf retains
Returns
the newly created node's id

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

Definition at line 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::ITI< AttributeSelection, isScalar >::_insertNode ( NodeDatabase< AttributeSelection, isScalar > *  nDB,
const DiscreteVariable boundVar 
)
protectedvirtual

inserts a new node in internal graph

inserts a new node in internal graohs

Parameters
nDB: the associated database
boundVar: the associated variable
Returns
the newly created node's id

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

Definition at line 207 of file iti_tpl.h.

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

Referenced by gum::ITI< AttributeSelection, isScalar >::~ITI().

209  {
210  NodeId n =
212  nDB, boundVar);
213  __staleTable.insert(n, true);
214  return n;
215  }
virtual NodeId _insertNode(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
inserts a new node in internal graph
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:253
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:

◆ _insertSetOfVars()

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

_insertSetOfVars

Parameters
ret

Definition at line 241 of file iti.h.

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

241  {
242  for (SetIteratorSafe< const DiscreteVariable* > varIter =
243  this->_setOfVars.beginSafe();
244  varIter != this->_setOfVars.endSafe();
245  ++varIter)
246  ret->add(**varIter);
247  }
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:

◆ _removeNode()

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

Removes a node from the internal graph.

Parameters
removedNodeId: the node to remove

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

Definition at line 243 of file iti_tpl.h.

References gum::ITI< AttributeSelection, isScalar >::__staleTable, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_removeNode(), and gum::HashTable< Key, Val, Alloc >::erase().

Referenced by gum::ITI< AttributeSelection, isScalar >::~ITI().

243  {
245  currentNodeId);
246  __staleTable.erase(currentNodeId);
247  }
void erase(const Key &key)
Removes a given element from the hash table.
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:253
virtual void _removeNode(NodeId removedNodeId)
Removes a node from the internal graph.
+ 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 
)
protectedvirtualinherited

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

From the given sets of node, selects randomly one and installs it on given node.

Chechks of course if node's current variable is not in that set first.

Parameters
nody: the node we update
bestVars: the set of interessting vars to be installed here

Chechks of course if node's current variable is not in that set first.

Parameters
nody: the node we update
bestVar: the set of interessting vars to be installed here

Definition at line 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>
void gum::ITI< AttributeSelection, isScalar >::_updateNodeWithObservation ( const Observation newObs,
NodeId  currentNodeId 
)
protectedvirtual

Will update internal graph's NodeDatabase of given node with the new observation.

Parameters
newObs
currentNodeId

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

Definition at line 123 of file iti_tpl.h.

References gum::ITI< AttributeSelection, isScalar >::__staleTable.

Referenced by gum::ITI< AttributeSelection, isScalar >::~ITI().

124  {
125  IncrementalGraphLearner< AttributeSelection,
126  isScalar >::_updateNodeWithObservation(newObs,
127  currentNodeId);
128  __staleTable[currentNodeId] = true;
129  }
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, Set< const DiscreteVariable * > attributesSet, const DiscreteVariable *learnVariable)
Default constructor.
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:253
void _updateNodeWithObservation(const Observation *newObs, NodeId currentNodeId)
Will update internal graph&#39;s NodeDatabase of given node with the new observation. ...
Definition: iti_tpl.h:123
+ Here is the caller graph for this function:

◆ addObservation()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::ITI< AttributeSelection, isScalar >::addObservation ( const Observation obs)
virtual

Inserts a new observation.

Parameters
obsthe new observation to learn
thenew observation to learn

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

Definition at line 109 of file iti_tpl.h.

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

Referenced by gum::ITI< AttributeSelection, isScalar >::~ITI().

109  {
112  }
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: iti.h:256
virtual void addObservation(const Observation *obs)
Inserts a new observation.
+ 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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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

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

Updates target to currently learned graph structure.

Implements gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 258 of file iti_tpl.h.

References gum::ITI< AttributeSelection, isScalar >::__insertNodeInFunctionGraph(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_target, gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::clear(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::manager(), and gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::setRootNode().

Referenced by gum::ITI< AttributeSelection, isScalar >::~ITI().

258  {
259  this->_target->clear();
260  this->_target->manager()->setRootNode(
261  this->__insertNodeInFunctionGraph(this->_root));
262  }
NodeId __insertNodeInFunctionGraph(NodeId src)
Inserts an internal node in the target.
Definition: iti_tpl.h:273
void setRootNode(const NodeId &root)
Sets root node of decision diagram.
MultiDimFunctionGraph< double > * _target
The final diagram we&#39;re building.
NodeId _root
The root of the ordered tree.
MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy > * manager()
Returns a const reference to the manager of this diagram.
void clear()
Clears the function graph.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateGraph()

template<TESTNAME AttributeSelection, bool isScalar>
void gum::ITI< AttributeSelection, isScalar >::updateGraph ( )
virtual

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

Implements gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 140 of file iti_tpl.h.

References gum::ITI< AttributeSelection, isScalar >::__attributeSelectionThreshold, gum::ITI< AttributeSelection, isScalar >::__staleTable, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeId2Database, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeSonsMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_nodeVarMap, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_root, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_setOfVars, gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_updateNode(), gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_value, gum::HashTable< Key, Val, Alloc >::beginSafe(), gum::HashTable< Key, Val, Alloc >::cendSafe(), gum::Set< Key, Alloc >::clear(), gum::HashTable< Key, Val, Alloc >::endSafe(), gum::Set< Key, Alloc >::erase(), gum::Set< Key, Alloc >::insert(), and gum::HashTable< Key, Val, Alloc >::insert().

Referenced by gum::ITI< AttributeSelection, isScalar >::~ITI().

140  {
141  std::vector< NodeId > filo;
142  filo.push_back(this->_root);
143  HashTable< NodeId, Set< const DiscreteVariable* >* > potentialVars;
144  potentialVars.insert(this->_root,
145  new Set< const DiscreteVariable* >(this->_setOfVars));
146 
147 
148  while (!filo.empty()) {
149  NodeId currentNodeId = filo.back();
150  filo.pop_back();
151 
152  // First we look for the best var to install on the node
153  double bestValue = __attributeSelectionThreshold;
154  Set< const DiscreteVariable* > bestVars;
155 
156  for (auto varIter = potentialVars[currentNodeId]->cbeginSafe();
157  varIter != potentialVars[currentNodeId]->cendSafe();
158  ++varIter)
159  if (this->_nodeId2Database[currentNodeId]->isTestRelevant(*varIter)) {
160  double varValue =
161  this->_nodeId2Database[currentNodeId]->testValue(*varIter);
162  if (varValue >= bestValue) {
163  if (varValue > bestValue) {
164  bestValue = varValue;
165  bestVars.clear();
166  }
167  bestVars.insert(*varIter);
168  }
169  }
170 
171  // Then We installed Variable a test on that node
172  this->_updateNode(currentNodeId, bestVars);
173 
174  // The we move on the children if needed
175  if (this->_nodeVarMap[currentNodeId] != this->_value) {
176  for (Idx moda = 0; moda < this->_nodeVarMap[currentNodeId]->domainSize();
177  moda++) {
178  Set< const DiscreteVariable* >* itsPotentialVars =
179  new Set< const DiscreteVariable* >(*potentialVars[currentNodeId]);
180  itsPotentialVars->erase(this->_nodeVarMap[currentNodeId]);
181  NodeId sonId = this->_nodeSonsMap[currentNodeId][moda];
182  if (__staleTable[sonId]) {
183  filo.push_back(sonId);
184  potentialVars.insert(sonId, itsPotentialVars);
185  }
186  }
187  }
188  }
189 
190  for (HashTableIteratorSafe< NodeId, Set< const DiscreteVariable* >* >
191  nodeIter = potentialVars.beginSafe();
192  nodeIter != potentialVars.endSafe();
193  ++nodeIter)
194  delete nodeIter.val();
195  }
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...
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: iti.h:259
void _updateNode(NodeId nody, Set< const DiscreteVariable * > &bestVars)
From the given sets of node, selects randomly one and installs it on given node.
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:253
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:

◆ updateVar()

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

If a new modality appears to exists for given variable, call this method to turn every associated node to this variable into leaf. Graph has then indeed to be revised.

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

◆ __attributeSelectionThreshold

template<TESTNAME AttributeSelection, bool isScalar = false>
double gum::ITI< AttributeSelection, isScalar >::__attributeSelectionThreshold
private

The threshold above which we consider variables to be dependant.

Definition at line 259 of file iti.h.

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

◆ __nbTotalObservation

template<TESTNAME AttributeSelection, bool isScalar = false>
Idx gum::ITI< AttributeSelection, isScalar >::__nbTotalObservation
private

The total number of observation added to this tree.

Definition at line 256 of file iti.h.

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

◆ __staleTable

template<TESTNAME AttributeSelection, bool isScalar = false>
HashTable< NodeId, bool > gum::ITI< AttributeSelection, isScalar >::__staleTable
private

Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpose) The aim is not if we have revise the installed variable on that node.

Definition at line 253 of file iti.h.

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

◆ _leafDatabase

◆ _model

◆ _needUpdate

◆ _nodeId2Database

◆ _nodeSonsMap

◆ _nodeVarMap

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

◆ _root

◆ _setOfVars

◆ _target

◆ _value

◆ _valueAssumed

template<TESTNAME AttributeSelection, bool isScalar = false>
Sequence< ValueType > gum::IncrementalGraphLearner< AttributeSelection, isScalar >::_valueAssumed
protectedinherited

◆ _var2Node


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