aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::ChiSquare Class Reference

<agrum/FMDP/learning/core/testPolicy/chiSquare.h> More...

#include <chiSquare.h>

Collaboration diagram for gum::ChiSquare:

Static Public Member Functions

static double probaChi2 (double x, Size df)
 computes the probability of chi2 value (used by the cache)

Static Private Member Functions

static double _exp_ (double x)
 Required constant to compute the cdf.
static double _probaZValue_ (double z)
 computes the probability of normal z value (used by the cache)

Static Private Attributes

static constexpr double _Z_MAX_ = 6.0
 Required constant to compute the cdf.
static constexpr double _CHI_EPSILON_ = 0.000001
 accuracy of critchi approximation
static constexpr double _CHI_MAX_ = 99999.0
 maximum chi square value
static constexpr double _LOG_SQRT_PI_ = 0.5723649429247000870717135
 log (sqrt (pi))
static constexpr double _I_SQRT_PI_ = 0.5641895835477562869480795
 1 / sqrt (pi)
static constexpr double _BIGX_ = 20.0
 max value to represent exp (x)

Detailed Description

<agrum/FMDP/learning/core/testPolicy/chiSquare.h>

Definition at line 68 of file chiSquare.h.

Member Function Documentation

◆ _exp_()

INLINE double gum::ChiSquare::_exp_ ( double x)
staticprivate

Required constant to compute the cdf.

Definition at line 48 of file chiSquare_inl.h.

48{ return (((x) < -_BIGX_) ? 0.0 : exp(x)); }
static constexpr double _BIGX_
max value to represent exp (x)
Definition chiSquare.h:92

References _BIGX_.

Referenced by probaChi2().

Here is the caller graph for this function:

◆ _probaZValue_()

double gum::ChiSquare::_probaZValue_ ( double z)
staticprivate

computes the probability of normal z value (used by the cache)

Definition at line 68 of file chiSquare.cpp.

68 {
69 // ++nbZt;
70
71 // z = std::round(z * std::pow(10, 3)) / std::pow(10, 3);
72 // if( ! _ZCache_.exists(z) ){
73
74 double y, x, w;
75
76 if (z == 0.0) x = 0.0;
77 else {
78 y = 0.5 * fabs(z);
79
80 if (y >= (_Z_MAX_ * 0.5)) x = 1.0;
81 else if (y < 1.0) {
82 w = y * y;
83 x = ((((((((0.000124818987 * w - 0.001075204047) * w + 0.005198775019) * w - 0.019198292004)
84 * w
85 + 0.059054035642)
86 * w
87 - 0.151968751364)
88 * w
89 + 0.319152932694)
90 * w
91 - 0.531923007300)
92 * w
93 + 0.797884560593)
94 * y * 2.0;
95 } else {
96 y -= 2.0;
97 x = (((((((((((((-0.000045255659 * y + 0.000152529290) * y - 0.000019538132) * y
98 - 0.000676904986)
99 * y
100 + 0.001390604284)
101 * y
102 - 0.000794620820)
103 * y
104 - 0.002034254874)
105 * y
106 + 0.006549791214)
107 * y
108 - 0.010557625006)
109 * y
110 + 0.011630447319)
111 * y
112 - 0.009279453341)
113 * y
114 + 0.005353579108)
115 * y
116 - 0.002141268741)
117 * y
118 + 0.000535310849)
119 * y
120 + 0.999936657524;
121 }
122 }
123
124 // _ZCache_.insert(z, ( z > 0.0 ? (( x + 1.0 ) * 0.5 ) : (( 1.0 - x )
125 // * 0.5 ) ) );
126 // } else {
127 // ++nbZ;
128 // }
129
130 // return _ZCache_[z];
131 return (z > 0.0 ? ((x + 1.0) * 0.5) : ((1.0 - x) * 0.5));
132 }
static constexpr double _Z_MAX_
Required constant to compute the cdf.
Definition chiSquare.h:77

References _Z_MAX_.

Referenced by probaChi2().

Here is the caller graph for this function:

◆ probaChi2()

double gum::ChiSquare::probaChi2 ( double x,
Size df )
static

computes the probability of chi2 value (used by the cache)

Definition at line 137 of file chiSquare.cpp.

