aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
greedyHillClimbing_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief The greedy hill learning algorithm (for directed graphs)
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 
28 #include <agrum/BN/learning/paramUtils/DAG2BNLearner.h>
29 #include <agrum/BN/learning/structureUtils/graphChange.h>
30 
31 namespace gum {
32 
33  namespace learning {
34 
35  /// learns the structure of a Bayes net
36  template < typename GRAPH_CHANGES_SELECTOR >
39 
40  unsigned int nb_changes_applied = 1;
41  double delta_score;
42 
44 
45  // a vector that indicates which queues have valid scores, i.e., scores
46  // that were not invalidated by previously applied changes
47  std::vector< bool > impacted_queues(dag.size(), false);
48 
49  do {
51  delta_score = 0;
52 
53  std::vector< std::pair< NodeId, double > > ordered_queues
55 
56  for (Idx j = 0; j < dag.size(); ++j) {
58 
59  if (!(selector.empty(i)) && (selector.bestScore(i) > 0)) {
60  // pick up the best change
62 
63  // perform the change
64  switch (change.type()) {
69  impacted_queues[change.node2()] = true;
72  }
73 
74  break;
75 
80  impacted_queues[change.node2()] = true;
83  }
84 
85  break;
86 
93  impacted_queues[change.node1()] = true;
94  impacted_queues[change.node2()] = true;
97  }
98 
99  break;
100 
101  default:
103  "edge modifications are not supported by local search")
104  }
105  }
106  }
107 
109 
110  // reset the impacted queue and applied changes structures
111  for (auto iter = impacted_queues.begin(); iter != impacted_queues.end(); ++iter) {
112  *iter = false;
113  }
114 
116 
118 
119  stopApproximationScheme(); // just to be sure of the approximationScheme
120  // has
121  // been notified of the end of looop
122 
123  return dag;
124  }
125 
126  /// learns the structure and the parameters of a BN
127  template < typename GUM_SCALAR, typename GRAPH_CHANGES_SELECTOR, typename PARAM_ESTIMATOR >
130  DAG initial_dag) {
133  }
134 
135  } /* namespace learning */
136 
137 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)