aGrUM  0.14.2
apriori.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
25 #ifndef GUM_LEARNING_A_PRIORI_H
26 #define GUM_LEARNING_A_PRIORI_H
27 
28 #include <string>
29 #include <vector>
30 
31 #include <agrum/agrum.h>
32 #include <agrum/core/bijection.h>
36 
37 namespace gum {
38 
39  namespace learning {
40 
46  template < template < typename > class ALLOC = std::allocator >
47  class Apriori : private ALLOC< NodeId > {
48  public:
50  using allocator_type = ALLOC< NodeId >;
51 
52  // ##########################################################################
54  // ##########################################################################
56 
58 
69  Apriori(const DatabaseTable< ALLOC >& database,
70  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
71  nodeId2columns =
72  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
73  const allocator_type& alloc = allocator_type());
74 
76  virtual Apriori< ALLOC >* clone() const = 0;
77 
79  virtual Apriori< ALLOC >* clone(const allocator_type& alloc) const = 0;
80 
82  virtual ~Apriori();
83 
85 
86  // ##########################################################################
88  // ##########################################################################
90 
92  virtual void setWeight(const double weight);
93 
95  double weight() const;
96 
98  virtual bool isOfType(const std::string& type) = 0;
99 
101  virtual const std::string& getType() const = 0;
102 
104 
111  virtual bool isInformative() const = 0;
112 
114 
119  virtual void
120  addAllApriori(const IdSet< ALLOC >& idset,
121  std::vector< double, ALLOC< double > >& counts) = 0;
122 
128  virtual void addConditioningApriori(
129  const IdSet< ALLOC >& idset,
130  std::vector< double, ALLOC< double > >& counts) = 0;
131 
134 
136 
137 
138  protected:
140  double _weight{1.0};
141 
144 
148 
149 
151  Apriori(const Apriori< ALLOC >& from);
152 
154  Apriori(const Apriori< ALLOC >& from, const allocator_type& alloc);
155 
157  Apriori(Apriori< ALLOC >&& from);
158 
160  Apriori(Apriori< ALLOC >&& from, const allocator_type& alloc);
161 
164 
167  };
168 
169  } /* namespace learning */
170 
171 } /* namespace gum */
172 
175 
176 #endif /* GUM_LEARNING_A_PRIORI_H */
virtual void setWeight(const double weight)
sets the weight of the a priori (kind of effective sample size)
virtual const std::string & getType() const =0
returns the type of the apriori
The class representing a tabular database stored in RAM.
the base class for all a prioris
virtual bool isOfType(const std::string &type)=0
indicates whether an apriori is of a certain type
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set...
Definition: idSet.h:45
the base class for all a priori
Definition: apriori.h:47
A class used by learning caches to represent uniquely sets of variables.
virtual void addConditioningApriori(const IdSet< ALLOC > &idset, std::vector< double, ALLOC< double > > &counts)=0
adds the apriori to a counting vectordefined over the right hand side of the idset ...
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
const DatabaseTable< ALLOC > * _database
a reference to the database in order to have access to its variables
Definition: apriori.h:143
virtual Apriori< ALLOC > * clone() const =0
virtual copy constructor
virtual void addAllApriori(const IdSet< ALLOC > &idset, std::vector< double, ALLOC< double > > &counts)=0
adds the apriori to a counting vector corresponding to the idset
double weight() const
returns the weight assigned to the apriori
double _weight
the weight of the apriori
Definition: apriori.h:140
Apriori< ALLOC > & operator=(const Apriori< ALLOC > &from)
copy operator
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
the different types of apriori
The class representing a tabular database as used by learning tasks.
virtual bool isInformative() const =0
indicates whether the apriori is potentially informative
allocator_type getAllocator() const
returns the allocator used by the internal apriori
Bijection< NodeId, std::size_t, ALLOC< std::size_t > > _nodeId2columns
a mapping from the NodeIds of the variables to the indices of the columns in the database ...
Definition: apriori.h:147
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: apriori.h:50
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Apriori(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
Set of pairs of elements with fast search for both elements.
virtual ~Apriori()
destructor