aGrUM  0.14.2
scoreBD.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  ***************************************************************************/
29 #ifndef GUM_LEARNING_SCORE_BD_H
30 #define GUM_LEARNING_SCORE_BD_H
31 
32 #include <string>
33 
34 #include <agrum/agrum.h>
35 #include <agrum/core/math/math.h>
39 
40 namespace gum {
41 
42  namespace learning {
43 
61  template < template < typename > class ALLOC = std::allocator >
62  class ScoreBD : public Score< ALLOC > {
63  public:
65  using allocator_type = ALLOC< NodeId >;
66 
67  // ##########################################################################
69  // ##########################################################################
71 
73 
94  const Apriori< ALLOC >& apriori,
95  const std::vector< std::pair< std::size_t, std::size_t >,
96  ALLOC< std::pair< std::size_t, std::size_t > > >&
97  ranges,
98  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
99  nodeId2columns =
100  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
101  const allocator_type& alloc = allocator_type());
102 
103 
105 
120  const Apriori< ALLOC >& apriori,
121  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
122  nodeId2columns =
123  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
124  const allocator_type& alloc = allocator_type());
125 
127  ScoreBD(const ScoreBD< ALLOC >& from);
128 
130  ScoreBD(const ScoreBD< ALLOC >& from, const allocator_type& alloc);
131 
133  ScoreBD(ScoreBD< ALLOC >&& from);
134 
136  ScoreBD(ScoreBD< ALLOC >&& from, const allocator_type& alloc);
137 
139  virtual ScoreBD< ALLOC >* clone() const;
140 
142  virtual ScoreBD< ALLOC >* clone(const allocator_type& alloc) const;
143 
145  virtual ~ScoreBD();
146 
148 
149 
150  // ##########################################################################
152  // ##########################################################################
153 
155 
158 
161 
163 
164 
165  // ##########################################################################
167  // ##########################################################################
169 
171 
180  virtual std::string isAprioriCompatible() const final;
181 
183 
193  virtual const Apriori< ALLOC >& internalApriori() const final;
194 
196 
197 
199 
201  static std::string isAprioriCompatible(const std::string& apriori_type,
202  double weight = 1.0f);
203 
205 
206  static std::string isAprioriCompatible(const Apriori< ALLOC >& apriori);
207 
208 
209  protected:
211 
214  virtual double _score(const IdSet< ALLOC >& idset) final;
215 
216 
217 #ifndef DOXYGEN_SHOULD_SKIP_THIS
218 
219  private:
221  AprioriNoApriori< ALLOC > __internal_apriori;
222 
224  GammaLog2 __gammalog2;
225 
226 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
227  };
228 
229  } /* namespace learning */
230 
231 } /* namespace gum */
232 
233 
234 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
235 extern template class gum::learning::ScoreBD<>;
236 #endif
237 
238 
239 // always include the template implementation
241 
242 #endif /* GUM_LEARNING_SCORE_BD_H */
Useful macros for maths.
virtual const Apriori< ALLOC > & internalApriori() const final
returns the internal apriori of the score
The class for computing Log2 (Gamma(x))
Definition: gammaLog2.h:45
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: scoreBD.h:65
The base class for all the scores used for learning (BIC, BDeu, etc)
Definition: score.h:49
the no a priori class: corresponds to 0 weight-sample
the class for computing Bayesian Dirichlet (BD) log2 scores
Definition: scoreBD.h:62
ScoreBD(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
virtual double _score(const IdSet< ALLOC > &idset) final
returns the score for a given IdSet
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 ~ScoreBD()
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
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
the class for computing BD scores
ScoreBD< ALLOC > & operator=(const ScoreBD< ALLOC > &from)
copy operator
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)
virtual ScoreBD< ALLOC > * clone() const
virtual copy 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 no a priori class: corresponds to 0 weight-sample