34 template <
typename GRAPH_CHANGES_
SELECTOR >
37 selector.setGraph(dag);
39 unsigned int nb_changes_applied = 1;
46 std::vector< bool > impacted_queues(dag.
size(),
false);
49 nb_changes_applied = 0;
52 std::vector< std::pair< NodeId, double > > ordered_queues =
53 selector.nodesSortedByBestScore();
55 for (
Idx j = 0; j < dag.
size(); ++j) {
56 Idx i = ordered_queues[j].first;
58 if (!(selector.empty(i)) && (selector.bestScore(i) > 0)) {
63 switch (change.
type()) {
65 if (!impacted_queues[change.
node2()]
66 && selector.isChangeValid(change)) {
67 delta_score += selector.bestScore(i);
69 impacted_queues[change.
node2()] =
true;
70 selector.applyChangeWithoutScoreUpdate(change);
77 if (!impacted_queues[change.
node2()]
78 && selector.isChangeValid(change)) {
79 delta_score += selector.bestScore(i);
81 impacted_queues[change.
node2()] =
true;
82 selector.applyChangeWithoutScoreUpdate(change);
89 if ((!impacted_queues[change.
node1()])
90 && (!impacted_queues[change.
node2()])
91 && selector.isChangeValid(change)) {
92 delta_score += selector.bestScore(i);
95 impacted_queues[change.
node1()] =
true;
96 impacted_queues[change.
node2()] =
true;
97 selector.applyChangeWithoutScoreUpdate(change);
105 "edge modifications are not supported by local search");
110 selector.updateScoresAfterAppliedChanges();
113 for (
auto iter = impacted_queues.begin(); iter != impacted_queues.end();
130 template <
typename GUM_SCALAR,
131 typename GRAPH_CHANGES_SELECTOR,
132 typename PARAM_ESTIMATOR >
135 PARAM_ESTIMATOR& estimator,
A class that, given a structure and a parameter estimator returns a full Bayes net.
Class representing a Bayesian Network.
the classes to account for structure changes in a graph
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.
gum is the global namespace for all aGrUM entities
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