aGrUM  0.13.2
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) More...

## Detailed Description

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

Definition at line 46 of file chiSquare.h.

## Member Function Documentation

 static double gum::ChiSquare::__exp ( double x )
inlinestaticprivate

Required constant to compute the cdf.

Definition at line 78 of file chiSquare.h.

References __probaZValue().

Referenced by probaChi2().

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Definition at line 41 of file chiSquare.cpp.

References __Z_MAX.

Referenced by __exp(), and probaChi2().

41  {
42  // ++nbZt;
43
44  // z = std::round(z * std::pow(10, 3)) / std::pow(10, 3);
45  // if( !__ZCache.exists(z) ){
46
47  double y, x, w;
48
49  if (z == 0.0)
50  x = 0.0;
51  else {
52  y = 0.5 * fabs(z);
53
54  if (y >= (__Z_MAX * 0.5))
55  x = 1.0;
56  else if (y < 1.0) {
57  w = y * y;
58  x = ((((((((0.000124818987 * w - 0.001075204047) * w + 0.005198775019) * w
59  - 0.019198292004)
60  * w
61  + 0.059054035642)
62  * w
63  - 0.151968751364)
64  * w
65  + 0.319152932694)
66  * w
67  - 0.531923007300)
68  * w
69  + 0.797884560593)
70  * y * 2.0;
71  } else {
72  y -= 2.0;
73  x =
74  (((((((((((((-0.000045255659 * y + 0.000152529290) * y - 0.000019538132)
75  * y
76  - 0.000676904986)
77  * y
78  + 0.001390604284)
79  * y
80  - 0.000794620820)
81  * y
82  - 0.002034254874)
83  * y
84  + 0.006549791214)
85  * y
86  - 0.010557625006)
87  * y
88  + 0.011630447319)
89  * y
90  - 0.009279453341)
91  * y
92  + 0.005353579108)
93  * y
94  - 0.002141268741)
95  * y
96  + 0.000535310849)
97  * y
98  + 0.999936657524;
99  }
100  }
101
102  // __ZCache.insert(z, ( z > 0.0 ? (( x + 1.0 ) * 0.5 ) : (( 1.0 - x )
103  // * 0.5 ) ) );
104  // } else {
105  // ++nbZ;
106  // }
107
108  // return __ZCache[z];
109  return (z > 0.0 ? ((x + 1.0) * 0.5) : ((1.0 - x) * 0.5));
110  }
static constexpr double __Z_MAX
Required constant to compute the cdf.
Definition: chiSquare.h:55

Here is the caller graph for this function:

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

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

Definition at line 116 of file chiSquare.cpp.

References __BIGX, __exp(), __I_SQRT_PI, __LOG_SQRT_PI, and __probaZValue().

116  {
117  double retVal = 0.0;
118  // ++nbChit;
119
120  // std::pair<double, unsigned long> conty(x, df);
121  // if( !__chi2Cache.exists(conty) ){
122
123  double a, y = 0, s;
124  double e, c, z;
125  int even; /* true if df is an even number */
126
127  if ((x <= 0.0) || (df < 1)) {
128  // __chi2Cache.insert(conty,1.0);
129  retVal = 1.0;
130  } else {
131  a = 0.5 * x;
132
133  even = (2 * (df / 2)) == df;
134
135  if (df > 1) y = __exp(-a);
136
137  s = (even ? y : (2.0 * __probaZValue(-sqrt(x))));
138
139  if (df > 2) {
140  x = 0.5 * (df - 1.0);
141  z = (even ? 1.0 : 0.5);
142
143  if (a > __BIGX) {
144  e = (even ? 0.0 : __LOG_SQRT_PI);
145  c = log(a);
146
147  while (z <= x) {
148  e = log(z) + e;
149  s += __exp(c * z - a - e);
150  z += 1.0;
151  }
152
153  // __chi2Cache.insert(conty,s);
154  retVal = s;
155
156  } else {
157  e = (even ? 1.0 : (__I_SQRT_PI / sqrt(a)));
158  c = 0.0;
159
160  while (z <= x) {
161  e = e * (a / z);
162  c = c + e;
163  z += 1.0;
164  }
165
166  // __chi2Cache.insert(conty,( c * y + s ));
167  retVal = (c * y + s);
168  }
169  } else {
170  // __chi2Cache.insert(conty,s);
171  retVal = s;
172  }
173  }
174  // } else {
175  // ++nbChi;
176  // }
177  // std::cout << "Z avoid : " << nbZ << " / " << nbZt << ". Chi avoid :
178  // " << nbChi << " / " << nbChit << "." << std::endl;
179  // return __chi2Cache[conty];
180  return retVal;
181  }
static constexpr double __LOG_SQRT_PI
log (sqrt (pi))
Definition: chiSquare.h:64
static constexpr double __BIGX
max value to represent exp (x)
Definition: chiSquare.h:70
static double __probaZValue(double z)
computes the probability of normal z value (used by the cache)
Definition: chiSquare.cpp:41
static double __exp(double x)
Required constant to compute the cdf.
Definition: chiSquare.h:78
static constexpr double __I_SQRT_PI
1 / sqrt (pi)
Definition: chiSquare.h:67

Here is the call graph for this function:

Here is the caller graph for this function:

## Member Data Documentation

 constexpr double gum::ChiSquare::__BIGX = 20.0
staticprivate

max value to represent exp (x)

Definition at line 70 of file chiSquare.h.

Referenced by probaChi2().

 constexpr double gum::ChiSquare::__CHI_EPSILON = 0.000001
staticprivate

accuracy of critchi approximation

Definition at line 58 of file chiSquare.h.

 constexpr double gum::ChiSquare::__CHI_MAX = 99999.0
staticprivate

maximum chi square value

Definition at line 61 of file chiSquare.h.

 constexpr double gum::ChiSquare::__I_SQRT_PI = 0.5641895835477562869480795
staticprivate

1 / sqrt (pi)

Definition at line 67 of file chiSquare.h.

Referenced by probaChi2().

 constexpr double gum::ChiSquare::__LOG_SQRT_PI = 0.5723649429247000870717135
staticprivate

log (sqrt (pi))

Definition at line 64 of file chiSquare.h.

Referenced by probaChi2().

 constexpr double gum::ChiSquare::__Z_MAX = 6.0
staticprivate

Required constant to compute the cdf.

maximum meaningful z value

Definition at line 55 of file chiSquare.h.

Referenced by __probaZValue().

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