aGrUM  0.13.2
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 <cmath>
34 
35 #include <agrum/agrum.h>
36 #include <agrum/core/hashTable.h>
37 
38 #define GUM_LEARNING_CONFIDENCE_PROBA 0.05
39 
40 namespace gum {
41 
42  // =========================================================================
43  // === CHI2 CLASS ===
44  // =========================================================================
45 
56  class Chi2 {
57  public:
58  // ==========================================================================
60  // ==========================================================================
62 
68  Chi2(const std::vector< Idx >& var_modalities,
69  double confidence_proba = GUM_LEARNING_CONFIDENCE_PROBA);
70 
74  ~Chi2();
75 
77  // ==========================================================================
79  // ==========================================================================
81 
88  void setConditioningNodes(const std::vector< Idx >& db_conditioning_ids);
89 
96  double criticalValue(const std::pair< Idx, Idx >& pair);
97 
105  double criticalValue(Idx var1, Idx var2);
106 
112  Size degreesOfFreedom(const std::pair< Idx, Idx >& pair);
113 
120  Size degreesOfFreedom(Idx var1, Idx var2);
121 
126  void setConfidenceProba(double new_proba);
127 
129 
130  private:
132  const std::vector< Idx >& __modalities;
133 
136 
139 
142 
153  static double __criticalValue(double proba, Size df);
154 
171  static double __probaChi2(double x, Size df);
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 */
void setConditioningNodes(const std::vector< Idx > &db_conditioning_ids)
Sets the conditioning nodes (useful for computing degrees of freedom).
Definition: chi2_inl.h:35
unsigned long Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:50
static double __criticalValue(double proba, Size df)
Computes the critical value of a given chi2 test (used by the cache).
Definition: chi2.cpp:175
double __confidence_proba
The confidence probability used for critical values.
Definition: chi2.h:135
Size __conditioning_size
The domain size of the conditioning nodes.
Definition: chi2.h:138
#define GUM_LEARNING_CONFIDENCE_PROBA
Definition: chi2.h:38
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:141
~Chi2()
Class destructor.
Definition: chi2.cpp:62
static double __probaChi2(double x, Size df)
Computes the probability of chi2 value.
Definition: chi2.cpp:128
Represent the chi2 distribution.
Definition: chi2.h:56
Size degreesOfFreedom(const std::pair< Idx, Idx > &pair)
Returns the number of degrees of freedom.
Definition: chi2_inl.h:43
The class that represents the chi2 distribution.
void setConfidenceProba(double new_proba)
Modifies the confidence probability.
Definition: chi2_inl.h:87
double criticalValue(const std::pair< Idx, Idx > &pair)
Computes the critical value according to the number of degrees of freedom.
Definition: chi2_inl.h:55
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:68
unsigned long Idx
Type for indexes.
Definition: types.h:43
Class hash tables iterators.
Chi2(const std::vector< Idx > &var_modalities, double confidence_proba=GUM_LEARNING_CONFIDENCE_PROBA)
Default constructor.
Definition: chi2.cpp:55
const std::vector< Idx > & __modalities
The modalities of the random variables.
Definition: chi2.h:132