aGrUM  0.16.0
GTestPolicy_tpl.h
Go to the documentation of this file.
1 
29 // =========================================================================
30 #include <agrum/core/math/math.h>
32 // =========================================================================
33 
34 
35 namespace gum {
36 
37 
38  // ##########################################################################
39  //
40  // ##########################################################################
41 
42  // ==========================================================================
43  //
44  // ==========================================================================
45  template < typename GUM_SCALAR >
46  void GTestPolicy< GUM_SCALAR >::addObservation(Idx iattr, GUM_SCALAR ivalue) {
48  __conTab.add(iattr, ivalue);
49  }
50 
51 
52  // ############################################################################
53  // @name Test result
54  // ############################################################################
55 
56  // ============================================================================
57  // Computes the GStat of current variable according to the test
58  // ============================================================================
59  template < typename GUM_SCALAR >
62  __GStat = 0;
63 
64  // Itération sur l'axe 1 du tableau
65  for (auto attrIter = __conTab.attrABeginSafe();
66  attrIter != __conTab.attrAEndSafe();
67  ++attrIter) {
68  // Mise en cache de valeur utile
69  double semiExpected =
70  (double)(attrIter.val()) / (double)this->nbObservation();
71 
72  // Itération sur l'axe 2 du tableau
73  for (auto valIter = __conTab.attrBBeginSafe();
74  valIter != __conTab.attrBEndSafe();
75  ++valIter) {
76  // Récupération de la valeur en cellule
77  Idx cell = __conTab.joint(attrIter.key(), valIter.key());
78  if (cell < 5) continue;
79 
80  // Récupération de la valeur en axe 2
81  double expected = semiExpected * (double)valIter.val();
82 
83  __GStat += 2 * cell * log(cell / expected);
84  }
85  }
86  }
87 
88  // ============================================================================
89  // Returns the performance of current variable according to the test
90  // ============================================================================
91  template < typename GUM_SCALAR >
93  if (this->_isModified()) computeScore();
94  // std::cout << this->toString() << std::endl;
95  double score =
96  1
98  __GStat, (__conTab.attrASize() - 1) * (__conTab.attrBSize() - 1));
99  return score;
100  }
101 
102  // ============================================================================
103  // Returns a second criterion to severe ties
104  // ============================================================================
105  template < typename GUM_SCALAR >
107  if (this->_isModified()) computeScore();
108  return __GStat;
109  }
110 
111  template < typename GUM_SCALAR >
114  __conTab += src.ct();
115  }
116 
117 } // End of namespace gum
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void computeScore() const
Computes the GStat of current variable according to the test.
virtual void computeScore() const
Recomputes the statistic from the beginning.
Definition: ITestPolicy.h:117
void addObservation(Idx iattr, GUM_SCALAR ivalue)
Comptabilizes the new observation.
const ContingencyTable< Idx, GUM_SCALAR > & ct() const
Returns contingency table (needed for the merging of GTestPolicy instances)
Definition: GTestPolicy.h:145
virtual void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.
Definition: ITestPolicy.h:90
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
double secondaryscore() const
Returns a second criterion to severe ties.
static double probaChi2(double x, Size df)
computes the probability of chi2 value (used by the cache)
Definition: chiSquare.cpp:118
<agrum/multidim/core/testPolicies/GTestPolicy.h>
Definition: GTestPolicy.h:53
double score() const
Returns the performance of current variable according to the test.
void add(const ITestPolicy< GUM_SCALAR > &src)
Definition: ITestPolicy.h:140
void add(const GTestPolicy< GUM_SCALAR > &src)
Performs the merging of current GTestPolicy instance with given instance.
Size Idx
Type for indexes.
Definition: types.h:53