aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
Chi2TestPolicy.h
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 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-2026 *
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
50
#ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_CHI2_TEST_POLICY_H
51
#define GUM_MULTI_DIM_FUNCTION_GRAPH_CHI2_TEST_POLICY_H
52
53
// ============================================================================
54
#include <
agrum/FMDP/learning/core/chiSquare.h
>
55
#include <
agrum/FMDP/learning/core/contingencyTable.h
>
56
#include <
agrum/FMDP/learning/core/testPolicy/ITestPolicy.h
>
57
58
// ============================================================================
59
60
namespace
gum
{
61
71
template
<
typename
GUM_ELEMENT >
72
class
Chi2TestPolicy
:
public
ITestPolicy
< GUM_ELEMENT > {
73
public
:
74
Chi2TestPolicy
();
75
76
~Chi2TestPolicy
()
override
;
77
78
// ============================================================================
80
// ============================================================================
81
void
*
operator
new
(
size_t
s);
82
83
void
operator
delete
(
void
* p);
84
85
// ############################################################################
87
// ############################################################################
89
90
// ============================================================================
92
// ============================================================================
93
void
addObservation
(
Idx
attr, GUM_ELEMENT value)
override
;
94
96
97
98
// ############################################################################
100
// ############################################################################
102
103
// ============================================================================
106
// ============================================================================
107
bool
isTestRelevant
()
const override
;
108
110
111
112
// ############################################################################
114
// ############################################################################
116
117
// ============================================================================
119
// ============================================================================
120
void
computeScore
()
const override
;
121
122
// ============================================================================
124
// ============================================================================
125
double
score
()
const override
;
126
127
// ============================================================================
129
// ============================================================================
130
double
secondaryscore
()
const override
;
131
133
134
const
ContingencyTable< Idx, GUM_ELEMENT >
&
ct
()
const
;
135
136
void
add
(
const
Chi2TestPolicy< GUM_ELEMENT >
& src);
137
138
std::string
toString
()
const
;
139
140
private
:
142
ContingencyTable< Idx, GUM_ELEMENT >
_conTab_
;
143
144
mutable
double
_chi2Score_
;
145
};
146
147
}
// End of namespace gum
148
149
#include <
agrum/FMDP/learning/core/testPolicy/Chi2TestPolicy_tpl.h
>
150
151
#endif
/* GUM_MULTI_DIM_FUNCTION_GRAPH_CHI2_TEST_POLICY_H */
Chi2TestPolicy_tpl.h
Template implementations for the Chi2TestPolicy class.
ITestPolicy.h
Headers of the ITestPolicy.
chiSquare.h
Headers of the ChiSquare class.
gum::Chi2TestPolicy::add
void add(const Chi2TestPolicy< GUM_ELEMENT > &src)
Definition
Chi2TestPolicy_tpl.h:119
gum::Chi2TestPolicy::addObservation
void addObservation(Idx attr, GUM_ELEMENT value) override
Comptabilizes the new observation.
Definition
Chi2TestPolicy_tpl.h:67
gum::Chi2TestPolicy::toString
std::string toString() const
Definition
Chi2TestPolicy_tpl.h:157
gum::Chi2TestPolicy::isTestRelevant
bool isTestRelevant() const override
Returns true if enough observation were made so that the test can be relevant.
Definition
Chi2TestPolicy_tpl.h:147
gum::Chi2TestPolicy::computeScore
void computeScore() const override
Recomputes the statistic from the beginning.
Definition
Chi2TestPolicy_tpl.h:80
gum::Chi2TestPolicy::_chi2Score_
double _chi2Score_
Definition
Chi2TestPolicy.h:144
gum::Chi2TestPolicy::_conTab_
ContingencyTable< Idx, GUM_ELEMENT > _conTab_
The contingency table used to keeps records of all observation.
Definition
Chi2TestPolicy.h:142
gum::Chi2TestPolicy::secondaryscore
double secondaryscore() const override
Returns a second criterion to severe ties.
Definition
Chi2TestPolicy_tpl.h:113
gum::Chi2TestPolicy::ct
const ContingencyTable< Idx, GUM_ELEMENT > & ct() const
Definition
Chi2TestPolicy_tpl.h:152
gum::Chi2TestPolicy::Chi2TestPolicy
Chi2TestPolicy()
Definition
Chi2TestPolicy_tpl.h:125
gum::Chi2TestPolicy::score
double score() const override
Returns the performance of current variable according to the test.
Definition
Chi2TestPolicy_tpl.h:101
gum::ContingencyTable< Idx, GUM_ELEMENT >
gum::ITestPolicy::ITestPolicy
ITestPolicy()
Allocators and Deallocators redefinition.
Definition
ITestPolicy_tpl.h:49
contingencyTable.h
Headers of the ContingencyTable class.
gum::Idx
Size Idx
Type for indexes.
Definition
types.h:79
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0