aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
aprioriK2.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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 internal apriori for the K2 score = Laplace Apriori
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #ifndef GUM_LEARNING_A_PRIORI_K2_H
28 #define GUM_LEARNING_A_PRIORI_K2_H
29 
30 #include <vector>
31 
32 #include <agrum/agrum.h>
33 #include <agrum/BN/learning/aprioris/aprioriSmoothing.h>
34 
35 namespace gum {
36 
37  namespace learning {
38 
39  /** @class AprioriK2
40  * @brief the internal apriori for the K2 score = Laplace Apriori
41  * @headerfile aprioriK2.h <agrum/tools/database/aprioriK2.h>
42  * @ingroup learning_apriori
43  *
44  * K2 is a BD score with a Laplace apriori (i.e., a smoothing of 1).
45  *
46  * It is important to note that, to be meaningful a structure + parameter
47  * learning requires that the same aprioris are taken into account during
48  * structure learning and parameter learning.
49  */
50  template < template < typename > class ALLOC = std::allocator >
51  class AprioriK2: public AprioriSmoothing< ALLOC > {
52  public:
53  /// the type of the a priori
55 
56  /// type for the allocators passed in arguments of methods
58 
59 
60  // ##########################################################################
61  /// @name Constructors / Destructors
62  // ##########################################################################
63  /// @{
64 
65  /// default constructor
66  /** @param database the database from which learning is performed. This is
67  * useful to get access to the random variables
68  * @param nodeId2Columns a mapping from the ids of the nodes in the
69  * graphical model to the corresponding column in the DatabaseTable.
70  * This enables estimating from a database in which variable A corresponds
71  * to the 2nd column the parameters of a BN in which variable A has a
72  * NodeId of 5. An empty nodeId2Columns bijection means that the mapping
73  * is an identity, i.e., the value of a NodeId is equal to the index of
74  * the column in the DatabaseTable.
75  * @param alloc the allocator used to allocate the structures within the
76  * RecordCounter.*/
77  AprioriK2(const DatabaseTable< ALLOC >& database,
78  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
80  = Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
82 
83  /// copy constructor
84  AprioriK2(const AprioriK2< ALLOC >& from);
85 
86  /// copy constructor with a given allocator
87  AprioriK2(const AprioriK2< ALLOC >& from, const allocator_type& alloc);
88 
89  /// move constructor
90  AprioriK2(AprioriK2< ALLOC >&& from);
91 
92  /// move constructor with a given allocator
93  AprioriK2(AprioriK2< ALLOC >&& from, const allocator_type& alloc);
94 
95  /// virtual copy constructor
96  virtual AprioriK2< ALLOC >* clone() const;
97 
98  /// virtual copy constructor with a given allocator
99  virtual AprioriK2< ALLOC >* clone(const allocator_type& alloc) const;
100 
101  /// destructor
102  virtual ~AprioriK2();
103 
104  /// @}
105 
106 
107  // ##########################################################################
108  /// @name Operators
109  // ##########################################################################
110  /// @{
111 
112  /// copy operator
113  AprioriK2< ALLOC >& operator=(const AprioriK2< ALLOC >& from);
114 
115  /// move operator
117 
118  /// @}
119 
120 
121  // ##########################################################################
122  /// @name Accessors / Modifiers
123  // ##########################################################################
124  /// @{
125 
126  /// dummy set weight function: in K2, weights are always equal to 1
127  virtual void setWeight(const double weight) final;
128 
129  /// @}
130  };
131 
132  } /* namespace learning */
133 
134 } /* namespace gum */
135 
136 /// include the template implementation
137 #include <agrum/BN/learning/aprioris/aprioriK2_tpl.h>
138 
139 #endif /* GUM_LEARNING_A_PRIORI_K2_H */
AprioriK2(const AprioriK2< ALLOC > &from)
copy constructor
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
AprioriK2(AprioriK2< ALLOC > &&from)
move constructor
virtual void setWeight(const double weight) final
dummy set weight function: in K2, weights are always equal to 1
AprioriK2(const DatabaseTable< ALLOC > &database, const Bijection< NodeId, std::size_t, ALLOC< std::size_t > > &nodeId2columns=Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(), const allocator_type &alloc=allocator_type())
default constructor
virtual AprioriK2< ALLOC > * clone() const
virtual copy constructor
virtual ~AprioriK2()
destructor
AprioriK2< ALLOC > & operator=(const AprioriK2< ALLOC > &from)
copy operator
AprioriK2(const AprioriK2< ALLOC > &from, const allocator_type &alloc)
copy constructor with a given allocator
AprioriK2(AprioriK2< ALLOC > &&from, const allocator_type &alloc)
move constructor with a given allocator
the internal apriori for the K2 score = Laplace AprioriK2 is a BD score with a Laplace apriori (i...
Definition: aprioriK2.h:51
virtual AprioriK2< ALLOC > * clone(const allocator_type &alloc) const
virtual copy constructor with a given allocator
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
AprioriK2< ALLOC > & operator=(AprioriK2< ALLOC > &&from)
move operator