aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
nodeDatabase.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
48
49// =========================================================================
50#ifndef GUM_NODE_DATABASE_H
51#define GUM_NODE_DATABASE_H
52// =========================================================================
54// =========================================================================
59
60// =========================================================================
61// =========================================================================
62
63namespace gum {
64
72
73
74 template < TESTNAME AttributeSelection, bool isScalar >
77
78 template < typename GUM_SCALAR >
79 using TestPolicy = typename TestSelect< AttributeSelection,
83
84 public:
85 // ==========================================================================
87 // ==========================================================================
89
90 // ###################################################################
92 // ###################################################################
93 NodeDatabase(const gum::VariableSet*, const DiscreteVariable* = nullptr);
94
95 // ###################################################################
97 // ###################################################################
99
100 // ============================================================================
102 // ============================================================================
103 void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
104
105 void operator delete(void* p) {
107 }
108
110
111 // ==========================================================================
113 // ==========================================================================
115
116 // ###################################################################
123 // ###################################################################
124 void addObservation(const Observation*);
125
126 private:
129
130 public:
131 // ###################################################################
133 // ###################################################################
134 INLINE Idx nbObservation() const { return _nbObservation_; }
135
137
138 // ==========================================================================
140 // ==========================================================================
142
143 // ###################################################################
146 // ###################################################################
147 INLINE bool isTestRelevant(const DiscreteVariable* var) const {
148 return _attrTable_[var]->isTestRelevant();
149 }
150
151 // ###################################################################
154 // ###################################################################
155 INLINE double testValue(const DiscreteVariable* var) const { return _attrTable_[var]->score(); }
156
157 // ###################################################################
160 // ###################################################################
161 INLINE double testOtherCriterion(const DiscreteVariable* var) const {
162 return _attrTable_[var]->secondaryscore();
163 }
164
166
167 // ==========================================================================
169 // ==========================================================================
171
172 // ###################################################################
174 // ###################################################################
177
178 // ###################################################################
181 // ###################################################################
183 return _attrTable_[var];
184 }
185
186 // ###################################################################
188 // ###################################################################
190 return _valueCount_.cbeginSafe();
191 }
192
194 return _valueCount_.cendSafe();
195 }
196
198
199 // ###################################################################
201 // ###################################################################
202
203 Idx effectif(Idx moda) const {
204 return _valueCount_.exists(ValueType(moda)) ? _valueCount_[ValueType(moda)] : 0;
205 }
206
208
209 private:
211
212 Idx _valueDomain_(Int2Type< false >) const { return _value_->domainSize(); }
213
214 std::string toString() const;
215
216 private:
219
222
225
228 };
229
230
231} /* namespace gum */
232
234
235#endif // GUM_NODE_DATABASE_H
Headers of the Chi2TestPolicy.
Headers of the GTestPolicy.
<agrum/base/multidim/core/testPolicy/Chi2TestPolicy.h>
Base class for discrete random variable.
<agrum/base/multidim/core/testPolicies/GTestPolicy.h>
Definition GTestPolicy.h:74
The class for generic Hash Tables.
Definition hashTable.h:637
<agrum/base/multidim/core/testPolicy/leastSquareTestPolicy.h>
<agrum/FMDP/learning/datastructure/nodeDatabase.h>
const TestPolicy< ValueType > * testPolicy(const DiscreteVariable *var) const
Returns a reference to nDB test policy for given variable (so that test policy information can be mer...
NodeDatabase(const gum::VariableSet *, const DiscreteVariable *=nullptr)
Default constructor.
~NodeDatabase()
Default destructor.
Idx _valueDomain_(Int2Type< false >) const
typename ValueSelect< isScalar, double, Idx >::type ValueType
INLINE Idx nbObservation() const
Nb observation taken into account by this instance.
const DiscreteVariable * _value_
So does this reference on the value observed.
INLINE double testValue(const DiscreteVariable *var) const
Returns the performance of given variables according to selection criterion.
Idx valueDomain() const
Idx effectif(Idx moda) const
Idx _valueDomain_(Int2Type< true >) const
void _addObservation_(const Observation *, Int2Type< true >)
Updates database with new observation.
typename TestSelect< AttributeSelection, GTestPolicy< GUM_SCALAR >, Chi2TestPolicy< GUM_SCALAR >, LeastSquareTestPolicy< GUM_SCALAR > >::type TestPolicy
std::string toString() const
INLINE double testOtherCriterion(const DiscreteVariable *var) const
Returns the performance of given variables according to selection secondary criterion (to break ties)...
INLINE bool isTestRelevant(const DiscreteVariable *var) const
Indicates wether or not, node has sufficient observation so that any statistic is relevant.
const HashTableConstIteratorSafe< ValueType, Idx > cendValues() const
Merges given NodeDatabase informations into current nDB.
const HashTableConstIteratorSafe< ValueType, Idx > cbeginValues() const
Iterators on value count to recopy correctly its content.
HashTable< ValueType, Idx > _valueCount_
NodeDatabase< AttributeSelection, isScalar > & operator+=(const NodeDatabase< AttributeSelection, isScalar > &src)
Merges given NodeDatabase informations into current nDB.
HashTable< const DiscreteVariable *, TestPolicy< ValueType > * > _attrTable_
Table giving for every variables its instantiation.
void addObservation(const Observation *)
Nb observation taken into account by this instance.
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
Headers of the LeastSquareTestPolicy.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
Template implémentations of the NodeDatabase class.
Header file of gum::Sequence, a class for storing (ordered) sequences of objects.
Template trick for efficient development.