aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
DAG2BNLearner.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 A class that, given a structure and a parameter estimator returns a
24  * full Bayes net
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 #ifndef GUM_LEARNING_DAG_2_BN_LEARNER_H
29 #define GUM_LEARNING_DAG_2_BN_LEARNER_H
30 
31 #include <vector>
32 
33 #include <agrum/agrum.h>
34 #include <agrum/tools/core/approximations/approximationScheme.h>
35 #include <agrum/tools/core/approximations/approximationSchemeListener.h>
36 #include <agrum/BN/BayesNet.h>
37 #include <agrum/tools/graphs/DAG.h>
38 #include <agrum/BN/learning/paramUtils/paramEstimator.h>
39 
40 namespace gum {
41 
42  namespace learning {
43 
44  /** @class DAG2BNLearner
45  * @brief A class that, given a structure and a parameter estimator returns
46  * a full Bayes net
47  * @headerfile DAG2BNLearner.h <agrum/BN/learning/paramUtils/DAG2BNLearner.h>
48  * @ingroup learning_param_utils
49  */
50  template < template < typename > class ALLOC = std::allocator >
51  class DAG2BNLearner: public ApproximationScheme, private ALLOC< NodeId > {
52  public:
53  /// type for the allocators passed in arguments of methods
55 
56  // ##########################################################################
57  /// @name Constructors / Destructors
58  // ##########################################################################
59  /// @{
60 
61  /// default constructor
62  DAG2BNLearner(const allocator_type& alloc = allocator_type());
63 
64  /// copy constructor
65  DAG2BNLearner(const DAG2BNLearner< ALLOC >& from);
66 
67  /// copy constructor with a given allocator
68  DAG2BNLearner(const DAG2BNLearner< ALLOC >& from, const allocator_type& alloc);
69 
70  /// move constructor
71  DAG2BNLearner(DAG2BNLearner< ALLOC >&& from);
72 
73  /// move constructor with a given allocator
74  DAG2BNLearner(DAG2BNLearner< ALLOC >&& from, const allocator_type& alloc);
75 
76  /// virtual copy constructor
77  virtual DAG2BNLearner< ALLOC >* clone() const;
78 
79  /// virtual copy constructor with a given allocator
80  virtual DAG2BNLearner< ALLOC >* clone(const allocator_type& alloc) const;
81 
82  /// destructor
83  virtual ~DAG2BNLearner();
84 
85  /// @}
86 
87 
88  // ##########################################################################
89  /// @name Operators
90  // ##########################################################################
91 
92  /// @{
93 
94  /// copy operator
96 
97  /// move operator
99 
100  /// @}
101 
102 
103  // ##########################################################################
104  /// @name Accessors / Modifiers
105  // ##########################################################################
106  /// @{
107 
108  /// create a BN from a DAG using a one pass generator (typically ML)
109  template < typename GUM_SCALAR = double >
111 
112  /// create a BN from a DAG using a two pass generator (typically EM)
113  /** The bootstrap estimator is used once to provide an inital BN. This
114  * one is used by the second estimator. The later is exploited in a loop
115  * until the stopping condition is met (max of relative error on every
116  * parameter<epsilon) */
117  template < typename GUM_SCALAR = double >
120  const DAG& dag);
121 
122  /// returns the approximation policy of the learning algorithm
124 
125  /// returns the allocator used by the score
127 
128  /// @}
129 
130 #ifndef DOXYGEN_SHOULD_SKIP_THIS
131 
132  private:
133  /// copy a potential into another whose variables' sequence differs
134  /** The variables of both potential should be the same, only their
135  * order differs */
136  template < typename GUM_SCALAR = double >
137  static void _probaVarReordering_(gum::Potential< GUM_SCALAR >& pot,
138  const gum::Potential< GUM_SCALAR >& other_pot);
139 
140 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
141  };
142 
143  } /* namespace learning */
144 
145 } /* namespace gum */
146 
147 /// always include templated methods
148 #include <agrum/BN/learning/paramUtils/DAG2BNLearner_tpl.h>
149 
150 #endif /* GUM_LEARNING_DAG_2_BN_LEARNER_H */
DAG2BNLearner< ALLOC > & operator=(DAG2BNLearner< ALLOC > &&from)
move operator
static BayesNet< GUM_SCALAR > createBN(ParamEstimator< ALLOC > &estimator, const DAG &dag)
create a BN from a DAG using a one pass generator (typically ML)
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
DAG2BNLearner(DAG2BNLearner< ALLOC > &&from)
move constructor
BayesNet< GUM_SCALAR > createBN(ParamEstimator< ALLOC > &bootstrap_estimator, ParamEstimator< ALLOC > &general_estimator, const DAG &dag)
create a BN from a DAG using a two pass generator (typically EM)
virtual ~DAG2BNLearner()
destructor
allocator_type getAllocator() const
returns the allocator used by the score
DAG2BNLearner(const DAG2BNLearner< ALLOC > &from, const allocator_type &alloc)
copy constructor with a given allocator
DAG2BNLearner(const DAG2BNLearner< ALLOC > &from)
copy constructor
DAG2BNLearner< ALLOC > & operator=(const DAG2BNLearner< ALLOC > &from)
copy operator
ApproximationScheme & approximationScheme()
returns the approximation policy of the learning algorithm
DAG2BNLearner(DAG2BNLearner< ALLOC > &&from, const allocator_type &alloc)
move constructor with a given allocator
virtual DAG2BNLearner< ALLOC > * clone(const allocator_type &alloc) const
virtual copy constructor with a given allocator
virtual DAG2BNLearner< ALLOC > * clone() const
virtual copy constructor
A class that, given a structure and a parameter estimator returns a full Bayes net.
Definition: DAG2BNLearner.h:51
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)