aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
incrementalGraphLearner.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2026 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
49
50// =========================================================================
51#ifndef GUM_INCREMENTAL_GRAPH_LEARNER_H
52#define GUM_INCREMENTAL_GRAPH_LEARNER_H
53// =========================================================================
54// =========================================================================
55// =========================================================================
58
59// =========================================================================
60// =========================================================================
61
62namespace gum {
63
82 template < TESTNAME AttributeSelection, bool isScalar = false >
85
86 public:
87 // ###################################################################
89 // ###################################################################
91
92 // ==========================================================================
103 // ==========================================================================
105 gum::VariableSet attributesSet,
106 const DiscreteVariable* learnVariable);
107
108 // ==========================================================================
110 // ==========================================================================
111 ~IncrementalGraphLearner() override;
112
113 private:
114 // ==========================================================================
116 // ==========================================================================
117 void _clearValue_();
118
119 // ==========================================================================
122 // ==========================================================================
124
125 // ==========================================================================
128 // ==========================================================================
130
132
133
134 // ###################################################################
136 // ###################################################################
138
139 public:
140 // ==========================================================================
144 // ==========================================================================
145 virtual void addObservation(const Observation* obs);
146
147 private:
148 // ==========================================================================
152 // ==========================================================================
153 void _assumeValue_(const Observation* obs);
154
156
158
159 // ==========================================================================
163 // ==========================================================================
164 Idx _branchObs_(const Observation* obs, const DiscreteVariable* var);
165
167
169
170 protected:
171 // ==========================================================================
178 // ==========================================================================
179 virtual void updateNodeWithObservation_(const Observation* newObs, NodeId currentNodeId);
180
182
183 // ###################################################################
185 // ###################################################################
187
188 public:
189 // ==========================================================================
194 // ==========================================================================
195 virtual void updateVar(const DiscreteVariable*);
196
197 // ==========================================================================
199 // ==========================================================================
200 virtual void updateGraph() = 0;
201
202 protected:
203 // ==========================================================================
212 // ==========================================================================
213 void updateNode_(NodeId nody, gum::VariableSet& bestVars);
214
215 // ==========================================================================
217 // ==========================================================================
218 virtual void convertNode2Leaf_(NodeId);
219
220 // ==========================================================================
223 // ==========================================================================
224 virtual void transpose_(NodeId, const DiscreteVariable*);
225
226 // ==========================================================================
233 // ==========================================================================
235 const DiscreteVariable* boundVar);
236
237 // ==========================================================================
245 // ==========================================================================
247 const DiscreteVariable* boundVar,
248 NodeId* sonsMap);
249
250 // ==========================================================================
258 // ==========================================================================
260 const DiscreteVariable* boundVar,
262
263 // ==========================================================================
269 // ==========================================================================
270 virtual void chgNodeBoundVar_(NodeId chgedNodeId, const DiscreteVariable* desiredVar);
271
272 // ==========================================================================
277 // ==========================================================================
278 virtual void removeNode_(NodeId removedNodeId);
279
281
282
283 // ###################################################################
285 // ###################################################################
287
288 public:
289 // ==========================================================================
291 // ==========================================================================
292 virtual void updateFunctionGraph() = 0;
293
295
296
297 public:
298 // ###################################################################
300 // ###################################################################
302
303 Size size();
304
305 NodeId root() const override;
306
307 bool isTerminal(NodeId ni) const override;
308
309 const DiscreteVariable* nodeVar(NodeId ni) const override;
310
311 NodeId nodeSon(NodeId ni, Idx modality) const override;
312
313 Idx nodeNbObservation(NodeId ni) const override;
314
315 void insertSetOfVars(MultiDimFunctionGraph< double >* ret) const override;
316
318
319 protected:
321
322 // ###################################################################
324 // ###################################################################
326
327 // ==========================================================================
329 // ==========================================================================
331
332 // ==========================================================================
334 // ==========================================================================
336
337 // ==========================================================================
339 // ==========================================================================
341
342 // ==========================================================================
345 // ==========================================================================
347
348 // ==========================================================================
351 // ==========================================================================
353
354 // ==========================================================================
357 // ==========================================================================
359
360 // ==========================================================================
363 // ==========================================================================
365
367
368
371
373
376
378 };
379
380
381} /* namespace gum */
382
384
385#endif // GUM_INCREMENTAL_GRAPH_LEARNER_H
Headers of the Learning Strategy interface.
Base class for discrete random variable.
The class for generic Hash Tables.
Definition hashTable.h:640
<agrum/FMDP/SDyna/IVisitableGraphLearner.h>
virtual void updateNodeWithObservation_(const Observation *newObs, NodeId currentNodeId)
Will update internal graph's NodeDatabase of given node with the new observation.
NodeId nodeSon(NodeId ni, Idx modality) const override
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 updateVar(const DiscreteVariable *)
If a new modality appears to exists for given variable, call this method to turn every associated nod...
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)
Seek modality assumed in obs for given var.
NodeId root_
The root of the ordered tree.
HashTable< NodeId, NodeId * > nodeSonsMap_
A table giving for any node a table mapping to its son idx is the modality of associated variable.
HashTable< NodeId, NodeDatabase< AttributeSelection, isScalar > * > nodeId2Database_
This hashtable binds every node to an associated NodeDatabase which handles every observation that co...
virtual void addObservation(const Observation *obs)
Inserts a new observation.
typename ValueSelect< isScalar, double, Idx >::type ValueType
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 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.
const DiscreteVariable * nodeVar(NodeId ni) const override
MultiDimFunctionGraph< double > * target_
The final diagram we're building.
~IncrementalGraphLearner() override
Default destructor.
HashTable< NodeId, Set< const Observation * > * > leafDatabase_
This hashtable binds to every leaf an associated set of all hte observations compatible with it.
Idx nodeNbObservation(NodeId ni) const override
void _clearValue_()
Template function dispatcher.
virtual void updateFunctionGraph()=0
Updates target to currently learned graph structure.
HashTable< NodeId, const DiscreteVariable * > nodeVarMap_
Gives for any node its associated variable.
void insertSetOfVars(MultiDimFunctionGraph< double > *ret) const override
IncrementalGraphLearner(MultiDimFunctionGraph< double > *target, gum::VariableSet attributesSet, const DiscreteVariable *learnVariable)
Default constructor.
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.
bool isTerminal(NodeId ni) const override
virtual void updateGraph()=0
Updates the tree after a new observation has been added.
virtual NodeId insertInternalNode_(NodeDatabase< AttributeSelection, isScalar > *nDB, const DiscreteVariable *boundVar, NodeId *sonsMap)
inserts a new internal node in internal graph
<agrum/FMDP/learning/datastructure/nodeDatabase.h>
Class for node sets in graph.
Representation of a set.
Definition set.h:129
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
Headers of the NodeDatabase class.