54#ifndef DOXYGEN_SHOULD_SKIP_THIS
59# define GUM_CHI_EPSILON 0.000001
60# define GUM_CHI_MAX 99999.0
61# define GUM_LOG_SQRT_PI 0.5723649429247000870717135
62# define GUM_I_SQRT_PI 0.5641895835477562869480795
64# define _gum_ex(x) (((x) < -GUM_BIGX) ? 0.0 : std::exp(x))
76 Chi2::Chi2(
const std::vector< std::size_t >& var_modalities,
double confidence_proba) :
79 GUM_CONSTRUCTOR(
Chi2);
92 if (z == 0.0) x = 0.0;
94 y = 0.5 * std::fabs(z);
96 if (y >= (GUM_Z_MAX * 0.5)) x = 1.0;
99 x = ((((((((0.000124818987 * w - 0.001075204047) * w + 0.005198775019) * w - 0.019198292004)
113 x = (((((((((((((-0.000045255659 * y + 0.000152529290) * y - 0.000019538132) * y
140 return (z > 0.0 ? ((x + 1.0) * 0.5) : ((1.0 - x) * 0.5));
149 if ((x <= 0.0) || (df < 1))
return (1.0);
153 even = (2 * (df / 2)) == df;
155 if (df > 1) y = _gum_ex(-a);
160 x = 0.5 * (df - 1.0);
161 z = (even ? 1.0 : 0.5);
164 e = (even ? 0.0 : GUM_LOG_SQRT_PI);
169 s += _gum_ex(c * z - a - e);
175 e = (even ? 1.0 : (GUM_I_SQRT_PI / std::sqrt(a)));
191 double minchisq = 0.0;
192 double maxchisq = GUM_CHI_MAX;
195 if (proba <= 0.0)
return (maxchisq);
196 else if (proba >= 1.0)
return (0.0);
198 chisqval = df / std::sqrt(proba);
200 while (maxchisq - minchisq > GUM_CHI_EPSILON) {
201 if (
probaChi2(chisqval, df) < proba) maxchisq = chisqval;
202 else minchisq = chisqval;
204 chisqval = (maxchisq + minchisq) * 0.5;
The class that represents the chi2 distribution.
The class that represents the chi2 distribution.
double _confidence_proba_
The confidence probability used for critical values.
const std::vector< std::size_t > & _modalities_
The modalities of the random variables.
static double _probaZValue_(double z)
Computes the probability of normal z value.
static double _criticalValue_(double proba, Size df)
Computes the critical value of a given chi2 test (used by the cache).
Chi2(const std::vector< std::size_t > &var_modalities, double confidence_proba=GUM_LEARNING_CONFIDENCE_PROBA)
Default constructor.
static double probaChi2(double x, Size df)
Computes the probability of chi2 value.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
gum is the global namespace for all aGrUM entities