aGrUM  0.14.2
aprioriDirichletFromDatabase.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_DIRICHLET_FROM_DATABASE_H
26 #define GUM_LEARNING_A_PRIORI_DIRICHLET_FROM_DATABASE_H
27 
28 #include <vector>
29 
30 #include <agrum/agrum.h>
33 
34 namespace gum {
35 
36  namespace learning {
37 
43  template < template < typename > class ALLOC = std::allocator >
44  class AprioriDirichletFromDatabase : public Apriori< ALLOC > {
45  public:
48 
50  using allocator_type = ALLOC< NodeId >;
51 
52 
53  // ##########################################################################
55  // ##########################################################################
57 
59 
79  const DatabaseTable< ALLOC >& learning_db,
80  const DBRowGeneratorParser< ALLOC >& apriori_parser,
81  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
82  nodeId2columns =
83  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
84  const allocator_type& alloc = allocator_type());
85 
89 
93  const allocator_type& alloc);
94 
97 
100  const allocator_type& alloc);
101 
104 
107  clone(const allocator_type& alloc) const;
108 
111 
113 
114 
115  // ##########################################################################
117  // ##########################################################################
119 
123 
127 
129 
130 
131  // ##########################################################################
133  // ##########################################################################
135 
137  virtual bool isOfType(const std::string& type) final;
138 
140  virtual const std::string& getType() const final;
141 
143 
150  virtual bool isInformative() const final;
151 
153  virtual void setWeight(const double weight) final;
154 
156 
161  virtual void
162  addAllApriori(const IdSet< ALLOC >& idset,
163  std::vector< double, ALLOC< double > >& counts) final;
164 
170  virtual void addConditioningApriori(
171  const IdSet< ALLOC >& idset,
172  std::vector< double, ALLOC< double > >& counts) final;
173 
175 
176 
177 #ifndef DOXYGEN_SHOULD_SKIP_THIS
178 
179  private:
180  // the record counter used to parse the apriori database
181  RecordCounter< ALLOC > __counter;
182 
183  // the internal weight is equal to _weight / nb rows of apriori database
184  // this internal weight is used to ensure that assigning a weight of 1
185  // to the apriori is equivalent to adding just one row to the learning
186  // database
187  double __internal_weight;
188 
189 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
190  };
191 
192  } /* namespace learning */
193 
194 } /* namespace gum */
195 
198 
199 #endif /* GUM_LEARNING_A_PRIORI_DIRICHLET_FROM_DATABASE_H */
virtual bool isOfType(const std::string &type) final
indicates whether an apriori is of a certain type
virtual AprioriDirichletFromDatabase< ALLOC > * clone() const
virtual copy constructor
the base class for all a priori
STL namespace.
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
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual bool isInformative() const final
indicates whether the apriori is potentially informative
A dirichlet priori: computes its N&#39;_ijk from a database.
The class that computes countings of observations from the database.
A dirichlet priori: computes its N&#39;_ijk from a database.
The class that computes countings of observations from the database.
virtual void setWeight(const double weight) final
sets the weight of the a priori (kind of effective sample size)
double weight() const
returns the weight assigned to the apriori
virtual void addConditioningApriori(const IdSet< 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 ~AprioriDirichletFromDatabase()
destructor
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
AprioriDirichletFromDatabase(const DatabaseTable< ALLOC > &learning_db, const DBRowGeneratorParser< ALLOC > &apriori_parser, 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
The class representing a tabular database as used by learning tasks.
virtual const std::string & getType() const final
returns the type of the apriori
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: apriori.h:50
virtual void addAllApriori(const IdSet< ALLOC > &idset, std::vector< double, ALLOC< double > > &counts) final
adds the apriori to a counting vector corresponding to the idset
the class used to read a row in the database and to transform it into a set of DBRow instances that c...
Size NodeId
Type for node ids.
Definition: graphElements.h:97
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
AprioriDirichletFromDatabase< ALLOC > & operator=(const AprioriDirichletFromDatabase< ALLOC > &from)
copy operator