aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
aprioriNoApriori.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 no a priori class: corresponds to 0 weight-sample
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #ifndef GUM_LEARNING_A_PRIORI_NO_APRIORI_H
28 #define GUM_LEARNING_A_PRIORI_NO_APRIORI_H
29 
30 #include <vector>
31 
32 #include <agrum/agrum.h>
33 #include <agrum/BN/learning/aprioris/apriori.h>
34 
35 namespace gum {
36 
37  namespace learning {
38 
39  /** @class AprioriNoApriori
40  * @brief the no a priori class: corresponds to 0 weight-sample
41  * @headerfile aprioriNoApriori.h <agrum/tools/database/aprioriNoApriori.h>
42  * @ingroup learning_apriori
43  */
44  template < template < typename > class ALLOC = std::allocator >
45  class AprioriNoApriori: public Apriori< ALLOC > {
46  public:
47  /// the type of the a priori
49 
50  /// type for the allocators passed in arguments of methods
52 
53 
54  // ##########################################################################
55  /// @name Constructors / Destructors
56  // ##########################################################################
57  /// @{
58 
59  /// default constructor
60  /** @param database the database from which learning is performed. This is
61  * useful to get access to the random variables
62  * @param nodeId2Columns a mapping from the ids of the nodes in the
63  * graphical model to the corresponding column in the DatabaseTable.
64  * This enables estimating from a database in which variable A corresponds
65  * to the 2nd column the parameters of a BN in which variable A has a
66  * NodeId of 5. An empty nodeId2Columns bijection means that the mapping
67  * is an identity, i.e., the value of a NodeId is equal to the index of
68  * the column in the DatabaseTable.
69  * @param alloc the allocator used to allocate the structures within the
70  * RecordCounter.*/
72  const DatabaseTable< ALLOC >& database,
73  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
75  = Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
77 
78  /// copy constructor
79  AprioriNoApriori(const AprioriNoApriori< ALLOC >& from);
80 
81  /// copy constructor with a given allocator
82  AprioriNoApriori(const AprioriNoApriori< ALLOC >& from,
83  const allocator_type& alloc);
84 
85  /// move constructor
86  AprioriNoApriori(AprioriNoApriori< ALLOC >&& from);
87 
88  /// move constructor with a given allocator
89  AprioriNoApriori(AprioriNoApriori< ALLOC >&& from,
90  const allocator_type& alloc);
91 
92  /// virtual copy constructor
93  virtual AprioriNoApriori< ALLOC >* clone() const;
94 
95  /// virtual copy constructor with a given allocator
96  virtual AprioriNoApriori< ALLOC >* clone(const allocator_type& alloc) const;
97 
98  /// destructor
99  virtual ~AprioriNoApriori();
100 
101  /// @}
102 
103 
104  // ##########################################################################
105  /// @name Operators
106  // ##########################################################################
107  /// @{
108 
109  /// copy operator
111 
112  /// move operator
114 
115  /// @}
116 
117 
118  // ##########################################################################
119  /// @name Accessors / Modifiers
120  // ##########################################################################
121  /// @{
122 
123  /// sets the weight of the a priori (kind of effective sample size)
124  virtual void setWeight(const double weight) final;
125 
126  /// indicates whether an apriori is of a certain type
127  virtual bool isOfType(const std::string& type) final;
128 
129  /// returns the type of the apriori
130  virtual const std::string& getType() const final;
131 
132  /// indicates whether the apriori is potentially informative
133  /** Basically, only the NoApriori is uninformative. However, it may happen
134  * that, under some circonstances, an apriori, which is usually not equal
135  * to the NoApriori, becomes equal to it (e.g., when the weight is equal
136  * to zero). In this case, if the apriori can detect this case, it shall
137  * inform the classes that use it that it is temporarily uninformative.
138  * These classes will then be able to speed-up their code by avoiding to
139  * take into account the apriori in their computations. */
140  virtual bool isInformative() const final;
141 
142  /// adds the apriori to a counting vector corresponding to the idset
143  /** adds the apriori to an already created counting vector defined over
144  * the union of the variables on both the left and right hand side of the
145  * conditioning bar of the idset.
146  * @warning the method assumes that the size of the vector is exactly
147  * the domain size of the joint variables set. */
148  virtual void
149  addAllApriori(const IdCondSet< ALLOC >& idset,
150  std::vector< double, ALLOC< double > >& counts) final;
151 
152  /** @brief adds the apriori to a counting vectordefined over the right
153  * hand side of the idset
154  *
155  * @warning the method assumes that the size of the vector is exactly
156  * the domain size of the joint RHS variables of the idset. */
157  virtual void addConditioningApriori(
158  const IdCondSet< ALLOC >& idset,
159  std::vector< double, ALLOC< double > >& counts) final;
160 
161  /// @}
162  };
163 
164  } /* namespace learning */
165 
166 } /* namespace gum */
167 
168 /// include the template implementation
169 #include <agrum/BN/learning/aprioris/aprioriNoApriori_tpl.h>
170 
171 #endif /* GUM_LEARNING_A_PRIORI_NO_APRIORI_H */
AprioriNoApriori< ALLOC > & operator=(const AprioriNoApriori< ALLOC > &from)
copy operator
virtual AprioriNoApriori< ALLOC > * clone(const allocator_type &alloc) const
virtual copy constructor with a given allocator
virtual bool isOfType(const std::string &type) final
indicates whether an apriori is of a certain type
AprioriNoApriori(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 const std::string & getType() const final
returns the type of the apriori
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
virtual void addAllApriori(const IdCondSet< ALLOC > &idset, std::vector< double, ALLOC< double > > &counts) final
adds the apriori to a counting vector corresponding to the idset
AprioriNoApriori(AprioriNoApriori< ALLOC > &&from)
move constructor
virtual bool isInformative() const final
indicates whether the apriori is potentially informative
virtual void setWeight(const double weight) final
sets the weight of the a priori (kind of effective sample size)
AprioriNoApriori(const AprioriNoApriori< ALLOC > &from, const allocator_type &alloc)
copy constructor with a given allocator
AprioriNoApriori(const AprioriNoApriori< ALLOC > &from)
copy constructor
AprioriNoApriori< ALLOC > & operator=(AprioriNoApriori< ALLOC > &&from)
move operator
virtual void addConditioningApriori(const IdCondSet< ALLOC > &idset, std::vector< double, ALLOC< double > > &counts) final
adds the apriori to a counting vectordefined over the right hand side of the idset ...
virtual ~AprioriNoApriori()
destructor
virtual AprioriNoApriori< ALLOC > * clone() const
virtual copy constructor
AprioriNoApriori(AprioriNoApriori< ALLOC > &&from, const allocator_type &alloc)
move constructor with a given allocator
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
the no a priori class: corresponds to 0 weight-sample