aGrUM  0.20.3
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

◆ _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 - 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 = (((((((((((((-0.000045255659 * y + 0.000152529290) * y - 0.000019538132) * y
74  - 0.000676904986)
75  * y
76  + 0.001390604284)
77  * y
78  - 0.000794620820)
79  * y
80  - 0.002034254874)
81  * y
82  + 0.006549791214)
83  * y
84  - 0.010557625006)
85  * y
86  + 0.011630447319)
87  * y
88  - 0.009279453341)
89  * y
90  + 0.005353579108)
91  * y
92  - 0.002141268741)
93  * y
94  + 0.000535310849)
95  * y
96  + 0.999936657524;
97  }
98  }
99 
100  // _ZCache_.insert(z, ( z > 0.0 ? (( x + 1.0 ) * 0.5 ) : (( 1.0 - x )
101  // * 0.5 ) ) );
102  // } else {
103  // ++nbZ;
104  // }
105 
106  // return _ZCache_[z];
107  return (z > 0.0 ? ((x + 1.0) * 0.5) : ((1.0 - x) * 0.5));
108  }
static constexpr double _Z_MAX_
Required constant to compute the cdf.
Definition: chiSquare.h:57
+ Here is the call 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 114 of file chiSquare.cpp.

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

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