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

Detailed Description

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

Definition at line 48 of file chiSquare.h.

Member Function Documentation

◆ exp__()

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

Required constant to compute the cdf.

Definition at line 80 of file chiSquare.h.

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

◆ probaChi2()

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

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

Definition at line 117 of file chiSquare.cpp.

References gum::Set< Key, Alloc >::emplace().

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

References gum::Set< Key, Alloc >::emplace().

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

Member Data Documentation

◆ BIGX__

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

max value to represent exp (x)

Definition at line 72 of file chiSquare.h.

◆ CHI_EPSILON__

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

accuracy of critchi approximation

Definition at line 60 of file chiSquare.h.

◆ CHI_MAX__

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

maximum chi square value

Definition at line 63 of file chiSquare.h.

◆ I_SQRT_PI__

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

1 / sqrt (pi)

Definition at line 69 of file chiSquare.h.

◆ LOG_SQRT_PI__

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

log (sqrt (pi))

Definition at line 66 of file chiSquare.h.

◆ Z_MAX__

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

Required constant to compute the cdf.

maximum meaningful z value

Definition at line 57 of file chiSquare.h.


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