aGrUM  0.16.0
chi2_inl.h
Go to the documentation of this file.
1 
34 namespace gum {
35 
36  // sets the conditioning nodes (useful for computing degrees of freedom)
37  INLINE void
38  Chi2::setConditioningNodes(const std::vector< Idx >& db_conditioning_ids) {
40  for (Idx i = 0; i < db_conditioning_ids.size(); ++i) {
41  __conditioning_size *= __modalities[db_conditioning_ids[i]];
42  }
43  }
44 
45  // returns the number of degrees of freedom
46  INLINE Size Chi2::degreesOfFreedom(const std::pair< Idx, Idx >& pair) {
47  return degreesOfFreedom(pair.first, pair.second);
48  }
49 
50  // returns the number of degrees of freedom
51  INLINE Size Chi2::degreesOfFreedom(Idx var1, Idx var2) {
52  return (__conditioning_size * (__modalities[var1] - 1)
53  * (__modalities[var2] - 1));
54  }
55 
56  // computes the critical value according to the number of degrees of freedom
57  ALWAYS_INLINE double Chi2::criticalValue(const std::pair< Idx, Idx >& pair) {
58  return criticalValue(pair.first, pair.second);
59  }
60 
61  // computes the critical value according to the number of degrees of freedom
62  ALWAYS_INLINE double Chi2::criticalValue(Idx var1, Idx var2) {
63  Size DF = degreesOfFreedom(var1, var2);
64 
65  // try to see if the threshold is not already in cache
66  try {
67  return __critical_values[DF];
68  } catch (const Exception&) {
69  // here we have to compute the threshold of the chi2
70  // we use Gary Perlman's algorithm
71  double value = __criticalValue(__confidence_proba, DF);
72  __critical_values.insert(DF, value);
73  return value;
74  }
75  }
76 
77  // modifies the confidence proba
78  INLINE void Chi2::setConfidenceProba(double new_proba) {
79  // if we did not change the confidence proba, do nothing
80  if (__confidence_proba == new_proba) return;
81 
82  __confidence_proba = new_proba;
83 
84  // remove the currently stored critical values
86  }
87 
88 } /* 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:38
static double __criticalValue(double proba, Size df)
Computes the critical value of a given chi2 test (used by the cache).
Definition: chi2.cpp:180
double __confidence_proba
The confidence probability used for critical values.
Definition: chi2.h:155
Size __conditioning_size
The domain size of the conditioning nodes.
Definition: chi2.h:158
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
HashTable< Idx, double > __critical_values
A set of already computed critical values.
Definition: chi2.h:161
Size degreesOfFreedom(const std::pair< Idx, Idx > &pair)
Returns the number of degrees of freedom.
Definition: chi2_inl.h:46
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:106
void clear()
Removes all the elements in the hash table.
void setConfidenceProba(double new_proba)
Modifies the confidence probability.
Definition: chi2_inl.h:78
Size Idx
Type for indexes.
Definition: types.h:53
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
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:57
const std::vector< std::size_t > & __modalities
The modalities of the random variables.
Definition: chi2.h:152