35 #ifndef DOXYGEN_SHOULD_SKIP_THIS 39 # define GUM_Z_MAX 6.0 // maximum meaningful z value 40 # define GUM_CHI_EPSILON 0.000001 // accuracy of critchi approximation 41 # define GUM_CHI_MAX 99999.0 // maximum chi square value 42 # define GUM_LOG_SQRT_PI \ 43 0.5723649429247000870717135 // std::log (std::sqrt (pi)) 44 # define GUM_I_SQRT_PI 0.5641895835477562869480795 // 1 / std::sqrt (pi) 45 # define GUM_BIGX 20.0 // max value to represent exp (x) 46 # define gum__ex(x) (((x) < -GUM_BIGX) ? 0.0 : std::exp(x)) 58 Chi2::Chi2(
const std::vector< std::size_t >& var_modalities,
59 double confidence_proba) :
60 __modalities(var_modalities),
61 __confidence_proba(confidence_proba) {
63 GUM_CONSTRUCTOR(
Chi2);
79 y = 0.5 * std::fabs(z);
81 if (y >= (GUM_Z_MAX * 0.5))
85 x = ((((((((0.000124818987 * w - 0.001075204047) * w + 0.005198775019) * w
101 (((((((((((((-0.000045255659 * y + 0.000152529290) * y - 0.000019538132)
129 return (z > 0.0 ? ((x + 1.0) * 0.5) : ((1.0 - x) * 0.5));
138 if ((x <= 0.0) || (df < 1))
return (1.0);
142 even = (2 * (df / 2)) == df;
144 if (df > 1) y = gum__ex(-a);
149 x = 0.5 * (df - 1.0);
150 z = (even ? 1.0 : 0.5);
153 e = (even ? 0.0 : GUM_LOG_SQRT_PI);
158 s += gum__ex(c * z - a - e);
164 e = (even ? 1.0 : (GUM_I_SQRT_PI / std::sqrt(a)));
181 double minchisq = 0.0;
182 double maxchisq = GUM_CHI_MAX;
187 else if (proba >= 1.0)
190 chisqval = df / std::sqrt(proba);
192 while (maxchisq - minchisq > GUM_CHI_EPSILON) {
198 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).
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Represent the chi2 distribution.
static double probaChi2(double x, Size df)
Computes the probability of chi2 value.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.