![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
<agrum/FMDP/learning/datastructure/incrementalGraphLearner> More...
#include <incrementalGraphLearner.h>
Public Member Functions | |
| Size | size () |
Function Graph Updating methods | |
| virtual void | updateFunctionGraph ()=0 |
| Updates target to currently learned graph structure. | |
Visit Methods | |
| NodeId | root () const |
| bool | isTerminal (NodeId ni) const |
| const DiscreteVariable * | nodeVar (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. | |
| 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. | |
| virtual | ~IncrementalGraphLearner () |
| 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 85 of file incrementalGraphLearner_tpl.h.
References IncrementalGraphLearner(), insertLeafNode_(), model_, root_, setOfVars_, target_, value_, and var2Node_.
Referenced by IncrementalGraphLearner().
|
virtual |
Default destructor.
Definition at line 106 of file incrementalGraphLearner_tpl.h.
References nodeId2Database_.
|
inlineprivate |
Get value assumed by studied variable for current observation.
Definition at line 153 of file incrementalGraphLearner.h.
References _assumeValue_().
Referenced by _assumeValue_(), and addObservation().
|
inlineprivate |
Inserts a new observation.
| the | new observation to learn |
Definition at line 159 of file incrementalGraphLearner.h.
References gum::Observation::modality(), value_, and valueAssumed_.
|
inlineprivate |
Inserts a new observation.
| the | new observation to learn |
Definition at line 155 of file incrementalGraphLearner.h.
References gum::Observation::reward(), and valueAssumed_.
|
inlineprivate |
Seek modality assumed in obs for given var.
Definition at line 168 of file incrementalGraphLearner.h.
References _branchObs_().
Referenced by _branchObs_().
|
inlineprivate |
Inserts a new observation.
| the | new observation to learn |
Definition at line 176 of file incrementalGraphLearner.h.
References gum::Observation::modality().
|
inlineprivate |
Inserts a new observation.
| the | new observation to learn |
Definition at line 172 of file incrementalGraphLearner.h.
References gum::Observation::rModality().
|
inlineprivate |
Template function dispatcher.
Definition at line 117 of file incrementalGraphLearner.h.
References _clearValue_().
Referenced by _clearValue_().
|
inlineprivate |
In case where we're learning function of variable behaviour, this should do nothing.
Definition at line 129 of file incrementalGraphLearner.h.
|
inlineprivate |
In the case where we're learning a function of real values this has to be wiped out upon destruction (to be deprecated).
Definition at line 123 of file incrementalGraphLearner.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 136 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 412 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 217 of file incrementalGraphLearner_tpl.h.
References leafDatabase_, nodeSonsMap_, 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 376 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 395 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 353 of file incrementalGraphLearner_tpl.h.
References model_, needUpdate_, nodeId2Database_, nodeVarMap_, and var2Node_.
Referenced by insertInternalNode_(), insertLeafNode_(), and gum::ITI< AttributeSelection, isScalar >::insertNode_().
|
inlinevirtual |
Implements gum::IVisitableGraphLearner.
Reimplemented in gum::IMDDI< AttributeSelection, isScalar >.
Definition at line 349 of file incrementalGraphLearner.h.
References gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::add(), and setOfVars_.
|
inlinevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 329 of file incrementalGraphLearner.h.
References nodeSonsMap_.
|
inlinevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 344 of file incrementalGraphLearner.h.
References nodeId2Database_.
|
inlinevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 339 of file incrementalGraphLearner.h.
References nodeSonsMap_.
|
inlinevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 334 of file incrementalGraphLearner.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 440 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_().
|
inlinevirtual |
Implements gum::IVisitableGraphLearner.
Definition at line 324 of file incrementalGraphLearner.h.
References root_.
|
inline |
|
protectedvirtual |
Installs given variable to the given node, ensuring that the variable is not present in its subtree.
Definition at line 243 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 187 of file incrementalGraphLearner_tpl.h.
References gum::Set< Key >::cbeginSafe(), gum::Set< Key >::cendSafe(), convertNode2Leaf_(), gum::Set< Key >::empty(), gum::Set< Key >::exists(), nodeVarMap_, gum::randomValue(), and gum::Set< Key >::size().
|
inlineprotectedvirtual |
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 189 of file incrementalGraphLearner.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 166 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 403 of file incrementalGraphLearner.h.
Referenced by chgNodeBoundVar_(), convertNode2Leaf_(), insertLeafNode_(), and removeNode_().
|
protected |
The source of nodeId.
Definition at line 369 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), insertNode_(), and removeNode_().
|
protected |
Definition at line 416 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 397 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 385 of file incrementalGraphLearner.h.
Referenced by addObservation(), convertNode2Leaf_(), insertInternalNode_(), isTerminal(), nodeSon(), and removeNode_().
|
protected |
Gives for any node its associated variable.
Definition at line 379 of file incrementalGraphLearner.h.
Referenced by chgNodeBoundVar_(), convertNode2Leaf_(), insertNode_(), nodeVar(), removeNode_(), size(), and updateNode_().
|
protected |
The root of the ordered tree.
Definition at line 374 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), addObservation(), and root().
|
protected |
Definition at line 411 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), and insertSetOfVars().
|
protected |
The final diagram we're building.
Definition at line 409 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner().
|
protected |
Definition at line 413 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), _assumeValue_(), _clearValue_(), chgNodeBoundVar_(), and convertNode2Leaf_().
|
protected |
Definition at line 414 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 391 of file incrementalGraphLearner.h.
Referenced by IncrementalGraphLearner(), chgNodeBoundVar_(), insertNode_(), removeNode_(), and updateVar().