aGrUM  0.16.0
graphChangesSelector4DiGraph.h
Go to the documentation of this file.
1 
29 #ifndef GUM_LEARNING_GRAPH_CHANGES_SELECTOR_4_DIGRAPH_H
30 #define GUM_LEARNING_GRAPH_CHANGES_SELECTOR_4_DIGRAPH_H
31 
32 #include <vector>
33 
34 #include <agrum/agrum.h>
36 #include <agrum/core/sequence.h>
37 #include <agrum/core/set.h>
38 #include <agrum/graphs/diGraph.h>
41 
42 namespace gum {
43 
44  namespace learning {
45 
51  template < typename STRUCTURAL_CONSTRAINT,
52  typename GRAPH_CHANGES_GENERATOR,
53  template < typename > class ALLOC = std::allocator >
55  public:
57  using GeneratorType = GRAPH_CHANGES_GENERATOR;
58 
59  // ##########################################################################
61  // ##########################################################################
63 
66  STRUCTURAL_CONSTRAINT& constraint,
67  GRAPH_CHANGES_GENERATOR& changes_generator);
68 
71  const GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT,
72  GRAPH_CHANGES_GENERATOR,
73  ALLOC >& from);
74 
77  GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT,
78  GRAPH_CHANGES_GENERATOR,
79  ALLOC >&& from);
80 
83 
85 
86  // ##########################################################################
88  // ##########################################################################
90 
92  GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT,
93  GRAPH_CHANGES_GENERATOR,
94  ALLOC >&
95  operator=(const GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT,
96  GRAPH_CHANGES_GENERATOR,
97  ALLOC >& from);
98 
100  GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT,
101  GRAPH_CHANGES_GENERATOR,
102  ALLOC >&
103  operator=(GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT,
104  GRAPH_CHANGES_GENERATOR,
105  ALLOC >&& from);
106 
108 
109  // ##########################################################################
111  // ##########################################################################
113 
115  GeneratorType& graphChangeGenerator() const noexcept;
116 
118  bool empty();
119 
123  bool empty(const NodeId i);
124 
126 
127  const GraphChange& bestChange();
128 
130 
135  const GraphChange& bestChange(const NodeId i);
136 
138 
139  double bestScore();
140 
142 
147  double bestScore(const NodeId i);
148 
150  void applyChange(const GraphChange& change);
151 
153 
159  void applyChangeWithoutScoreUpdate(const GraphChange& change);
160 
162 
167 
169  bool isChangeValid(const GraphChange& change) const;
170 
172  void setGraph(DiGraph& graph);
173 
175  std::vector< std::pair< NodeId, double > > nodesSortedByBestScore() const;
176 
178  std::vector< std::pair< NodeId, double > > nodesUnsortedWithScore() const;
179 
181 
182  private:
184  Score< ALLOC >* __score;
185 
187  STRUCTURAL_CONSTRAINT* __constraint;
188 
190  GRAPH_CHANGES_GENERATOR* __changes_generator;
191 
194 
196 
197  std::vector< std::pair< double, double > > __change_scores;
198 
200 
202  NodeProperty< PriorityQueue< std::size_t, double, std::greater< double > > >
204 
206  PriorityQueue< NodeId, double, std::greater< double > > __node_queue;
207 
209 
212 
215 
217  NodeProperty< std::vector< NodeId, ALLOC< NodeId > > > __parents;
218 
220  bool __queues_valid{false};
221 
224 
226  bool __isChangeValid(const std::size_t index) const;
227 
229  void __invalidateChange(const std::size_t change_index);
230 
232  void __illegal2LegalChanges(Set< std::size_t >& changes_to_recompute);
233 
235  void
237  const NodeId target_node);
238 
240  void __updateScores(const Set< std::size_t >& changes_to_recompute);
241 
243  void __getNewChanges();
244  };
245 
246  } /* namespace learning */
247 
248 } /* namespace gum */
249 
252 
253 #endif /* GUM_LEARNING_GRAPH_CHANGES_SELECTOR_4_DIGRAPH_H */
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
NodeProperty< double > __node_current_scores
the current score of each node
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool empty()
indicates whether the selector still contains graph changes
The base class for all the scores used for learning (BIC, BDeu, etc)
Definition: score.h:52
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
GeneratorType & graphChangeGenerator() const noexcept
returns the generator used by the selector
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void __updateScores(const Set< std::size_t > &changes_to_recompute)
perform the necessary updates of the scores
STRUCTURAL_CONSTRAINT * __constraint
the set of constraints used to determine valid changes
The generic class for storing (ordered) sequences of objects.
Definition: sequence.h:1022
GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT, GRAPH_CHANGES_GENERATOR, ALLOC > & operator=(const GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT, GRAPH_CHANGES_GENERATOR, ALLOC > &from)
copy operator
const GraphChange & bestChange()
returns the best graph change to examine
STL namespace.
void applyChange(const GraphChange &change)
indicate to the selector that a change has been applied
Set< std::size_t > __illegal_changes
the set of changes known to be currently illegal (due to the constraints)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
PriorityQueue< NodeId, double, std::greater< double > > __node_queue
a global priority queue indicating for each node its best score
The class for generic Hash Tables.
Definition: hashTable.h:679
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::vector< std::pair< double, double > > __change_scores
the scores for the head and tail of all the changes
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:165
The mecanism to compute the next available graph changes for directed structure learning search algor...
void applyChangeWithoutScoreUpdate(const GraphChange &change)
indicate to the selector that one of serveral changes has been applied
A priorityQueue is a heap in which each element has a mutable priorityA priority queue is quite simil...
Definition: priorityQueue.h:51
bool __isChangeValid(const std::size_t index) const
indicates whether a given change is valid or not
NodeProperty< std::vector< NodeId, ALLOC< NodeId > > > __parents
the set of parents of each node (speeds-up score computations)
Base class for all oriented graphs.
Definition: diGraph.h:111
Set< NodeId > __queues_to_update
the set of queues to update when applying several changes
double bestScore()
return the score of the best graph change
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool __queues_valid
indicates whether we need to recompute whether the queue is empty or not
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
GraphChangesSelector4DiGraph(Score< ALLOC > &score, STRUCTURAL_CONSTRAINT &constraint, GRAPH_CHANGES_GENERATOR &changes_generator)
default constructor
void updateScoresAfterAppliedChanges()
recompute all the scores after the application of several changes
std::vector< std::pair< NodeId, double > > nodesUnsortedWithScore() const
returns the set of queues top priorities
Sequence< GraphChange > __changes
a sequence containing all the possible changes
std::vector< std::pair< NodeId, double > > nodesSortedByBestScore() const
returns the set of queues sorted by decreasing top priority
void __invalidateChange(const std::size_t change_index)
put a change into the illegal set
void __findLegalChangesNeedingUpdate(Set< std::size_t > &changes_to_recompute, const NodeId target_node)
finds the changes that are affected by a given node modification
void __illegal2LegalChanges(Set< std::size_t > &changes_to_recompute)
remove the now legal changes from the illegal set
void setGraph(DiGraph &graph)
sets the graph from which scores are computed
GRAPH_CHANGES_GENERATOR GeneratorType
the type of the generator
GRAPH_CHANGES_GENERATOR * __changes_generator
the generator that returns the set of possible changes
void __getNewChanges()
get from the graph change generator a new set of changes
bool isChangeValid(const GraphChange &change) const
indicates whether a given change is valid or not
Size NodeId
Type for node ids.
Definition: graphElements.h:98
NodeProperty< PriorityQueue< std::size_t, double, std::greater< double > > > __change_queue_per_node
for each node, a priority queue sorting GraphChanges by decreasing score