aGrUM  0.16.0
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 62 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 61 of file iti_tpl.h.

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

65  :
66  IncrementalGraphLearner< AttributeSelection, isScalar >(
67  target, attributeListe, learnedValue),
69  __attributeSelectionThreshold(attributeSelectionThreshold) {
70  GUM_CONSTRUCTOR(ITI);
71  __staleTable.insert(this->_root, false);
72  }
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: iti.h:262
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:256
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: iti.h:259
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:61
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 87 of file iti_tpl.h.

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

90  :
91  IncrementalGraphLearner< AttributeSelection, isScalar >(
92  target, attributeListe, new LabelizedVariable("Reward", "", 2)),
94  __attributeSelectionThreshold(attributeSelectionThreshold) {
95  GUM_CONSTRUCTOR(ITI);
96  __staleTable.insert(this->_root, false);
97  }
double __attributeSelectionThreshold
The threshold above which we consider variables to be dependant.
Definition: iti.h:262
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:256
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: iti.h:259
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:61
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 105 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().

105 { 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:61
+ 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 276 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().

277  {
278  if (this->_nodeVarMap[currentNodeId] == this->_value) {
279  NodeId nody = __insertTerminalNode(currentNodeId);
280  return nody;
281  }
282 
283  if (!this->_target->variablesSequence().exists(
284  this->_nodeVarMap[currentNodeId])) {
285  this->_target->add(*(this->_nodeVarMap[currentNodeId]));
286  }
287 
288  NodeId nody =
289  this->_target->manager()->addInternalNode(this->_nodeVarMap[currentNodeId]);
290  for (Idx moda = 0; moda < this->_nodeVarMap[currentNodeId]->domainSize();
291  ++moda) {
293  this->_nodeSonsMap[currentNodeId][moda]);
294  this->_target->manager()->setSon(nody, moda, son);
295  }
296 
297  return nody;
298  }
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:276
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:208
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:98
+ 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 208 of file iti.h.

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

208  {
209  return __insertTerminalNode(src, Int2Type< isScalar >());
210  }
NodeId __insertTerminalNode(NodeId src)
Insert a terminal node in the target.
Definition: iti.h:208
+ 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 342 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().

343  {
344  double value = 0.0;
345  for (auto valIter = this->_nodeId2Database[currentNodeId]->cbeginValues();
346  valIter != this->_nodeId2Database[currentNodeId]->cendValues();
347  ++valIter) {
348  value += (double)valIter.key() * valIter.val();
349  }
350  if (this->_nodeId2Database[currentNodeId]->nbObservation())
351  value /= (double)this->_nodeId2Database[currentNodeId]->nbObservation();
352  NodeId nody = this->_target->manager()->addTerminalNode(value);
353  return nody;
354  }
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:98
+ 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 311 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().

312  {
313  if (!this->_target->variablesSequence().exists(this->_value))
314  this->_target->add(*(this->_value));
315 
316  Size tot = this->_nodeId2Database[currentNodeId]->nbObservation();
317  if (tot == Size(0)) return this->_target->manager()->addTerminalNode(0.0);
318 
319  NodeId* sonsMap = static_cast< NodeId* >(
320  SOA_ALLOCATE(sizeof(NodeId) * this->_value->domainSize()));
321  for (Idx modality = 0; modality < this->_value->domainSize(); ++modality) {
322  double newVal = 0.0;
323  newVal = (double)this->_nodeId2Database[currentNodeId]->effectif(modality)
324  / (double)tot;
325  sonsMap[modality] = this->_target->manager()->addTerminalNode(newVal);
326  }
327  NodeId nody = this->_target->manager()->addInternalNode(this->_value, sonsMap);
328  return nody;
329  }
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:48
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#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 229 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().

230  {
231  if (this->_nodeVarMap[currentNodeId] != desiredVar) {
232  __staleTable[currentNodeId] = true;
234  currentNodeId, desiredVar);
235  }
236  }
HashTable< NodeId, bool > __staleTable
Hashtable indicating if given node has been modified (upon receiving new exemple or through a transpo...
Definition: iti.h:256
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 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 
)
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 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 
)
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 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::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 210 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().

