57 template <
typename GRAPH_CHANGES_
SELECTOR >
59 selector.setGraph(dag);
61 unsigned int nb_changes_applied = 1;
68 std::vector< bool > impacted_queues(dag.
size(),
false);
71 nb_changes_applied = 0;
74 std::vector< std::pair< NodeId, double > > ordered_queues
75 = selector.nodesSortedByBestScore();
77 for (
Idx j = 0; j < dag.
size(); ++j) {
78 Idx i = ordered_queues[j].first;
80 if (!(selector.empty(i)) && (selector.bestScore(i) > 0)) {
85 switch (change.
type()) {
87 if (!impacted_queues[change.
node2()] && selector.isChangeValid(change)) {
88 delta_score += selector.bestScore(i);
90 impacted_queues[change.
node2()] =
true;
91 selector.applyChangeWithoutScoreUpdate(change);
98 if (!impacted_queues[change.
node2()] && selector.isChangeValid(change)) {
99 delta_score += selector.bestScore(i);
101 impacted_queues[change.
node2()] =
true;
102 selector.applyChangeWithoutScoreUpdate(change);
103 ++nb_changes_applied;
109 if ((!impacted_queues[change.
node1()]) && (!impacted_queues[change.
node2()])
110 && selector.isChangeValid(change)) {
111 delta_score += selector.bestScore(i);
114 impacted_queues[change.
node1()] =
true;
115 impacted_queues[change.
node2()] =
true;
116 selector.applyChangeWithoutScoreUpdate(change);
117 ++nb_changes_applied;
124 "edge modifications are not supported by local search")
129 selector.updateScoresAfterAppliedChanges();
132 for (
auto iter = impacted_queues.begin(); iter != impacted_queues.end(); ++iter) {
148 template <
typename GUM_SCALAR,
typename GRAPH_CHANGES_
SELECTOR,
typename PARAM_ESTIMATOR >
150 PARAM_ESTIMATOR& estimator,
A class that, given a structure and a parameter estimator returns a full Bayes net.
void updateApproximationScheme(unsigned int incr=1)
Update the scheme w.r.t the new error and increment steps.
void initApproximationScheme()
Initialise the scheme.
void stopApproximationScheme()
Stop the approximation scheme.
bool continueApproximationScheme(double error)
Update the scheme w.r.t the new error.
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
The base class for all directed edges.
void addArc(NodeId tail, NodeId head) final
insert a new arc into the directed graph
Size size() const
alias for sizeNodes
Exception : operation not allowed.
static BayesNet< GUM_SCALAR > createBN(ParamEstimator &estimator, const DAG &dag)
create a BN from a DAG using a one pass generator (typically ML)
NodeId node1() const noexcept
returns the first node involved in the modification
GraphChangeType type() const noexcept
returns the type of the operation
NodeId node2() const noexcept
returns the second node involved in the modification
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR &selector, PARAM_ESTIMATOR &estimator, DAG initial_dag=DAG())
learns the structure and the parameters of a BN
#define GUM_ERROR(type, msg)
the classes to account for structure changes in a graph
Size Idx
Type for indexes.
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities