37 template <
typename GRAPH_CHANGES_
SELECTOR >
40 selector.setGraph(dag);
42 unsigned int nb_changes_applied = 1;
49 std::vector< bool > impacted_queues(dag.
size(),
false);
52 nb_changes_applied = 0;
55 std::vector< std::pair< NodeId, double > > ordered_queues =
56 selector.nodesSortedByBestScore();
58 for (
Idx j = 0; j < dag.
size(); ++j) {
59 Idx i = ordered_queues[j].first;
61 if (!(selector.empty(i)) && (selector.bestScore(i) > 0)) {
66 switch (change.
type()) {
68 if (!impacted_queues[change.
node2()]
69 && selector.isChangeValid(change)) {
70 delta_score += selector.bestScore(i);
72 impacted_queues[change.
node2()] =
true;
73 selector.applyChangeWithoutScoreUpdate(change);
80 if (!impacted_queues[change.
node2()]
81 && selector.isChangeValid(change)) {
82 delta_score += selector.bestScore(i);
84 impacted_queues[change.
node2()] =
true;
85 selector.applyChangeWithoutScoreUpdate(change);
92 if ((!impacted_queues[change.
node1()])
93 && (!impacted_queues[change.
node2()])
94 && selector.isChangeValid(change)) {
95 delta_score += selector.bestScore(i);
98 impacted_queues[change.
node1()] =
true;
99 impacted_queues[change.
node2()] =
true;
100 selector.applyChangeWithoutScoreUpdate(change);
101 ++nb_changes_applied;
108 "edge modifications are not supported by local search");
113 selector.updateScoresAfterAppliedChanges();
116 for (
auto iter = impacted_queues.begin(); iter != impacted_queues.end();
133 template <
typename GUM_SCALAR,
134 typename GRAPH_CHANGES_SELECTOR,
135 typename PARAM_ESTIMATOR >
138 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
BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR &selector, PARAM_ESTIMATOR &estimator, DAG initial_dag=DAG())
learns the structure and the parameters of a BN
void initApproximationScheme()
Initialise the scheme.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
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
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.
#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