![]() |
aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
|
<agrum/FMDP/learning/datastructure/incrementalGraphLearner> More...
#include <incrementalGraphLearner.h>
Public Member Functions | |
Function Graph Updating methods | |
| virtual void | updateFunctionGraph ()=0 |
| Updates target to currently learned graph structure. | |
Visit Methods | |
| Size | size () |
| NodeId | root () const override |
| bool | isTerminal (NodeId ni) const override |
| const DiscreteVariable * | nodeVar (NodeId ni) const override |
| NodeId | nodeSon (NodeId ni, Idx modality) const override |
| Idx | nodeNbObservation (NodeId ni) const override |
| void | insertSetOfVars (MultiDimFunctionGraph< double > *ret) const override |
Protected Attributes | |
| MultiDimFunctionGraph< double > * | target_ |
| The final diagram we're building. | |
| gum::VariableSet | setOfVars_ |
| const DiscreteVariable * | value_ |
| Sequence< ValueType > | valueAssumed_ |
| bool | needUpdate_ |
Model handling datastructures | |
| NodeGraphPart | model_ |
| The source of nodeId. | |
| NodeId | root_ |
| The root of the ordered tree. | |
| HashTable< NodeId, const DiscreteVariable * > | nodeVarMap_ |
| Gives for any node its associated variable. | |
| HashTable< NodeId, NodeId * > | nodeSonsMap_ |
| A table giving for any node a table mapping to its son idx is the modality of associated variable. | |
| HashTable< const DiscreteVariable *, LinkedList< NodeId > * > | var2Node_ |
| Associates to any variable the list of all nodes associated to this variable. | |
| HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > * > | nodeId2Database_ |
| This hashtable binds every node to an associated NodeDatabase which handles every observation that concerns that node. | |
| HashTable< NodeId, Set< const Observation * > * > | leafDatabase_ |
| This hashtable binds to every leaf an associated set of all hte observations compatible with it. | |
Private Types | |
| using | ValueType = typename ValueSelect< isScalar, double, Idx >::type |
Constructor & destructor. | |
| IncrementalGraphLearner (MultiDimFunctionGraph< double > *target, gum::VariableSet attributesSet, const DiscreteVariable *learnVariable) | |
| Default constructor. | |
| ~IncrementalGraphLearner () override | |
| Default destructor. | |
| void | _clearValue_ () |
| Template function dispatcher. | |
| void | _clearValue_ (Int2Type< true >) |
| In the case where we're learning a function of real values this has to be wiped out upon destruction (to be deprecated). | |
| void | _clearValue_ (Int2Type< false >) |
| In case where we're learning function of variable behaviour, this should do nothing. | |
New Observation insertion methods | |
| virtual void | addObservation (const Observation *obs) |
| Inserts a new observation. | |
| void | _assumeValue_ (const Observation *obs) |
| Get value assumed by studied variable for current observation. | |
| void | _assumeValue_ (const Observation *obs, Int2Type< true >) |
| Inserts a new observation. | |
| void | _assumeValue_ (const Observation *obs, Int2Type< false >) |
| Inserts a new observation. | |
| Idx | _branchObs_ (const Observation *obs, const DiscreteVariable *var) |
| Seek modality assumed in obs for given var. | |
| Idx | _branchObs_ (const Observation *obs, const DiscreteVariable *var, Int2Type< true >) |
| Inserts a new observation. | |
| Idx | _branchObs_ (const Observation *obs, const DiscreteVariable *var, Int2Type< false >) |
| Inserts a new observation. | |
| virtual void | updateNodeWithObservation_ (const Observation *newObs, NodeId currentNodeId) |
| Will update internal graph's NodeDatabase of given node with the new observation. | |
Graph Structure update methods | |
| virtual void | updateVar (const DiscreteVariable *) |
| If a new modality appears to exists for given variable, call this method to turn every associated node to this variable into leaf. Graph has then indeed to be revised. | |
| virtual void | updateGraph ()=0 |
| Updates the tree after a new observation has been added. | |
| void | updateNode_ (NodeId nody, gum::VariableSet &bestVars) |
| From the given sets of node, selects randomly one and installs it on given node. | |
| virtual void | convertNode2Leaf_ (NodeId) |
| Turns the given node into a leaf if not already so. | |
| virtual void | transpose_ (NodeId, const DiscreteVariable *) |
| Installs given variable to the given node, ensuring that the variable is not present in its subtree. | |
| virtual NodeId | insertNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar) |
| inserts a new node in internal graph | |
| virtual NodeId | insertInternalNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap) |
| inserts a new internal node in internal graph | |
| virtual NodeId | insertLeafNode_ (NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet) |
| inserts a new leaf node in internal graohs | |
| virtual void | chgNodeBoundVar_ (NodeId chgedNodeId, const DiscreteVariable *desiredVar) |
| Changes the associated variable of a node. | |
| virtual void | removeNode_ (NodeId removedNodeId) |
| Removes a node from the internal graph. | |
<agrum/FMDP/learning/datastructure/incrementalGraphLearner>
Abstract class for incrementally learn a graphical representation of a function. Can handle both function of real values, and function explaining the behaviour of a variable given set of other variables (as typically in conditional probabilities)
Maintains two graph in memory, one which is incrementally updated and the other one which is updated on demand and is usable by the outside.
Definition at line 83 of file incrementalGraphLearner.h.
|
private |
Definition at line 84 of file incrementalGraphLearner.h.
| gum::IncrementalGraphLearner< AttributeSelection, isScalar >::IncrementalGraphLearner | ( | MultiDimFunctionGraph< double > * | target, |
| gum::VariableSet | varList, | ||
| const DiscreteVariable * | value ) |
Default constructor.
| target | : the output diagram usable by the outside |
| attributesSet | : set of variables from which we try to describe the learned function |
| learnVariable | : if we tried to learn a the behaviour of a variable given variable given another set of variables, this is the one. If we are learning a function of real value, this is just a computationnal trick (and is to be deprecated) |
Definition at line 86 of file incrementalGraphLearner_tpl.h.
References IncrementalGraphLearner(), insertLeafNode_(), model_, root_, setOfVars_, target_, value_, and var2Node_.
Referenced by IncrementalGraphLearner().
|
override |
Default destructor.
Definition at line 107 of file incrementalGraphLearner_tpl.h.
References nodeId2Database_.
|
private |
Get value assumed by studied variable for current observation.
Definition at line 482 of file incrementalGraphLearner_tpl.h.
References _assumeValue_().
Referenced by _assumeValue_(), and addObservation().
|
private |
Inserts a new observation.
| the | new observation to learn |
Definition at line 496 of file incrementalGraphLearner_tpl.h.
References gum::Observation::modality(), value_, and valueAssumed_.
|
private |
Inserts a new observation.
| the | new observation to learn |
Definition at line 489 of file incrementalGraphLearner_tpl.h.
References gum::Observation::reward(), and valueAssumed_.
|
private |
Seek modality assumed in obs for given var.
Definition at line 502 of file incrementalGraphLearner_tpl.h.
References _branchObs_().
Referenced by _branchObs_().
|
private |
Inserts a new observation.
| the | new observation to learn |
Definition at line 517 of file incrementalGraphLearner_tpl.h.
References gum::Observation::modality().
|
private |
Inserts a new observation.
| the | new observation to learn |
Definition at line 509 of file incrementalGraphLearner_tpl.h.
References gum::Observation::rModality().
|
private |
Template function dispatcher.
Definition at line 469 of file incrementalGraphLearner_tpl.h.
References _clearValue_().
Referenced by _clearValue_().
|
private |
In case where we're learning function of variable behaviour, this should do nothing.
Definition at line 479 of file incrementalGraphLearner_tpl.h.
|
private |
In the case where we're learning a function of real values this has to be wiped out upon destruction (to be deprecated).
Definition at line 474 of file incrementalGraphLearner_tpl.h.
References value_.
|
virtual |
Inserts a new observation.
| the | new observation to learn |
Reimplemented in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.
Definition at line 137 of file incrementalGraphLearner_tpl.h.
References _assumeValue_(), nodeSonsMap_, and root_.
Referenced by gum::IMDDI< AttributeSelection, isScalar >::addObservation(), and gum::ITI< AttributeSelection, isScalar >::addObservation().
|
protectedvirtual |
Changes the associated variable of a node.
| chgedNodeId | : the node to change |
| desiredVar | : its new associated variable |
Reimplemented in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.
Definition at line 413 of file incrementalGraphLearner_tpl.h.
References leafDatabase_, needUpdate_, nodeVarMap_, value_, and var2Node_.
Referenced by gum::IMDDI< AttributeSelection, isScalar >::chgNodeBoundVar_(), and gum::ITI< AttributeSelection, isScalar >::chgNodeBoundVar_().
|
protectedvirtual |
Turns the given node into a leaf if not already so.
Definition at line 218 of file incrementalGraphLearner_tpl.h.
References leafDatabase_, nodeVarMap_, and value_.
Referenced by updateNode_(), and updateVar().
|
protectedvirtual |
inserts a new internal node in internal graph
| nDB | : the associated database |
| boundVar | : the associated variable |
| sonsMap | : a table giving node's sons node |
Definition at line 377 of file incrementalGraphLearner_tpl.h.
References insertNode_(), and nodeSonsMap_.
|
protectedvirtual |
inserts a new leaf node in internal graohs
| nDB | : the associated database |
| boundVar | : the associated variable |
| obsSet | : the set of observation this leaf retains |
Reimplemented in gum::IMDDI< AttributeSelection, isScalar >.
Definition at line 396 of file incrementalGraphLearner_tpl.h.
References insertNode_(), and leafDatabase_.
Referenced by IncrementalGraphLearner(), and gum::IMDDI< AttributeSelection, isScalar >::insertLeafNode_().
|
protectedvirtual |
inserts a new node in internal graph
| nDB | : the associated database |
| boundVar | : the associated variable |
Reimplemented in gum::ITI< AttributeSelection, isScalar >.
Definition at line 354 of file incrementalGraphLearner_tpl.h.
References model_, needUpdate_, nodeId2Database_, nodeVarMap_, and var2Node_.
Referenced by insertInternalNode_(), insertLeafNode_(), and gum::ITI< AttributeSelection, isScalar >::insertNode_().
|
overridevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 564 of file incrementalGraphLearner_tpl.h.
References gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::add(), and setOfVars_.
|
overridevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 535 of file incrementalGraphLearner_tpl.h.
References nodeSonsMap_.
|
overridevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 552 of file incrementalGraphLearner_tpl.h.
References nodeId2Database_.
|
overridevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 546 of file incrementalGraphLearner_tpl.h.
References nodeSonsMap_.
|
overridevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 541 of file incrementalGraphLearner_tpl.h.
References nodeVarMap_.
|
protectedvirtual |
Removes a node from the internal graph.
| removedNodeId | : the node to remove |
Reimplemented in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.
Definition at line 441 of file incrementalGraphLearner_tpl.h.
References leafDatabase_, model_, needUpdate_, nodeId2Database_, nodeSonsMap_, nodeVarMap_, SOA_DEALLOCATE, and var2Node_.
Referenced by gum::IMDDI< AttributeSelection, isScalar >::removeNode_(), and gum::ITI< AttributeSelection, isScalar >::removeNode_().
|
overridevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 530 of file incrementalGraphLearner_tpl.h.
References root_.
| Size gum::IncrementalGraphLearner< AttributeSelection, isScalar >::size | ( | ) |
Definition at line 525 of file incrementalGraphLearner_tpl.h.
References nodeVarMap_.
|
protectedvirtual |
Installs given variable to the given node, ensuring that the variable is not present in its subtree.
Definition at line 244 of file incrementalGraphLearner_tpl.h.
|
pure virtual |
Updates target to currently learned graph structure.
Implemented in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.
|
pure virtual |
Updates the tree after a new observation has been added.
Implemented in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.
|
protected |
From the given sets of node, selects randomly one and installs it on given node.
Chechks of course if node's current variable is not in that set first.
| 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.
| nody | : the node we update |
| bestVar | : the set of interessting vars to be installed here |
Definition at line 188 of file incrementalGraphLearner_tpl.h.
References convertNode2Leaf_(), and gum::Set< Key >::empty().
|
protectedvirtual |
Will update internal graph's NodeDatabase of given node with the new observation.
| newObs | |
| currentNodeId |
Reimplemented in gum::IMDDI< AttributeSelection, isScalar >, and gum::ITI< AttributeSelection, isScalar >.
Definition at line 557 of file incrementalGraphLearner_tpl.h.
References nodeId2Database_.
Referenced by gum::IMDDI< AttributeSelection, isScalar >::updateNodeWithObservation_(), and gum::ITI< AttributeSelection, isScalar >::updateNodeWithObservation_().
|
virtual |
If a new modality appears to exists for given variable, call this method to turn every associated node to this variable into leaf. Graph has then indeed to be revised.
Definition at line 167 of file incrementalGraphLearner_tpl.h.
References convertNode2Leaf_(), gum::Link< T >::element(), gum::Link< T >::nextLink(), and var2Node_.
|
protected |
This hashtable binds to every leaf an associated set of all hte observations compatible with it.
Definition at line 364 of file incrementalGraphLearner.h.
Referenced by chgNodeBoundVar_(), convertNode2Leaf_(), insertLeafNode_(), and removeNode_().
|
protected |
The source of nodeId.
Definition at line 330 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), insertNode_(), and removeNode_().
|
protected |
Definition at line 377 of file incrementalGraphLearner.h.
Referenced by chgNodeBoundVar_(), insertNode_(), and removeNode_().
|
protected |
This hashtable binds every node to an associated NodeDatabase which handles every observation that concerns that node.
Definition at line 358 of file incrementalGraphLearner.h.
Referenced by ~IncrementalGraphLearner(), insertNode_(), nodeNbObservation(), removeNode_(), and updateNodeWithObservation_().
|
protected |
A table giving for any node a table mapping to its son idx is the modality of associated variable.
Definition at line 346 of file incrementalGraphLearner.h.
Referenced by addObservation(), insertInternalNode_(), isTerminal(), nodeSon(), and removeNode_().
|
protected |
Gives for any node its associated variable.
Definition at line 340 of file incrementalGraphLearner.h.
Referenced by chgNodeBoundVar_(), convertNode2Leaf_(), insertNode_(), nodeVar(), removeNode_(), and size().
|
protected |
The root of the ordered tree.
Definition at line 335 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), addObservation(), and root().
|
protected |
Definition at line 372 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), and insertSetOfVars().
|
protected |
The final diagram we're building.
Definition at line 370 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner().
|
protected |
Definition at line 374 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), _assumeValue_(), _clearValue_(), chgNodeBoundVar_(), and convertNode2Leaf_().
|
protected |
Definition at line 375 of file incrementalGraphLearner.h.
Referenced by _assumeValue_(), and _assumeValue_().
|
protected |
Associates to any variable the list of all nodes associated to this variable.
Definition at line 352 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), chgNodeBoundVar_(), insertNode_(), removeNode_(), and updateVar().