137 {
138 double retVal = 0.0;
139 // ++nbChit;
140
141 // std::pair<double, unsigned long> conty(x, df);
142 // if( ! _chi2Cache_.exists(conty) ){
143
144 double a, y = 0, s;
145 double e, c, z;
146 int even; /* true if df is an even number */
147
148 if ((x <= 0.0) || (df < 1)) {
149 // _chi2Cache_.insert(conty,1.0);
150 retVal = 1.0;
151 } else {
152 a = 0.5 * x;
153
154 even = (2 * (df / 2)) == df;
155
156 if (df > 1) y = _exp_(-a);
157
158 s = (even ? y : (2.0 * _probaZValue_(-sqrt(x))));
159
160 if (df > 2) {
161 x = 0.5 * (df - 1.0);
162 z = (even ? 1.0 : 0.5);
163
164 if (a > _BIGX_) {
165 e = (even ? 0.0 : _LOG_SQRT_PI_);
166 c = log(a);
167
168 while (z <= x) {
169 e = log(z) + e;
170 s += _exp_(c * z - a - e);
171 z += 1.0;
172 }
173
174 // _chi2Cache_.insert(conty,s);
175 retVal = s;
176
177 } else {
178 e = (even ? 1.0 : (_I_SQRT_PI_ / sqrt(a)));
179 c = 0.0;
180
181 while (z <= x) {
182 e = e * (a / z);
183 c = c + e;
184 z += 1.0;
185 }
186
187 // _chi2Cache_.insert(conty,( c * y + s ));
188 retVal = (c * y + s);
189 }
190 } else {
191 // _chi2Cache_.insert(conty,s);
192 retVal = s;
193 }
194 }
195 // } else {
196 // ++nbChi;
197 // }
198 // std::cout << "Z avoid : " << nbZ << " / " << nbZt << ". Chi avoid :
199 // " << nbChi << " / " << nbChit << "." << std::endl;
200 // return _chi2Cache_[conty];
201 return retVal;
202 }
static double _probaZValue_(double z)
computes the probability of normal z value (used by the cache)
Definition chiSquare.cpp:68
static double _exp_(double x)
Required constant to compute the cdf.
static constexpr double _I_SQRT_PI_
1 / sqrt (pi)
Definition chiSquare.h:89
static constexpr double _LOG_SQRT_PI_
log (sqrt (pi))
Definition chiSquare.h:86

References _BIGX_, _exp_(), _I_SQRT_PI_, _LOG_SQRT_PI_, and _probaZValue_().

Referenced by gum::LeafPair::likelyhood(), gum::Chi2TestPolicy< GUM_ELEMENT >::score(), and gum::GTestPolicy< GUM_ELEMENT >::score().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _BIGX_

double gum::ChiSquare::_BIGX_ = 20.0
staticconstexprprivate

max value to represent exp (x)

Definition at line 92 of file chiSquare.h.

Referenced by _exp_(), and probaChi2().

◆ _CHI_EPSILON_

double gum::ChiSquare::_CHI_EPSILON_ = 0.000001
staticconstexprprivate

accuracy of critchi approximation

Definition at line 80 of file chiSquare.h.

◆ _CHI_MAX_

double gum::ChiSquare::_CHI_MAX_ = 99999.0
staticconstexprprivate

maximum chi square value

Definition at line 83 of file chiSquare.h.

◆ _I_SQRT_PI_

double gum::ChiSquare::_I_SQRT_PI_ = 0.5641895835477562869480795
staticconstexprprivate

1 / sqrt (pi)

Definition at line 89 of file chiSquare.h.

Referenced by probaChi2().

◆ _LOG_SQRT_PI_

double gum::ChiSquare::_LOG_SQRT_PI_ = 0.5723649429247000870717135
staticconstexprprivate

log (sqrt (pi))

Definition at line 86 of file chiSquare.h.

Referenced by probaChi2().

◆ _Z_MAX_

double gum::ChiSquare::_Z_MAX_ = 6.0
staticconstexprprivate

Required constant to compute the cdf.

maximum meaningful z value

Definition at line 77 of file chiSquare.h.

Referenced by _probaZValue_().


The documentation for this class was generated from the following files: