aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
graphChangesSelector4DiGraph.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
48#ifndef GUM_LEARNING_GRAPH_CHANGES_SELECTOR_4_DIGRAPH_H
49#define GUM_LEARNING_GRAPH_CHANGES_SELECTOR_4_DIGRAPH_H
50
51#include <vector>
52
53#include <agrum/agrum.h>
54
57
58namespace gum {
59
60 namespace learning {
61
74 template < typename INVARIABLE_CONSTRAINT_TYPE, typename VARIABLE_CONSTRAINT_TYPE >
76 public:
77 // ##########################################################################
79 // ##########################################################################
81
91 INVARIABLE_CONSTRAINT_TYPE& invariable_constraints,
92 VARIABLE_CONSTRAINT_TYPE& variable_constraints);
93
96 const GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE,
97 VARIABLE_CONSTRAINT_TYPE >& from);
98
101 VARIABLE_CONSTRAINT_TYPE >&& from);
102
105
107
108 // ##########################################################################
110 // ##########################################################################
112
115 operator=(const GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE,
116 VARIABLE_CONSTRAINT_TYPE >& from);
117
120 operator=(GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE,
121 VARIABLE_CONSTRAINT_TYPE >&& from);
122
124
125 // ##########################################################################
127 // ##########################################################################
129
131
133
135
141
143
150 double deltaScore(const GraphChange& change, const bool internal_change = false) const;
151
153 double score(const NodeId node) const;
154
156 void applyChange(const GraphChange& change);
157
159 bool isChangeValid(const GraphChange& change) const;
160
163
172
174 void useArcAdditions(bool use);
175
177 void useArcDeletions(bool use);
178
180 void useArcReversals(bool use);
181
184
187
190
193
196
198 INVARIABLE_CONSTRAINT_TYPE& invariableConstraints();
199
201 VARIABLE_CONSTRAINT_TYPE& variableConstraints();
202
204
205 private:
208
218 INVARIABLE_CONSTRAINT_TYPE* _invariable_constraints_;
219
227 VARIABLE_CONSTRAINT_TYPE* _variable_constraints_;
228
229
231 DiGraph* _graph_{nullptr};
232
235
238
252
258
263
265 double _scoreAfterAddingParent_(const NodeId node, const NodeId new_parent);
266
269 const NodeId new_parent1,
270 const NodeId new_parent2);
271
273 double _scoreAfterRemovingParent_(const NodeId node, const NodeId parent);
274
277 const NodeId parent1,
278 const NodeId parent2);
279
280
282
285
287
290
292
295
297
300
302
305
306
308 void _updateArcAdditionScore_(const NodeId tail, const NodeId head);
309
311 void _updateArcDeletionScore_(const NodeId tail, const NodeId head);
312
314 void _updateArcReversalScore_(const NodeId tail, const NodeId head);
315
319
320
323
326
329
332
333
335 void _applyArcAddition_(const ArcAddition& change, bool update_contraints);
336
338 void _applyArcDeletion_(const ArcDeletion& change, bool update_contraints);
339
341 void _applyArcReversal_(const ArcReversal& change, bool update_contraints);
342
344 void _applyArcTriangleDeletion1_(const ArcTriangleDeletion1& change, bool update_contraints);
345
347 void _applyArcTriangleDeletion2_(const ArcTriangleDeletion2& change, bool update_contraints);
348 };
349
350 } /* namespace learning */
351
352} /* namespace gum */
353
356
357#endif /* GUM_LEARNING_GRAPH_CHANGES_SELECTOR_4_DIGRAPH_H */
Base class for all oriented graphs.
Definition diGraph.h:132
A priority queue in which we can iterate over the elements from the top to bottom or conversely.
The class for notifying learning algorithms of new arc additions.
The class for notifying learning algorithms of arc removals.
The class for notifying learning algorithms of arc reversals.
The graph change substituting a triangle node1->node2->node3 + node1->node3 into v-structure node2->n...
The graph change substituting a triangle node1->node2->node3 + node1->node3 into v-structure node1->n...
void _updateArcAdditionScore_(const NodeId tail, const NodeId head)
updates the score of a given ArcAddition
double _scoreAfterAddingParents_(const NodeId node, const NodeId new_parent1, const NodeId new_parent2)
computes the new score of node given that we added it two new parents
void _applyArcDeletion_(const ArcDeletion &change, bool update_contraints)
indicate to the selector that an ArcDeletion has been applied
bool arcDeletionsEnabled() const
indicates whether the selector allows the application of arc deletions
void _updateTriangleDeletionsScoresFromNeighborhood_(const NodeId changed_node)
update the score of the triangle deletions which contain a node whose neighborhood has changed
SortedPriorityQueue< GraphChange, double > _sorted_changes_
the graph changes sorted by decreasing delta score value
INVARIABLE_CONSTRAINT_TYPE * _invariable_constraints_
the set of constraints which, for a given change, always return the same output
void _applyArcAddition_(const ArcAddition &change, bool update_contraints)
indicate to the selector that an ArcAddition has been applied
bool arcAdditionsEnabled() const
indicates whether the selector allows the application of arc additions
void useArcAdditions(bool use)
sets whether or not the selector allows the application of arc additions
void _initSortedChangesWithArcTriangleDeletions_(const DiGraph &graph)
add all the possible ArcTriangleDeletions to initialize sorted_changes
void _addArcReversalToSortedChanges_(const ArcReversal &change)
adds an ArcReversal to sorted_changes if possible
bool isChangeValid(const GraphChange &change) const
indicates whether a given change is valid or not
void finalizeGraph(DiGraph &graph)
adds some nodes that were removed because they did not belong to the database
void _updateArcReversalScore_(const NodeId tail, const NodeId head)
updates the score of a given ArcReversal
void _addArcTriangleDeletion2ToSortedChanges_(const ArcTriangleDeletion2 &change)
adds an ArcTriangleDeletion2 to sorted_changes if possible
GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE > & operator=(GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE > &&from)
move operator
double deltaScore(const GraphChange &change, const bool internal_change=false) const
return the score of a given change
void _applyArcTriangleDeletion1_(const ArcTriangleDeletion1 &change, bool update_contraints)
indicate to the selector that an ArcTriangleDeletion1 has been applied
void useArcDeletions(bool use)
sets whether or not the selector allows the application of arc deletions
double score(const NodeId node) const
returns the current score of a node
void _initSortedChangesWithArcDeletions_(const DiGraph &graph)
add all the possible ArcDeletions to initialize sorted_changes
bool arcReversalsEnabled() const
indicates whether the selector allows the application of arc reversals
GraphChangesSelector4DiGraph(Score &score, INVARIABLE_CONSTRAINT_TYPE &invariable_constraints, VARIABLE_CONSTRAINT_TYPE &variable_constraints)
default constructor
NodeProperty< std::vector< NodeId > > _node_parents_
the set of parents of each node (speeds-up score computations)
void _addArcTriangleDeletion1ToSortedChanges_(const ArcTriangleDeletion1 &change)
adds an ArcTriangleDeletion1 to sorted_changes if possible
void useArcReversals(bool use)
sets whether or not the selector allows the application of arc reversals
INVARIABLE_CONSTRAINT_TYPE & invariableConstraints()
returns the set of invariable constraints used by the selector
void useArcTriangleDeletions(bool use)
sets whether or not the selector allows the application of arc triangle deletions
void _addArcAdditionToSortedChanges_(const ArcAddition &change)
adds an ArcAddition to sorted_changes if possible
GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE > & operator=(const GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE > &from)
copy operator
void setGraph(DiGraph &graph)
sets the graph from which scores are computed
NodeProperty< double > _node_scores_
the current score of each node
void _applyArcReversal_(const ArcReversal &change, bool update_contraints)
indicate to the selector that an ArcReversal has been applied
double bestDeltaScore()
return the score of the best graph change
double _scoreAfterRemovingParent_(const NodeId node, const NodeId parent)
computes the new score of node given that we removed a parent
void applyChange(const GraphChange &change)
indicate to the selector that a change has been applied
bool arcTriangleDeletionsEnabled() const
indicates whether the selector allows the application of arc triangle deletions
VARIABLE_CONSTRAINT_TYPE * _variable_constraints_
the set of constraints whose outputs can change depending on the current graph
VARIABLE_CONSTRAINT_TYPE & variableConstraints()
returns the set of variable constraints used by the selector
NodeSet _removed_nodes_
the set of nodes removed from the graph passed in argument to the selector because they do not appear...
GraphChangesSelector4DiGraph(const GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE > &from)
copy constructor
const GraphChange & bestChange()
returns the best graph change to examine
double _scoreAfterAddingParent_(const NodeId node, const NodeId new_parent)
computes the new score of node given that we added it a new parent
void _addArcDeletionToSortedChanges_(const ArcDeletion &change)
adds an ArcDeletion to sorted_changes if possible
void _applyArcTriangleDeletion2_(const ArcTriangleDeletion2 &change, bool update_contraints)
indicate to the selector that an ArcTriangleDeletion2 has been applied
void _initSortedChangesWithArcAdditions_(const DiGraph &graph)
add all the possible ArcAdditions to initialize sorted_changes
GraphChangesSelector4DiGraph(GraphChangesSelector4DiGraph< INVARIABLE_CONSTRAINT_TYPE, VARIABLE_CONSTRAINT_TYPE > &&from)
move constructor
void _updateArcDeletionScore_(const NodeId tail, const NodeId head)
updates the score of a given ArcDeletion
double _scoreAfterRemovingParents_(const NodeId node, const NodeId parent1, const NodeId parent2)
computes the new score of node given that we removed two parents
void _initSortedChangesWithArcReversals_(const DiGraph &graph)
add all the possible ArcReversals to initialize sorted_changes
The base class for all the scores used for learning (BIC, BDeu, etc).
Definition score.h:68
The mecanism to compute the next available graph changes for directed structure learning search algor...
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
the base class for all the scores used for learning (BIC, BDeu, etc)
Priority queues which can be parsed using iterators.