aGrUM 2.3.2
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_()

double gum::ChiSquare::_exp_ ( double x)
inlinestaticprivate

Required constant to compute the cdf.

Definition at line 100 of file chiSquare.h.

100{ 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 64 of file chiSquare.cpp.

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

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