aGrUM  0.14.2
chi2_inl.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  ***************************************************************************/
31 namespace gum {
32 
33  // sets the conditioning nodes (useful for computing degrees of freedom)
34  INLINE void
35  Chi2::setConditioningNodes(const std::vector< Idx >& db_conditioning_ids) {
37  for (Idx i = 0; i < db_conditioning_ids.size(); ++i) {
38  __conditioning_size *= __modalities[db_conditioning_ids[i]];
39  }
40  }
41 
42  // returns the number of degrees of freedom
43  INLINE Size Chi2::degreesOfFreedom(const std::pair< Idx, Idx >& pair) {
44  return degreesOfFreedom(pair.first, pair.second);
45  }
46 
47  // returns the number of degrees of freedom
48  INLINE Size Chi2::degreesOfFreedom(Idx var1, Idx var2) {
49  return (__conditioning_size * (__modalities[var1] - 1)
50  * (__modalities[var2] - 1));
51  }
52 
53  // computes the critical value according to the number of degrees of freedom
54  ALWAYS_INLINE double Chi2::criticalValue(const std::pair< Idx, Idx >& pair) {
55  return criticalValue(pair.first, pair.second);
56  }
57 
58  // computes the critical value according to the number of degrees of freedom
59  ALWAYS_INLINE double Chi2::criticalValue(Idx var1, Idx var2) {
60  Size DF = degreesOfFreedom(var1, var2);
61 
62  // try to see if the threshold is not already in cache
63  try {
64  return __critical_values[DF];
65  } catch (const Exception&) {
66  // here we have to compute the threshold of the chi2
67  // we use Gary Perlman's algorithm
68  double value = __criticalValue(__confidence_proba, DF);
69  __critical_values.insert(DF, value);
70  return value;
71  }
72  }
73 
74  // modifies the confidence proba
75  INLINE void Chi2::setConfidenceProba(double new_proba) {
76  // if we did not change the confidence proba, do nothing
77  if (__confidence_proba == new_proba) return;
78 
79  __confidence_proba = new_proba;
80 
81  // remove the currently stored critical values
83  }
84 
85 } /* namespace gum */
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
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
Size degreesOfFreedom(const std::pair< Idx, Idx > &pair)
Returns the number of degrees of freedom.
Definition: chi2_inl.h:43
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:103
void clear()
Removes all the elements in the hash table.
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
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
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
const std::vector< std::size_t > & __modalities
The modalities of the random variables.
Definition: chi2.h:149