aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
aprioriK2.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 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,
79  = Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
81 
82  /// copy constructor
83  AprioriK2(const AprioriK2< ALLOC >& from);
84 
85  /// copy constructor with a given allocator
86  AprioriK2(const AprioriK2< ALLOC >& from, const allocator_type& alloc);
87 
88  /// move constructor
89  AprioriK2(AprioriK2< ALLOC >&& from);
90 
91  /// move constructor with a given allocator
92  AprioriK2(AprioriK2< ALLOC >&& from, const allocator_type& alloc);
93 
94  /// virtual copy constructor
95  virtual AprioriK2< ALLOC >* clone() const;
96 
97  /// virtual copy constructor with a given allocator
98  virtual AprioriK2< ALLOC >* clone(const allocator_type& alloc) const;
99 
100  /// destructor
101  virtual ~AprioriK2();
102 
103  /// @}
104 
105 
106  // ##########################################################################
107  /// @name Operators
108  // ##########################################################################
109  /// @{
110 
111  /// copy operator
112  AprioriK2< ALLOC >& operator=(const AprioriK2< ALLOC >& from);
113 
114  /// move operator
116 
117  /// @}
118 
119 
120  // ##########################################################################
121  /// @name Accessors / Modifiers
122  // ##########################################################################
123  /// @{
124 
125  /// dummy set weight function: in K2, weights are always equal to 1
126  virtual void setWeight(const double weight) final;
127 
128  /// @}
129  };
130 
131  } /* namespace learning */
132 
133 } /* namespace gum */
134 
135 /// include the template implementation
136 #include <agrum/BN/learning/aprioris/aprioriK2_tpl.h>
137 
138 #endif /* GUM_LEARNING_A_PRIORI_K2_H */
AprioriK2(const AprioriK2< ALLOC > &from)
copy constructor
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
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