aGrUM  0.14.2
K2_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}@lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it wil be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #include <type_traits>
27 
31 
32 namespace gum {
33 
34  namespace learning {
35 
37  template < typename GRAPH_CHANGES_SELECTOR >
38  DAG K2::learnStructure(GRAPH_CHANGES_SELECTOR& selector, DAG initial_dag) {
39  // check that we used a selector compatible with the K2 algorithm
40  static_assert(
41  std::is_base_of< __GraphChangesGenerator4K2,
42  typename GRAPH_CHANGES_SELECTOR::GeneratorType >::value,
43  "K2 must be called with a K2-compliant Graph Change Generator");
44 
45  // check that the order passed in argument concerns all the nodes
46  //__checkOrder(modal);
47 
48  // get the generator and assign the order
49  auto& generator = selector.graphChangeGenerator();
50  generator.setOrder(__order);
51 
52  // use the greedy hill climbing algorithm to perform the search
53  return GreedyHillClimbing::learnStructure(selector, initial_dag);
54  }
55 
57  template < typename GUM_SCALAR,
58  typename GRAPH_CHANGES_SELECTOR,
59  typename PARAM_ESTIMATOR >
60  BayesNet< GUM_SCALAR > K2::learnBN(GRAPH_CHANGES_SELECTOR& selector,
61  PARAM_ESTIMATOR& estimator,
62  DAG initial_dag) {
63  // check that we used a selector compatible with the K2 algorithm
64  static_assert(
65  std::is_base_of< __GraphChangesGenerator4K2,
66  typename GRAPH_CHANGES_SELECTOR::GeneratorType >::value,
67  "K2 must be called with a K2-compliant Graph Change Generator");
68 
69  // check that the order passed in argument concerns all the nodes
70  //__checkOrder(modal);
71 
72  // get the generator and assign the order
73  auto& generator = selector.graphChangeGenerator();
74  generator.setOrder(__order);
75 
76  // use the greedy hill climbing algorithm to perform the search
77  return GreedyHillClimbing::learnBN< GUM_SCALAR >(
78  selector, estimator, initial_dag);
79  }
80 
81  } /* namespace learning */
82 
83 } /* namespace gum */
A class that, given a structure and a parameter estimator returns a full Bayes net.
Class representing a Bayesian Network.
Definition: BayesNet.h:76
the classes to account for structure changes in a graph
The basic class for computing the set of digraph changes allowed by the user to be executed by the le...
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
Definition: K2_tpl.h:38
Base class for dag.
Definition: DAG.h:99
Sequence< NodeId > __order
the order on the variable used for learning
Definition: K2.h:116
BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR &selector, PARAM_ESTIMATOR &estimator, DAG initial_dag=DAG())
learns the structure and the parameters of a BN
Definition: K2_tpl.h:60