aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
aprioriNoApriori.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 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.*/
71  AprioriNoApriori(const DatabaseTable< ALLOC >& database,
73  = Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
75 
76  /// copy constructor
77  AprioriNoApriori(const AprioriNoApriori< ALLOC >& from);
78 
79  /// copy constructor with a given allocator
80  AprioriNoApriori(const AprioriNoApriori< ALLOC >& from, const allocator_type& alloc);
81 
82  /// move constructor
83  AprioriNoApriori(AprioriNoApriori< ALLOC >&& from);
84 
85  /// move constructor with a given allocator
86  AprioriNoApriori(AprioriNoApriori< ALLOC >&& from, const allocator_type& alloc);
87 
88  /// virtual copy constructor
89  virtual AprioriNoApriori< ALLOC >* clone() const;
90 
91  /// virtual copy constructor with a given allocator
92  virtual AprioriNoApriori< ALLOC >* clone(const allocator_type& alloc) const;
93 
94  /// destructor
95  virtual ~AprioriNoApriori();
96 
97  /// @}
98 
99 
100  // ##########################################################################
101  /// @name Operators
102  // ##########################################################################
103  /// @{
104 
105  /// copy operator
107 
108  /// move operator
110 
111  /// @}
112 
113 
114  // ##########################################################################
115  /// @name Accessors / Modifiers
116  // ##########################################################################
117  /// @{
118 
119  /// sets the weight of the a priori (kind of effective sample size)
120  virtual void setWeight(const double weight) final;
121 
122  /// indicates whether an apriori is of a certain type
123  virtual bool isOfType(const std::string& type) final;
124 
125  /// returns the type of the apriori
126  virtual const std::string& getType() const final;
127 
128  /// indicates whether the apriori is potentially informative
129  /** Basically, only the NoApriori is uninformative. However, it may happen
130  * that, under some circonstances, an apriori, which is usually not equal
131  * to the NoApriori, becomes equal to it (e.g., when the weight is equal
132  * to zero). In this case, if the apriori can detect this case, it shall
133  * inform the classes that use it that it is temporarily uninformative.
134  * These classes will then be able to speed-up their code by avoiding to
135  * take into account the apriori in their computations. */
136  virtual bool isInformative() const final;
137 
138  /// adds the apriori to a counting vector corresponding to the idset
139  /** adds the apriori to an already created counting vector defined over
140  * the union of the variables on both the left and right hand side of the
141  * conditioning bar of the idset.
142  * @warning the method assumes that the size of the vector is exactly
143  * the domain size of the joint variables set. */
144  virtual void addAllApriori(const IdCondSet< ALLOC >& idset,
145  std::vector< double, ALLOC< double > >& counts) final;
146 
147  /** @brief adds the apriori to a counting vectordefined over the right
148  * hand side of the idset
149  *
150  * @warning the method assumes that the size of the vector is exactly
151  * the domain size of the joint RHS variables of the idset. */
152  virtual void addConditioningApriori(const IdCondSet< ALLOC >& idset,
153  std::vector< double, ALLOC< double > >& counts) final;
154 
155  /// @}
156  };
157 
158  } /* namespace learning */
159 
160 } /* namespace gum */
161 
162 /// include the template implementation
163 #include <agrum/BN/learning/aprioris/aprioriNoApriori_tpl.h>
164 
165 #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:643
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