aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
chi2.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
51
52#ifndef GUM_LEARNING_CHI2_H
53#define GUM_LEARNING_CHI2_H
54
55#include <agrum/agrum.h>
56
58
60
61#define GUM_LEARNING_CONFIDENCE_PROBA 0.05
62
63namespace gum {
64
65 // =========================================================================
66 // === CHI2 CLASS ===
67 // =========================================================================
68
79 class Chi2 {
80 public:
81 // ==========================================================================
83 // ==========================================================================
85
91 Chi2(const std::vector< std::size_t >& var_modalities,
92 double confidence_proba = GUM_LEARNING_CONFIDENCE_PROBA);
93
97 ~Chi2();
98
100 // ==========================================================================
102 // ==========================================================================
104
111 void setConditioningNodes(const std::vector< Idx >& db_conditioning_ids);
112
119 double criticalValue(const std::pair< Idx, Idx >& pair);
120
128 double criticalValue(Idx var1, Idx var2);
129
135 Size degreesOfFreedom(const std::pair< Idx, Idx >& pair);
136
143 Size degreesOfFreedom(Idx var1, Idx var2);
144
149 void setConfidenceProba(double new_proba);
150
167
168 static double probaChi2(double x, Size df);
170
171 private:
173 const std::vector< std::size_t >& _modalities_;
174
177
180
183
194 static double _criticalValue_(double proba, Size df);
195
196
212 static double _probaZValue_(double z);
213
215 Chi2(const Chi2&) = delete;
216
218 Chi2& operator=(const Chi2&) = delete;
219 };
220
221} /* namespace gum */
222
224#ifndef GUM_NO_INLINE
226#endif /* GUM_NO_INLINE */
227
228#endif /* GUM_LEARNING_CHI2_H */
#define GUM_LEARNING_CONFIDENCE_PROBA
Definition chi2.h:61
The class that represents the chi2 distribution.
Chi2 & operator=(const Chi2 &)=delete
Forbid used of the copy operator.
double _confidence_proba_
The confidence probability used for critical values.
Definition chi2.h:176
Size _conditioning_size_
The domain size of the conditioning nodes.
Definition chi2.h:179
double criticalValue(const std::pair< Idx, Idx > &pair)
Computes the critical value according to the number of degrees of freedom.
Definition chi2_inl.h:74
HashTable< Idx, double > _critical_values_
A set of already computed critical values.
Definition chi2.h:182
Chi2(const Chi2 &)=delete
Forbid use of the copy constructor.
void setConfidenceProba(double new_proba)
Modifies the confidence probability.
Definition chi2_inl.h:95
const std::vector< std::size_t > & _modalities_
The modalities of the random variables.
Definition chi2.h:173
~Chi2()
Class destructor.
Definition chi2.cpp:83
void setConditioningNodes(const std::vector< Idx > &db_conditioning_ids)
Sets the conditioning nodes (useful for computing degrees of freedom).
Definition chi2_inl.h:56
static double _probaZValue_(double z)
Computes the probability of normal z value.
Definition chi2.cpp:89
Size degreesOfFreedom(const std::pair< Idx, Idx > &pair)
Returns the number of degrees of freedom.
Definition chi2_inl.h:64
static double _criticalValue_(double proba, Size df)
Computes the critical value of a given chi2 test (used by the cache).
Definition chi2.cpp:190
Chi2(const std::vector< std::size_t > &var_modalities, double confidence_proba=GUM_LEARNING_CONFIDENCE_PROBA)
Default constructor.
Definition chi2.cpp:76
static double probaChi2(double x, Size df)
Computes the probability of chi2 value.
Definition chi2.cpp:144
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Class hash tables iterators.
Useful macros for maths.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46