32 #ifndef DOXYGEN_SHOULD_SKIP_THIS 36 # define GUM_Z_MAX 6.0 // maximum meaningful z value 37 # define GUM_CHI_EPSILON 0.000001 // accuracy of critchi approximation 38 # define GUM_CHI_MAX 99999.0 // maximum chi square value 39 # define GUM_LOG_SQRT_PI \ 40 0.5723649429247000870717135 // std::log (std::sqrt (pi)) 41 # define GUM_I_SQRT_PI 0.5641895835477562869480795 // 1 / std::sqrt (pi) 42 # define GUM_BIGX 20.0 // max value to represent exp (x) 43 # define gum__ex(x) (((x) < -GUM_BIGX) ? 0.0 : std::exp(x)) 55 Chi2::Chi2(
const std::vector< std::size_t >& var_modalities,
56 double confidence_proba) :
57 __modalities(var_modalities),
58 __confidence_proba(confidence_proba) {
60 GUM_CONSTRUCTOR(
Chi2);
76 y = 0.5 * std::fabs(z);
78 if (y >= (GUM_Z_MAX * 0.5))
82 x = ((((((((0.000124818987 * w - 0.001075204047) * w + 0.005198775019) * w
98 (((((((((((((-0.000045255659 * y + 0.000152529290) * y - 0.000019538132)
126 return (z > 0.0 ? ((x + 1.0) * 0.5) : ((1.0 - x) * 0.5));
135 if ((x <= 0.0) || (df < 1))
return (1.0);
139 even = (2 * (df / 2)) == df;
141 if (df > 1) y = gum__ex(-a);
146 x = 0.5 * (df - 1.0);
147 z = (even ? 1.0 : 0.5);
150 e = (even ? 0.0 : GUM_LOG_SQRT_PI);
155 s += gum__ex(c * z - a - e);
161 e = (even ? 1.0 : (GUM_I_SQRT_PI / std::sqrt(a)));
178 double minchisq = 0.0;
179 double maxchisq = GUM_CHI_MAX;
184 else if (proba >= 1.0)
187 chisqval = df / std::sqrt(proba);
189 while (maxchisq - minchisq > GUM_CHI_EPSILON) {
195 chisqval = (maxchisq + minchisq) * 0.5;
static double __criticalValue(double proba, Size df)
Computes the critical value of a given chi2 test (used by the cache).
gum is the global namespace for all aGrUM entities
Represent the chi2 distribution.
static double probaChi2(double x, Size df)
Computes the probability of chi2 value.
The class that represents the chi2 distribution.
The class that represents the chi2 distribution.
Chi2(const std::vector< std::size_t > &var_modalities, double confidence_proba=GUM_LEARNING_CONFIDENCE_PROBA)
Default constructor.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
static double __probaZValue(double z)
Computes the probability of normal z value.