aGrUM  0.14.2
scoreBDeu.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  ***************************************************************************/
26 #ifndef GUM_LEARNING_SCORE_BDEU_H
27 #define GUM_LEARNING_SCORE_BDEU_H
28 
29 #include <string>
30 
31 #include <agrum/agrum.h>
32 #include <agrum/core/math/math.h>
36 
37 namespace gum {
38 
39  namespace learning {
40 
55  template < template < typename > class ALLOC = std::allocator >
56  class ScoreBDeu : public Score< ALLOC > {
57  public:
59  using allocator_type = ALLOC< NodeId >;
60 
61  // ##########################################################################
63  // ##########################################################################
65 
67 
87  ScoreBDeu(
88  const DBRowGeneratorParser< ALLOC >& parser,
89  const Apriori< ALLOC >& apriori,
90  const std::vector< std::pair< std::size_t, std::size_t >,
91  ALLOC< std::pair< std::size_t, std::size_t > > >&
92  ranges,
93  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
94  nodeId2columns =
95  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
96  const allocator_type& alloc = allocator_type());
97 
98 
100 
115  const Apriori< ALLOC >& apriori,
116  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
117  nodeId2columns =
118  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
119  const allocator_type& alloc = allocator_type());
120 
122  ScoreBDeu(const ScoreBDeu< ALLOC >& from);
123 
125  ScoreBDeu(const ScoreBDeu< ALLOC >& from, const allocator_type& alloc);
126 
129 
131  ScoreBDeu(ScoreBDeu< ALLOC >&& from, const allocator_type& alloc);
132 
134  virtual ScoreBDeu< ALLOC >* clone() const;
135 
137  virtual ScoreBDeu< ALLOC >* clone(const allocator_type& alloc) const;
138 
140  virtual ~ScoreBDeu();
141 
143 
144 
145  // ##########################################################################
147  // ##########################################################################
148 
150 
153 
156 
158 
159 
160  // ##########################################################################
162  // ##########################################################################
164 
166 
175  virtual std::string isAprioriCompatible() const final;
176 
178 
188  virtual const Apriori< ALLOC >& internalApriori() const final;
189 
191  void setEffectiveSampleSize(double ess);
192 
194 
195 
197 
199  static std::string isAprioriCompatible(const std::string& apriori_type,
200  double weight = 1.0f);
201 
203 
204  static std::string isAprioriCompatible(const Apriori< ALLOC >& apriori);
205 
206 
207  protected:
209 
212  virtual double _score(const IdSet< ALLOC >& idset) final;
213 
214 
215 #ifndef DOXYGEN_SHOULD_SKIP_THIS
216 
217  private:
219  AprioriBDeu< ALLOC > __internal_apriori;
220 
222  GammaLog2 __gammalog2;
223 
224 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
225  };
226 
227  } /* namespace learning */
228 
229 } /* namespace gum */
230 
231 
232 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
233 extern template class gum::learning::ScoreBDeu<>;
234 #endif
235 
236 
237 // always include the template implementation
239 
240 #endif /* GUM_LEARNING_SCORE_BDEU_H */
Useful macros for maths.
the class for computing BDeu scores
virtual ScoreBDeu< ALLOC > * clone() const
virtual copy constructor
The class for computing Log2 (Gamma(x))
Definition: gammaLog2.h:45
the class for computing BDeu scores
Definition: scoreBDeu.h:56
virtual const Apriori< ALLOC > & internalApriori() const final
returns the internal apriori of the score
The base class for all the scores used for learning (BIC, BDeu, etc)
Definition: score.h:49
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: scoreBDeu.h:59
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
The class for computing Log2 (Gamma(x)).
virtual ~ScoreBDeu()
destructor
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: score.h:52
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
the internal apriori for the BDeu score (N&#39; / (r_i * q_i)BDeu is a BD score with a N&#39;/(r_i * q_i) apr...
Definition: aprioriBDeu.h:51
const std::vector< std::pair< std::size_t, std::size_t >, ALLOC< std::pair< std::size_t, std::size_t > > > & ranges() const
returns the current ranges
void setEffectiveSampleSize(double ess)
sets the effective sample size of the internal apriori
virtual double _score(const IdSet< ALLOC > &idset) final
returns the score for a given IdSet
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
virtual std::string isAprioriCompatible() const final
indicates whether the apriori is compatible (meaningful) with the score
the base class for all the scores used for learning (BIC, BDeu, etc)
ScoreBDeu< ALLOC > & operator=(const ScoreBDeu< ALLOC > &from)
copy operator
ScoreBDeu(const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &apriori, const std::vector< std::pair< std::size_t, std::size_t >, ALLOC< std::pair< std::size_t, std::size_t > > > &ranges, 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 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
the internal apriori for the BDeu score (N&#39; / (r_i * q_i)