212  {
213  NodeId n =
215  nDB, boundVar);
216  __staleTable.insert(n, true);
217  return n;
218  }
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:256
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:

◆ _insertSetOfVars()

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

_insertSetOfVars

Parameters
ret

Definition at line 244 of file iti.h.

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

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

246  {
248  currentNodeId);
249  __staleTable.erase(currentNodeId);
250  }
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:256
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 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 
)
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 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>
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 126 of file iti_tpl.h.

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

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

127  {
128  IncrementalGraphLearner< AttributeSelection,
129  isScalar >::_updateNodeWithObservation(newObs,
130  currentNodeId);
131  __staleTable[currentNodeId] = true;
132  }
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:256
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:126
+ 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 112 of file iti_tpl.h.

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

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

112  {
115  }
Idx __nbTotalObservation
The total number of observation added to this tree.
Definition: iti.h:259
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 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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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
inlinevirtualinherited

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

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

Updates target to currently learned graph structure.

Implements gum::IncrementalGraphLearner< AttributeSelection, isScalar >.

Definition at line 261 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().

261  {
262  this->_target->clear();
263  this->_target->manager()->setRootNode(
264  this->__insertNodeInFunctionGraph(this->_root));
265  }
NodeId __insertNodeInFunctionGraph(NodeId src)
Inserts an internal node in the target.
Definition: iti_tpl.h:276
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 143 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().

143  {
144  std::vector< NodeId > filo;
145  filo.push_back(this->_root);
146  HashTable< NodeId, Set< const DiscreteVariable* >* > potentialVars;
147  potentialVars.insert(this->_root,
148  new Set< const DiscreteVariable* >(this->_setOfVars));
149 
150 
151  while (!filo.empty()) {
152  NodeId currentNodeId = filo.back();
153  filo.pop_back();
154 
155  // First we look for the best var to install on the node
156  double bestValue = __attributeSelectionThreshold;
157  Set< const DiscreteVariable* > bestVars;
158 
159  for (auto varIter = potentialVars[currentNodeId]->cbeginSafe();
160  varIter != potentialVars[currentNodeId]->cendSafe();
161  ++varIter)
162  if (this->_nodeId2Database[currentNodeId]->isTestRelevant(*varIter)) {
163  double varValue =
164  this->_nodeId2Database[currentNodeId]->testValue(*varIter);
165  if (varValue >= bestValue) {
166  if (varValue > bestValue) {
167  bestValue = varValue;
168  bestVars.clear();
169  }
170  bestVars.insert(*varIter);
171  }
172  }
173 
174  // Then We installed Variable a test on that node
175  this->_updateNode(currentNodeId, bestVars);
176 
177  // The we move on the children if needed
178  if (this->_nodeVarMap[currentNodeId] != this->_value) {
179  for (Idx moda = 0; moda < this->_nodeVarMap[currentNodeId]->domainSize();
180  moda++) {
181  Set< const DiscreteVariable* >* itsPotentialVars =
182  new Set< const DiscreteVariable* >(*potentialVars[currentNodeId]);
183  itsPotentialVars->erase(this->_nodeVarMap[currentNodeId]);
184  NodeId sonId = this->_nodeSonsMap[currentNodeId][moda];
185  if (__staleTable[sonId]) {
186  filo.push_back(sonId);
187  potentialVars.insert(sonId, itsPotentialVars);
188  }
189  }
190  }
191  }
192 
193  for (HashTableIteratorSafe< NodeId, Set< const DiscreteVariable* >* >
194  nodeIter = potentialVars.beginSafe();
195  nodeIter != potentialVars.endSafe();
196  ++nodeIter)
197  delete nodeIter.val();
198  }
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:262
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:256
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:

◆ 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 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

◆ __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 262 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 259 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 256 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: