aGrUM  0.14.1
chi2.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  ***************************************************************************/
30 #ifndef GUM_LEARNING_CHI2_H
31 #define GUM_LEARNING_CHI2_H
32 
33 #include <agrum/agrum.h>
34 #include <agrum/core/math/math.h>
35 #include <agrum/core/hashTable.h>
36 
37 #define GUM_LEARNING_CONFIDENCE_PROBA 0.05
38 
39 namespace gum {
40 
41  // =========================================================================
42  // === CHI2 CLASS ===
43  // =========================================================================
44 
55  class Chi2 {
56  public:
57  // ==========================================================================
59  // ==========================================================================
61 
67  Chi2(const std::vector< std::size_t >& var_modalities,
68  double confidence_proba = GUM_LEARNING_CONFIDENCE_PROBA);
69 
73  ~Chi2();
74 
76  // ==========================================================================
78  // ==========================================================================
80 
87  void setConditioningNodes(const std::vector< Idx >& db_conditioning_ids);
88 
95  double criticalValue(const std::pair< Idx, Idx >& pair);
96 
104  double criticalValue(Idx var1, Idx var2);
105 
111  Size degreesOfFreedom(const std::pair< Idx, Idx >& pair);
112 
119  Size degreesOfFreedom(Idx var1, Idx var2);
120 
125  void setConfidenceProba(double new_proba);
126 
144  static double probaChi2(double x, Size df);
146 
147  private:
149  const std::vector< std::size_t >& __modalities;
150 
153 
156 
159 
170  static double __criticalValue(double proba, Size df);
171 
172 
188  static double __probaZValue(double z);
189 
191  Chi2(const Chi2&) = delete;
192 
194  Chi2& operator=(const Chi2&) = delete;
195  };
196 
197 } /* namespace gum */
198 
200 #ifndef GUM_NO_INLINE
201 # include <agrum/core/math/chi2_inl.h>
202 #endif /* GUM_NO_INLINE */
203 
204 #endif /* GUM_LEARNING_CHI2_H */
Useful macros for maths.
void setConditioningNodes(const std::vector< Idx > &db_conditioning_ids)
Sets the conditioning nodes (useful for computing degrees of freedom).
Definition: chi2_inl.h:35
static double __criticalValue(double proba, Size df)
Computes the critical value of a given chi2 test (used by the cache).
Definition: chi2.cpp:177
double __confidence_proba
The confidence probability used for critical values.
Definition: chi2.h:152
Size __conditioning_size
The domain size of the conditioning nodes.
Definition: chi2.h:155
#define GUM_LEARNING_CONFIDENCE_PROBA
Definition: chi2.h:37
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
HashTable< Idx, double > __critical_values
A set of already computed critical values.
Definition: chi2.h:158
~Chi2()
Class destructor.
Definition: chi2.cpp:64
Represent the chi2 distribution.
Definition: chi2.h:55
Size degreesOfFreedom(const std::pair< Idx, Idx > &pair)
Returns the number of degrees of freedom.
Definition: chi2_inl.h:43
static double probaChi2(double x, Size df)
Computes the probability of chi2 value.
Definition: chi2.cpp:130
The class that represents the chi2 distribution.
Chi2(const std::vector< std::size_t > &var_modalities, double confidence_proba=GUM_LEARNING_CONFIDENCE_PROBA)
Default constructor.
Definition: chi2.cpp:55
void setConfidenceProba(double new_proba)
Modifies the confidence probability.
Definition: chi2_inl.h:75
Size Idx
Type for indexes.
Definition: types.h:50
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
double criticalValue(const std::pair< Idx, Idx > &pair)
Computes the critical value according to the number of degrees of freedom.
Definition: chi2_inl.h:54
Chi2 & operator=(const Chi2 &)=delete
Forbid used of the copy operator.
static double __probaZValue(double z)
Computes the probability of normal z value.
Definition: chi2.cpp:70
const std::vector< std::size_t > & __modalities
The modalities of the random variables.
Definition: chi2.h:149
Class hash tables iterators.