aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
GTestPolicy.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
50#ifndef GUM_MULTI_DIM_FUNCTION_GRAPH_G_TEST_POLICY_H
51#define GUM_MULTI_DIM_FUNCTION_GRAPH_G_TEST_POLICY_H
52// ============================================================================
57
58// ============================================================================
59
60namespace gum {
61
62 // template <typename GUM_SCALAR>
63 // using ConTab = ContingencyTable<Idx, GUM_SCALAR>;
64
73 template < typename GUM_SCALAR >
74 class GTestPolicy final: public ITestPolicy< GUM_SCALAR > {
75 public:
76 // ############################################################################
78 // ############################################################################
80
81 // ============================================================================
83 // ============================================================================
84 GTestPolicy() : ITestPolicy< GUM_SCALAR >(), _conTab_(), _GStat_(0) {
85 GUM_CONSTRUCTOR(GTestPolicy);
86 }
87
88 // ============================================================================
90 // ============================================================================
91 virtual ~GTestPolicy() {
92 GUM_DESTRUCTOR(GTestPolicy);
93 ;
94 }
95
96 // ============================================================================
98 // ============================================================================
99 void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
100
101 void operator delete(void* p) {
103 }
104
106
107 // ############################################################################
109 // ############################################################################
111
112 // ============================================================================
114 // ============================================================================
115 void addObservation(Idx iattr, GUM_SCALAR ivalue);
116
118
119
120 // ############################################################################
122 // ############################################################################
124
125 // ============================================================================
128 // ============================================================================
129 bool isTestRelevant() const {
130 return (this->nbObservation() > 20 && this->nbObservation() > _conTab_.attrASize() * 5);
131 }
132
133 // ============================================================================
135 // ============================================================================
136 void computeScore() const;
137
138 // ============================================================================
140 // ============================================================================
141 double score() const;
142
143 // ============================================================================
145 // ============================================================================
146 double secondaryscore() const;
147
148
150
151
152 // ############################################################################
154 // ############################################################################
156
157 // ============================================================================
159 // ============================================================================
160 void add(const GTestPolicy< GUM_SCALAR >& src);
161
162 // ============================================================================
165 // ============================================================================
167
169
170
171 // ############################################################################
173 // ############################################################################
175
176 std::string toString() const {
177 std::stringstream ss;
178 ss << ITestPolicy< GUM_SCALAR >::toString() << "\t\t\tContingency Table : " << std::endl
179 << _conTab_.toString() << std::endl
180 << "\t\t\tGStat : " << _GStat_ << std::endl
181 << "\t\t\tGStat : " << this->secondaryscore() << std::endl;
182 return ss.str();
183 }
184
186
187 private:
190 mutable double _GStat_;
191 };
192
193} // End of namespace gum
194
196
197#endif /* GUM_MULTI_DIM_FUNCTION_GRAPH_G_TEST_POLICY_H */
Template implementations for the GTestPolicy class.
Headers of the ITestPolicy.
Headers of the ChiSquare class.
<agrum/base/multidim/core/testPolicies/GTestPolicy.h>
Definition GTestPolicy.h:74
GTestPolicy()
Constructor.
Definition GTestPolicy.h:84
virtual ~GTestPolicy()
Destructor.
Definition GTestPolicy.h:91
const ContingencyTable< Idx, GUM_SCALAR > & ct() const
Returns contingency table (needed for the merging of GTestPolicy instances).
std::string toString() const
double secondaryscore() const
Returns a second criterion to severe ties.
void addObservation(Idx iattr, GUM_SCALAR ivalue)
Comptabilizes the new observation.
double score() const
Returns the performance of current variable according to the test.
void add(const GTestPolicy< GUM_SCALAR > &src)
Performs the merging of current GTestPolicy instance with given instance.
void computeScore() const
Computes the GStat of current variable according to the test.
ContingencyTable< Idx, GUM_SCALAR > _conTab_
The contingency table used to keeps records of all observation.
bool isTestRelevant() const
Returns true if enough observation were made so that the test can be relevant.
Idx nbObservation() const
Comptabilizes the new observation.
ITestPolicy()
Allocators and Deallocators redefinition.
Definition ITestPolicy.h:81
static SmallObjectAllocator & instance()
void * allocate(const size_t &objectSize)
Allocates a block.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Headers of the ContingencyTable class.
Size Idx
Type for indexes.
Definition types.h:79
gum is the global namespace for all aGrUM entities
Definition agrum.h:46