38 template <
typename GRAPH_CHANGES_
SELECTOR >
41 selector.setGraph(dag);
43 unsigned int nb_changes_applied = 0;
44 Idx applied_change_with_positive_score = 0;
51 std::vector< bool > impacted_queues(dag.
size(),
false);
55 double best_score = 0;
56 double current_score = 0;
57 double delta_score = 0;
60 applied_change_with_positive_score = 0;
63 std::vector< std::pair< NodeId, double > > ordered_queues =
64 selector.nodesSortedByBestScore();
66 for (
Idx j = 0; j < dag.
size(); ++j) {
67 NodeId i = ordered_queues[j].first;
69 if (!selector.empty(i)
70 && (!nb_changes_applied || (selector.bestScore(i) > 0))) {
75 switch (change.
type()) {
77 if (!impacted_queues[change.
node2()]
78 && selector.isChangeValid(change)) {
79 if (selector.bestScore(i) > 0) {
80 ++applied_change_with_positive_score;
81 }
else if (current_score > best_score) {
82 best_score = current_score;
91 delta_score += selector.bestScore(i);
92 current_score += selector.bestScore(i);
94 impacted_queues[change.
node2()] =
true;
95 selector.applyChangeWithoutScoreUpdate(change);
102 if (!impacted_queues[change.
node2()]
103 && selector.isChangeValid(change)) {
104 if (selector.bestScore(i) > 0) {
105 ++applied_change_with_positive_score;
106 }
else if (current_score > best_score) {
107 best_score = current_score;
116 delta_score += selector.bestScore(i);
117 current_score += selector.bestScore(i);
119 impacted_queues[change.
node2()] =
true;
120 selector.applyChangeWithoutScoreUpdate(change);
121 ++nb_changes_applied;
127 if ((!impacted_queues[change.
node1()])
128 && (!impacted_queues[change.
node2()])
129 && selector.isChangeValid(change)) {
130 if (selector.bestScore(i) > 0) {
131 ++applied_change_with_positive_score;
132 }
else if (current_score > best_score) {
133 best_score = current_score;
142 delta_score += selector.bestScore(i);
143 current_score += selector.bestScore(i);
146 impacted_queues[change.
node1()] =
true;
147 impacted_queues[change.
node2()] =
true;
148 selector.applyChangeWithoutScoreUpdate(change);
149 ++nb_changes_applied;
156 "edge modifications are not " 157 "supported by local search");
164 selector.updateScoresAfterAppliedChanges();
167 for (
auto iter = impacted_queues.begin(); iter != impacted_queues.end();
175 if (applied_change_with_positive_score) {
177 nb_changes_applied = 0;
190 if (current_score > best_score) {
198 template <
typename GUM_SCALAR,
199 typename GRAPH_CHANGES_SELECTOR,
200 typename PARAM_ESTIMATOR >
203 PARAM_ESTIMATOR& estimator,
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Class representing a Bayesian Network.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
Size size() const
alias for sizeNodes
void initApproximationScheme()
Initialise the scheme.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
GraphChangeType type() const noexcept
returns the type of the operation
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
void stopApproximationScheme()
Stop the approximation scheme.
virtual void addArc(const NodeId tail, const NodeId head)
insert a new arc into the directed graph
BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR &selector, PARAM_ESTIMATOR &estimator, DAG initial_dag=DAG())
learns the structure and the parameters of a BN
Size __MaxNbDecreasing
the max number of changes decreasing the score that we allow to apply
NodeId node2() const noexcept
returns the second node involved in the modification
Size Idx
Type for indexes.
A class that, given a structure and a parameter estimator returns a full Bayes net.
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
NodeId node1() const noexcept
returns the first node involved in the modification