aGrUM  0.14.2
scoreK2.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_K2_H
30 #define GUM_LEARNING_SCORE_K2_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 
57  template < template < typename > class ALLOC = std::allocator >
58  class ScoreK2 : public Score< ALLOC > {
59  public:
61  using allocator_type = ALLOC< NodeId >;
62 
63  // ##########################################################################
65  // ##########################################################################
67 
69 
90  const Apriori< ALLOC >& apriori,
91  const std::vector< std::pair< std::size_t, std::size_t >,
92  ALLOC< std::pair< std::size_t, std::size_t > > >&
93  ranges,
94  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
95  nodeId2columns =
96  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
97  const allocator_type& alloc = allocator_type());
98 
99 
101 
116  const Apriori< ALLOC >& apriori,
117  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
118  nodeId2columns =
119  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
120  const allocator_type& alloc = allocator_type());
121 
123  ScoreK2(const ScoreK2< ALLOC >& from);
124 
126  ScoreK2(const ScoreK2< ALLOC >& from, const allocator_type& alloc);
127 
129  ScoreK2(ScoreK2< ALLOC >&& from);
130 
132  ScoreK2(ScoreK2< ALLOC >&& from, const allocator_type& alloc);
133 
135  virtual ScoreK2< ALLOC >* clone() const;
136 
138  virtual ScoreK2< ALLOC >* clone(const allocator_type& alloc) const;
139 
141  virtual ~ScoreK2();
142 
144 
145 
146  // ##########################################################################
148  // ##########################################################################
149 
151 
154 
157 
159 
160 
161  // ##########################################################################
163  // ##########################################################################
165 
167 
176  virtual std::string isAprioriCompatible() const final;
177 
179 
189  virtual const Apriori< ALLOC >& internalApriori() const final;
190 
192 
193 
195 
197  static std::string isAprioriCompatible(const std::string& apriori_type,
198  double weight = 1.0f);
199 
201 
202  static std::string isAprioriCompatible(const Apriori< ALLOC >& apriori);
203 
204 
205  protected:
207 
210  virtual double _score(const IdSet< ALLOC >& idset) final;
211 
212 
213 #ifndef DOXYGEN_SHOULD_SKIP_THIS
214 
215  private:
217  AprioriK2< ALLOC > __internal_apriori;
218 
220  GammaLog2 __gammalog2;
221 
222 
223 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
224  };
225 
226  } /* namespace learning */
227 
228 } /* namespace gum */
229 
230 
231 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
232 extern template class gum::learning::ScoreK2<>;
233 #endif
234 
235 
236 // always include the template implementation
238 
239 #endif /* GUM_LEARNING_SCORE_K2_H */
Useful macros for maths.
The class for computing Log2 (Gamma(x))
Definition: gammaLog2.h:45
The base class for all the scores used for learning (BIC, BDeu, etc)
Definition: score.h:49
the internal apriori for the K2 score = Laplace Apriori
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)).
the class for computing K2 scores (actually their log2 value)
Definition: scoreK2.h:58
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 class for computing K2 scores
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
ScoreK2< ALLOC > & operator=(const ScoreK2< ALLOC > &from)
copy operator
virtual ScoreK2< ALLOC > * clone() const
virtual copy constructor
ScoreK2(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
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
the base class for all the scores used for learning (BIC, BDeu, etc)
virtual const Apriori< ALLOC > & internalApriori() const final
returns the internal apriori of the score
virtual std::string isAprioriCompatible() const final
indicates whether the apriori is compatible (meaningful) with the score
the internal apriori for the K2 score = Laplace AprioriK2 is a BD score with a Laplace apriori (i...
Definition: aprioriK2.h:49
virtual double _score(const IdSet< ALLOC > &idset) final
returns the score for a given IdSet
virtual ~ScoreK2()
destructor
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
Definition: scoreK2.h:61