aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
ITestPolicy.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_INTERFACE_TEST_POLICY_H
51#define GUM_MULTI_DIM_FUNCTION_GRAPH_INTERFACE_TEST_POLICY_H
52
53// ============================================================================
55// ============================================================================
57
58// ============================================================================
59
60namespace gum {
61
70 template < typename GUM_SCALAR >
72 public:
73 // ############################################################################
75 // ############################################################################
77
78 // ============================================================================
80 // ============================================================================
81 ITestPolicy() : _isModified_(false), _nbObs_(0) { GUM_CONSTRUCTOR(ITestPolicy); }
82
83 // ============================================================================
85 // ============================================================================
86 virtual ~ITestPolicy() {
87 GUM_DESTRUCTOR(ITestPolicy);
88 ;
89 }
90
91 // ============================================================================
93 // ============================================================================
94 void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
95
96 void operator delete(void* p) {
98 }
99
101
102
103 // ############################################################################
105 // ############################################################################
107
108 // ============================================================================
110 // ============================================================================
111 virtual void addObservation(Idx attr, GUM_SCALAR value) {
112 _isModified_ = true;
113 _nbObs_++;
114 }
115
116 // ============================================================================
118 // ============================================================================
119 Idx nbObservation() const { return _nbObs_; }
120
122
123
124 // ############################################################################
126 // ############################################################################
128
129 // ============================================================================
132 // ============================================================================
133 virtual bool isTestRelevant() const = 0;
134
135 // ============================================================================
137 // ============================================================================
138 virtual void computeScore() const { _isModified_ = false; }
139
140 // ============================================================================
142 // ============================================================================
143 virtual double score() const = 0;
144
145 // ============================================================================
147 // ============================================================================
148 virtual double secondaryscore() const = 0;
149
151
152
153 // ############################################################################
155 // ############################################################################
157
158 // ============================================================================
160 // ============================================================================
162 _isModified_ = true;
163 _nbObs_ += src.nbObservation();
164 }
165
167
168
169 // ############################################################################
171 // ############################################################################
173
174 // ============================================================================
176 // ============================================================================
177 std::string toString() const {
178 std::stringstream ss;
179 ss << "\t\t\tNb Obs : " << _nbObs_ << std::endl;
180 return ss.str();
181 }
182
184
185 protected:
186 bool isModified_() const { return _isModified_; }
187
188 private:
190 mutable bool _isModified_;
191
194 };
195
196} // End of namespace gum
197
198#endif /* GUM_MULTI_DIM_FUNCTION_GRAPH_INTERFACE_TEST_POLICY_H */
virtual double score() const =0
Returns the performance of current variable according to the test.
Idx nbObservation() const
Comptabilizes the new observation.
virtual void computeScore() const
Recomputes the statistic from the beginning.
bool isModified_() const
ITestPolicy()
Allocators and Deallocators redefinition.
Definition ITestPolicy.h:81
virtual bool isTestRelevant() const =0
Returns true if enough observation were added so that the test can be relevant.
bool _isModified_
Booleans indicating if we have to re eval test.
virtual void addObservation(Idx attr, GUM_SCALAR value)
Comptabilizes the new observation.
void add(const ITestPolicy< GUM_SCALAR > &src)
virtual double secondaryscore() const =0
Returns a second criterion to severe ties.
std::string toString() const
virtual ~ITestPolicy()
Allocators and Deallocators redefinition.
Definition ITestPolicy.h:86
static SmallObjectAllocator & instance()
void * allocate(const size_t &objectSize)
Allocates a block.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Size Idx
Type for indexes.
Definition types.h:79
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Base node set class for graphs.
Headers of gum::SmallObjectAllocator.