28 #ifndef GUM_LEARNING_GRAPH_CHANGES_SELECTOR_4_DIGRAPH_H 29 #define GUM_LEARNING_GRAPH_CHANGES_SELECTOR_4_DIGRAPH_H 33 #include <agrum/agrum.h> 34 #include <agrum/tools/core/priorityQueue.h> 35 #include <agrum/tools/core/sequence.h> 36 #include <agrum/tools/core/set.h> 37 #include <agrum/tools/graphs/diGraph.h> 38 #include <agrum/BN/learning/scores_and_tests/score.h> 39 #include <agrum/BN/learning/structureUtils/graphChange.h> 50 template <
typename STRUCTURAL_CONSTRAINT,
51 typename GRAPH_CHANGES_GENERATOR,
52 template <
typename >
class ALLOC = std::allocator >
56 using GeneratorType = GRAPH_CHANGES_GENERATOR;
65 STRUCTURAL_CONSTRAINT& constraint,
66 GRAPH_CHANGES_GENERATOR& changes_generator);
70 GRAPH_CHANGES_GENERATOR,
75 GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT, GRAPH_CHANGES_GENERATOR, ALLOC >&&
116 bool empty(
const NodeId i);
229 const NodeId target_node);
232 void _updateScores_(
const Set< std::size_t >& changes_to_recompute);
243 #include <agrum/BN/learning/structureUtils/graphChangesSelector4DiGraph_tpl.h> void _invalidateChange_(const std::size_t change_index)
put a change into the illegal set
void _illegal2LegalChanges_(Set< std::size_t > &changes_to_recompute)
remove the now legal changes from the illegal set
bool empty()
indicates whether the selector still contains graph changes
Set< NodeId > _queues_to_update_
the set of queues to update when applying several changes
GeneratorType & graphChangeGenerator() const noexcept
returns the generator used by the selector
INLINE void emplace(Args &&... args)
bool _queues_valid_
indicates whether we need to recompute whether the queue is empty or not
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
NodeProperty< double > _node_current_scores_
the current score of each node
void applyChange(const GraphChange &change)
indicate to the selector that a change has been applied
void _getNewChanges_()
get from the graph change generator a new set of changes
std::vector< std::pair< double, double > > _change_scores_
the scores for the head and tail of all the changes
void _findLegalChangesNeedingUpdate_(Set< std::size_t > &changes_to_recompute, const NodeId target_node)
finds the changes that are affected by a given node modification
Sequence< GraphChange > _changes_
a sequence containing all the possible changes
~GraphChangesSelector4DiGraph()
destructor
GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT, GRAPH_CHANGES_GENERATOR, ALLOC > & operator=(GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT, GRAPH_CHANGES_GENERATOR, ALLOC > &&from)
move operator
GRAPH_CHANGES_GENERATOR * _changes_generator_
the generator that returns the set of possible changes
void _updateScores_(const Set< std::size_t > &changes_to_recompute)
perform the necessary updates of the scores
void applyChangeWithoutScoreUpdate(const GraphChange &change)
indicate to the selector that one of serveral changes has been applied
Score< ALLOC > * _score_
the scoring function
NodeProperty< std::vector< NodeId, ALLOC< NodeId > > > _parents_
the set of parents of each node (speeds-up score computations)
const GraphChange & bestChange(const NodeId i)
returns the best graph change to examine related to the ith node
bool _isChangeValid_(const std::size_t index) const
indicates whether a given change is valid or not
double bestScore()
return the score of the best graph change
bool empty(const NodeId i)
indicates whether the selector contains graph changes related to the ith node
Set< std::size_t > _illegal_changes_
the set of changes known to be currently illegal (due to the constraints)
GraphChangesSelector4DiGraph(GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT, GRAPH_CHANGES_GENERATOR, ALLOC > &&from)
move constructor
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
std::vector< std::pair< NodeId, double > > nodesSortedByBestScore() const
returns the set of queues sorted by decreasing top priority
STRUCTURAL_CONSTRAINT * _constraint_
the set of constraints used to determine valid changes
void setGraph(DiGraph &graph)
sets the graph from which scores are computed
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
GraphChangesSelector4DiGraph(const GraphChangesSelector4DiGraph< STRUCTURAL_CONSTRAINT, GRAPH_CHANGES_GENERATOR, ALLOC > &from)
copy constructor
double bestScore(const NodeId i)
return the score of the best graph change related to the ith node
bool isChangeValid(const GraphChange &change) const
indicates whether a given change is valid or not