aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
chiSquare.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Headers of the ChiSquare class.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  */
29 
30 
31 #ifndef GUM_CHI_SQUARE_H
32 # define GUM_CHI_SQUARE_H
33 
34 # include <agrum/tools/core/math/math_utils.h>
35 # include <agrum/tools/core/hashTable.h>
36 
37 
38 namespace gum {
39 
40  /**
41  * @class ChiSquare chiSquare.h
42  * <agrum/FMDP/learning/core/testPolicy/chiSquare.h>
43  * @brief
44  * @ingroup fmdp_group
45  *
46  */
47 
48  class ChiSquare {
49  public:
50  static double probaChi2(double x, Size df);
51 
52  private:
53  /// Required constant to compute the cdf
54  /// @{
55 
56  /// maximum meaningful z value
57  static constexpr double _Z_MAX_ = 6.0;
58 
59  /// accuracy of critchi approximation
60  static constexpr double _CHI_EPSILON_ = 0.000001;
61 
62  /// maximum chi square value
63  static constexpr double _CHI_MAX_ = 99999.0;
64 
65  /// log (sqrt (pi))
66  static constexpr double _LOG_SQRT_PI_ = 0.5723649429247000870717135;
67 
68  /// 1 / sqrt (pi)
69  static constexpr double _I_SQRT_PI_ = 0.5641895835477562869480795;
70 
71  /// max value to represent exp (x)
72  static constexpr double _BIGX_ = 20.0;
73 
74  /// @}
75 
76 
77  /// Required constant to compute the cdf
78  /// @{
79 
80  static double _exp_(double x) { return (((x) < -_BIGX_) ? 0.0 : exp(x)); }
81 
82  static double _probaZValue_(double z);
83  /// @}
84  };
85 
86 } /* namespace gum */
87 
88 #endif // GUM_CHI_SQUARE_H
89 
90 
91 // static HashTable<std::pair<double, unsigned long>, double> _chi2Cache_;
92 // static HashTable<double, double> _ZCache_;
93 // static Idx nbZ;
94 // static Idx nbChi;
95 // static Idx nbZt;
96 // static Idx nbChit;
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
static constexpr double _CHI_EPSILON_
accuracy of critchi approximation
Definition: chiSquare.h:60
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 _Z_MAX_
Required constant to compute the cdf.
Definition: chiSquare.h:57
static constexpr double _I_SQRT_PI_
1 / sqrt (pi)
Definition: chiSquare.h:69
static constexpr double _CHI_MAX_
maximum chi square value
Definition: chiSquare.h:63
static constexpr double _BIGX_
max value to represent exp (x)
Definition: chiSquare.h:72
static double probaChi2(double x, Size df)
computes the probability of chi2 value (used by the cache)
Definition: chiSquare.cpp:114
static double _probaZValue_(double z)
computes the probability of normal z value (used by the cache)
Definition: chiSquare.cpp:42
<agrum/FMDP/learning/core/testPolicy/chiSquare.h>
Definition: chiSquare.h:48