84 template < TESTNAME AttributeSelection,
bool isScalar >
105 template < TESTNAME AttributeSelection,
bool isScalar >
109 delete nodeIter.val();
115 delete varIter.val();
118 delete nodeIter.val();
135 template < TESTNAME AttributeSelection,
bool isScalar >
152 updateNodeWithObservation_(newObs, currentNodeId);
153 leafDatabase_[currentNodeId]->insert(newObs);
165 template < TESTNAME AttributeSelection,
bool isScalar >
186 template < TESTNAME AttributeSelection,
bool isScalar >
191 if (varsOfInterest.
empty()) {
204 SetConstIteratorSafe< const DiscreteVariable* > varIter;
205 for (varIter = varsOfInterest.
cbeginSafe(), basc = 0;
206 varIter != varsOfInterest.
cendSafe() && basc < randy;
216 template < TESTNAME AttributeSelection,
bool isScalar >
223 for (
Idx modality = 0; modality <
nodeVarMap_[currentNodeId]->domainSize(); ++modality) {
242 template < TESTNAME AttributeSelection,
bool isScalar >
249 if (
nodeVarMap_[currentNodeId] == desiredVar) {
return; }
254 if (nodeVarMap_[currentNodeId] == value_) {
266 for (
Idx modality = 0; modality < desiredVar->
domainSize(); ++modality) {
275 obsetMap[
_branchObs_(*obsIter, desiredVar)]->insert(*obsIter);
281 for (
Idx modality = 0; modality < desiredVar->
domainSize(); ++modality)
302 for (
Idx modality = 0; modality < nodeVarMap_[currentNodeId]->domainSize(); ++modality)
303 transpose_(nodeSonsMap_[currentNodeId][modality], desiredVar);
312 for (
Idx desiredVarModality = 0; desiredVarModality < desiredVar->
domainSize();
313 ++desiredVarModality) {
318 for (
Idx currentVarModality = 0;
319 currentVarModality < nodeVarMap_[currentNodeId]->domainSize();
320 ++currentVarModality) {
321 grandSonsMap[currentVarModality]
322 = nodeSonsMap_[nodeSonsMap_[currentNodeId][currentVarModality]][desiredVarModality];
323 sonDB->operator+=((*nodeId2Database_[grandSonsMap[currentVarModality]]));
326 sonsMap[desiredVarModality]
327 = insertInternalNode_(sonDB, nodeVarMap_[currentNodeId], grandSonsMap);
331 for (
Idx currentVarModality = 0; currentVarModality < nodeVarMap_[currentNodeId]->domainSize();
332 ++currentVarModality) {
333 removeNode_(nodeSonsMap_[currentNodeId][currentVarModality]);
338 sizeof(
NodeId) * nodeVarMap_[currentNodeId]->domainSize());
339 nodeSonsMap_[currentNodeId] = sonsMap;
341 chgNodeBoundVar_(currentNodeId, desiredVar);
352 template < TESTNAME AttributeSelection,
bool isScalar >
375 template < TESTNAME AttributeSelection,
bool isScalar >
394 template < TESTNAME AttributeSelection,
bool isScalar >
411 template < TESTNAME AttributeSelection,
bool isScalar >
415 if (
nodeVarMap_[currentNodeId] == desiredVar)
return;
418 var2Node_[desiredVar]->addLink(currentNodeId);
439 template < TESTNAME AttributeSelection,
bool isScalar >
442 model_.eraseNode(currentNodeId);
Headers of the ChiSquare class.
Base class for discrete random variable.
virtual Size domainSize() const =0
virtual void transpose_(NodeId, const DiscreteVariable *)
virtual void updateVar(const DiscreteVariable *)
If a new modality appears to exists for given variable, call this method to turn every associated nod...
virtual ~IncrementalGraphLearner()
Default destructor.
virtual NodeId insertLeafNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, Set< const Observation * > *obsSet)
inserts a new leaf node in internal graohs
HashTable< const DiscreteVariable *, LinkedList< NodeId > * > var2Node_
Associates to any variable the list of all nodes associated to this variable.
NodeGraphPart model_
The source of nodeId.
Idx _branchObs_(const Observation *obs, const DiscreteVariable *var)
NodeId root_
The root of the ordered tree.
HashTable< NodeId, NodeId * > nodeSonsMap_
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > * > nodeId2Database_
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
const DiscreteVariable * value_
virtual void addObservation(const Observation *obs)
Inserts a new observation.
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.
gum::VariableSet setOfVars_
virtual NodeId insertNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar)
inserts a new node in internal graph
void _assumeValue_(const Observation *obs)
Get value assumed by studied variable for current observation.
virtual void updateNodeWithObservation_(const Observation *newObs, NodeId currentNodeId)
MultiDimFunctionGraph< double > * target_
The final diagram we're building.
HashTable< NodeId, Set< const Observation * > * > leafDatabase_
HashTable< NodeId, const DiscreteVariable * > nodeVarMap_
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, gum::VariableSet attributesSet, const DiscreteVariable *learnVariable)
Default constructor.
virtual void removeNode_(NodeId removedNodeId)
virtual void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable *desiredVar)
virtual NodeId insertInternalNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
inserts a new internal node in internal graph
const Link< T > * nextLink() const
Returns next link.
const T & element() const
Returns the element stored in this link.
<agrum/FMDP/learning/datastructure/nodeDatabase.h>
void addObservation(const Observation *)
Nb observation taken into account by this instance.
Safe iterators for the Set class.
Size size() const noexcept
Returns the number of elements in the set.
const_iterator_safe cbeginSafe() const
The usual safe begin iterator to parse the set.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
const const_iterator_safe & cendSafe() const noexcept
The usual safe end iterator to parse the set.
bool empty() const noexcept
Indicates whether the set is the empty set.
Base class for discrete random variable.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
Idx randomValue(const Size max=2)
Returns a random Idx between 0 and max-1 included.
Headers of the interface specifying functions to be implemented by any incremental learner.
Priority queues in which the same element can appear several times.
gum is the global namespace for all aGrUM entities
Set< const DiscreteVariable * > VariableSet
#define SOA_DEALLOCATE(x, y)
Provides basic types used in aGrUM.
Contains useful methods for random stuff.