aGrUM  0.14.1
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 45 of file chiSquare.h.

## ◆ __exp()

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

Required constant to compute the cdf.

Definition at line 77 of file chiSquare.h.

References __probaZValue().

Referenced by probaChi2().

77 { return (((x) < -__BIGX) ? 0.0 : exp(x)); }
static constexpr double __BIGX
max value to represent exp (x)
Definition: chiSquare.h:69
Here is the call graph for this function:
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 40 of file chiSquare.cpp.

References __Z_MAX.

Referenced by __exp(), and probaChi2().

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

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

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

## ◆ __BIGX

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

max value to represent exp (x)

Definition at line 69 of file chiSquare.h.

Referenced by probaChi2().

## ◆ __CHI_EPSILON

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

accuracy of critchi approximation

Definition at line 57 of file chiSquare.h.

## ◆ __CHI_MAX

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

maximum chi square value

Definition at line 60 of file chiSquare.h.

## ◆ __I_SQRT_PI

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

1 / sqrt (pi)

Definition at line 66 of file chiSquare.h.

Referenced by probaChi2().

## ◆ __LOG_SQRT_PI

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

log (sqrt (pi))

Definition at line 63 of file chiSquare.h.

Referenced by probaChi2().

## ◆ __Z_MAX

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

Required constant to compute the cdf.

maximum meaningful z value

Definition at line 54 of file chiSquare.h.

Referenced by __probaZValue().

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