aGrUM  0.14.2
K2.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  ***************************************************************************/
25 #ifndef GUM_LEARNING_K2_H
26 #define GUM_LEARNING_K2_H
27 
28 #include <string>
29 #include <vector>
30 
31 #include <agrum/BN/BayesNet.h>
32 #include <agrum/core/sequence.h>
33 #include <agrum/graphs/DAG.h>
35 
36 namespace gum {
37 
38  namespace learning {
39 
44  class K2 : private GreedyHillClimbing {
45  public:
46  // ##########################################################################
48  // ##########################################################################
50 
52  K2();
53 
55  K2(const K2& from);
56 
58  K2(K2&& from);
59 
61  ~K2();
62 
64 
65  // ##########################################################################
67  // ##########################################################################
69 
71  K2& operator=(const K2& from);
72 
74  K2& operator=(K2&& from);
75 
77 
78  // ##########################################################################
80  // ##########################################################################
82 
85 
87  void setOrder(const Sequence< NodeId >& order);
88 
90  void setOrder(const std::vector< NodeId >& order);
91 
93  const Sequence< NodeId >& order() const noexcept;
94 
96 
102  template < typename GRAPH_CHANGES_SELECTOR >
103  DAG learnStructure(GRAPH_CHANGES_SELECTOR& selector,
104  DAG initial_dag = DAG());
105 
107  template < typename GUM_SCALAR,
108  typename GRAPH_CHANGES_SELECTOR,
109  typename PARAM_ESTIMATOR >
110  BayesNet< GUM_SCALAR > learnBN(GRAPH_CHANGES_SELECTOR& selector,
111  PARAM_ESTIMATOR& estimator,
112  DAG initial_dag = DAG());
113 
114  private:
117 
121  void __checkOrder(const std::vector< Size >& modal);
123  };
124 
125  } /* namespace learning */
126 
127 } /* namespace gum */
128 
130 #ifndef GUM_NO_INLINE
131 # include <agrum/learning/K2_inl.h>
132 #endif /* GUM_NO_INLINE */
133 
135 #include <agrum/learning/K2_tpl.h>
136 
137 #endif /* GUM_LEARNING_K2_H */
Class representing a Bayesian Network.
Definition: BayesNet.h:76
ApproximationScheme & approximationScheme()
returns the approximation policy of the learning algorithm
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
Approximation Scheme.
void setOrder(const Sequence< NodeId > &order)
sets the order on the variables
Class representing Bayesian networks.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
const Sequence< NodeId > & order() const noexcept
returns the current order
The greedy hill climbing learning algorithm (for directed graphs)
K2 & operator=(const K2 &from)
copy operator
K2()
default constructor
DAG learnStructure(GRAPH_CHANGES_SELECTOR &selector, DAG initial_dag=DAG())
learns the structure of a Bayes net
Definition: K2_tpl.h:38
The K2 algorithm.
Definition: K2.h:44
The K2 algorithm.
void __checkOrder(const std::vector< Size > &modal)
checks that the order passed to K2 is coherent with the variables as specified by their modalities ...
The greedy hill learning algorithm (for directed graphs)
The K2 algorithm.
Base class for dag.
Definition: DAG.h:99
Base classes for directed acyclic graphs.
~K2()
destructor
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