aGrUM  0.14.2
indepTestChi2.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_INDEP_TEST_CHI2_H
27 #define GUM_LEARNING_INDEP_TEST_CHI2_H
28 
29 #include <vector>
30 
31 #include <agrum/core/math/chi2.h>
34 
35 namespace gum {
36 
37  namespace learning {
38 
44  template < template < typename > class ALLOC = std::allocator >
45  class IndepTestChi2 : public IndependenceTest< ALLOC > {
46  public:
48  using allocator_type = ALLOC< NodeId >;
49 
50  // ##########################################################################
52  // ##########################################################################
54 
56 
79  const DBRowGeneratorParser< ALLOC >& parser,
80  const Apriori< ALLOC >& external_apriori,
81  const std::vector< std::pair< std::size_t, std::size_t >,
82  ALLOC< std::pair< std::size_t, std::size_t > > >&
83  ranges,
84  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
85  nodeId2columns =
86  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
87  const allocator_type& alloc = allocator_type());
88 
89 
91 
106  const Apriori< ALLOC >& apriori,
107  const Bijection< NodeId, std::size_t, ALLOC< std::size_t > >&
108  nodeId2columns =
109  Bijection< NodeId, std::size_t, ALLOC< std::size_t > >(),
110  const allocator_type& alloc = allocator_type());
111 
114 
117  const allocator_type& alloc);
118 
121 
124 
126  virtual IndepTestChi2< ALLOC >* clone() const;
127 
129  virtual IndepTestChi2< ALLOC >* clone(const allocator_type& alloc) const;
130 
132  virtual ~IndepTestChi2();
133 
135 
136 
137  // ##########################################################################
139  // ##########################################################################
140 
142 
145 
148 
150 
151  // ##########################################################################
153  // ##########################################################################
154 
156 
159  std::pair< double, double >
160  statistics(NodeId var1,
161  NodeId var2,
162  const std::vector< NodeId, ALLOC< NodeId > >& rhs_ids = {});
163 
165 
166 
167  protected:
169 
172  virtual double _score(const IdSet< ALLOC >& idset) final;
173 
175  std::pair< double, double > _statistics(const IdSet< ALLOC >& idset);
176 
177 #ifndef DOXYGEN_SHOULD_SKIP_THIS
178 
179  private:
181  std::vector< std::size_t, ALLOC< std::size_t > > __domain_sizes;
182 
184  Chi2 __chi2;
185 
187  const std::vector< Idx > __empty_set;
188 
189 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
190  };
191 
192  } /* namespace learning */
193 
194 } /* namespace gum */
195 
196 
197 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
198 extern template class gum::learning::IndepTestChi2<>;
199 #endif
200 
201 
202 // always include the template implementation
204 
205 #endif /* GUM_LEARNING_INDEP_TEST_CHI2_H */
std::pair< double, double > _statistics(const IdSet< ALLOC > &idset)
compute the pair <chi2 statistic,pvalue>
virtual IndepTestChi2< ALLOC > * clone() const
virtual copy constructor
the base class for all the independence tests used for learning
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
Definition: indepTestChi2.h:48
The base class for all the independence tests used for learning.
IndepTestChi2(const DBRowGeneratorParser< ALLOC > &parser, const Apriori< ALLOC > &external_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
IndepTestChi2< ALLOC > & operator=(const IndepTestChi2< ALLOC > &from)
copy operator
ALLOC< NodeId > allocator_type
type for the allocators passed in arguments of methods
the no a priori class: corresponds to 0 weight-sample
the class for computing Chi2 independence test scores
Definition: indepTestChi2.h:45
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
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
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
the class for computing Chi2 scores
std::pair< double, double > statistics(NodeId var1, NodeId var2, const std::vector< NodeId, ALLOC< NodeId > > &rhs_ids={})
get the pair <chi2 statistic,pvalue> for a test var1 indep var2 given rhs_ids
Represent the chi2 distribution.
Definition: chi2.h:55
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
The class that represents the chi2 distribution.
virtual double _score(const IdSet< ALLOC > &idset) final
returns the score for a given IdSet
virtual ~IndepTestChi2()
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