aGrUM  0.14.2
nodeDatabase.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 // =========================================================================
28 #ifndef GUM_NODE_DATABASE_H
29 #define GUM_NODE_DATABASE_H
30 // =========================================================================
31 #include <agrum/core/hashTable.h>
32 #include <agrum/core/sequence.h>
33 // =========================================================================
39 // =========================================================================
41 // =========================================================================
42 
43 namespace gum {
44 
54  template < TESTNAME AttributeSelection, bool isScalar >
55  class NodeDatabase {
57 
58  template < typename GUM_SCALAR >
59  using TestPolicy =
60  typename TestSelect< AttributeSelection,
64 
65  public:
66  // ==========================================================================
68  // ==========================================================================
70 
71  // ###################################################################
73  // ###################################################################
75  const DiscreteVariable* = nullptr);
76 
77  // ###################################################################
79  // ###################################################################
80  ~NodeDatabase();
81 
82  // ============================================================================
84  // ============================================================================
85  void* operator new(size_t s) {
87  }
88  void operator delete(void* p) {
90  }
91 
93 
94  // ==========================================================================
96  // ==========================================================================
98 
99  // ###################################################################
106  // ###################################################################
107  void addObservation(const Observation*);
108 
109  private:
112 
113  public:
114  // ###################################################################
116  // ###################################################################
117  INLINE Idx nbObservation() const { return __nbObservation; }
118 
120 
121  // ==========================================================================
123  // ==========================================================================
125 
126  // ###################################################################
129  // ###################################################################
130  INLINE bool isTestRelevant(const DiscreteVariable* var) const {
131  return __attrTable[var]->isTestRelevant();
132  }
133 
134  // ###################################################################
137  // ###################################################################
138  INLINE double testValue(const DiscreteVariable* var) const {
139  return __attrTable[var]->score();
140  }
141 
142  // ###################################################################
145  // ###################################################################
146  INLINE double testOtherCriterion(const DiscreteVariable* var) const {
147  return __attrTable[var]->secondaryscore();
148  }
149 
151 
152  // ==========================================================================
154  // ==========================================================================
156 
157  // ###################################################################
159  // ###################################################################
162 
163  // ###################################################################
166  // ###################################################################
168  return __attrTable[var];
169  }
170 
171  // ###################################################################
173  // ###################################################################
175  return __valueCount.cbeginSafe();
176  }
178  return __valueCount.cendSafe();
179  }
180 
182 
183  // ###################################################################
185  // ###################################################################
186 
187  Idx effectif(Idx moda) const {
188  return __valueCount.exists(ValueType(moda)) ? __valueCount[ValueType(moda)]
189  : 0;
190  }
191 
193 
194  private:
195  Idx __valueDomain(Int2Type< true >) const { return __valueCount.size(); }
197 
198  std::string toString() const;
199 
200  private:
203 
206 
209 
212  };
213 
214 
215 } /* namespace gum */
216 
218 
219 #endif // GUM_NODE_DATABASE_H
Template trick for efficient development.
Idx __valueDomain(Int2Type< false >) const
Definition: nodeDatabase.h:196
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...
Definition: nodeDatabase.h:167
const DiscreteVariable * __value
So does this reference on the value observed.
Definition: nodeDatabase.h:205
Base class for discrete random variable.
Header file of gum::Sequence, a class for storing (ordered) sequences of objects. ...
HashTable< ValueType, Idx > __valueCount
Definition: nodeDatabase.h:211
const HashTableConstIteratorSafe< ValueType, Idx > cendValues() const
Merges given NodeDatabase informations into current nDB.
Definition: nodeDatabase.h:177
Safe Const Iterators for hashtables.
Definition: hashTable.h:1915
Idx valueDomain() const
Definition: nodeDatabase.h:192
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
Definition: nodeDatabase.h:63
Idx __valueDomain(Int2Type< true >) const
Definition: nodeDatabase.h:195
NodeDatabase(const Set< const DiscreteVariable * > *, const DiscreteVariable *=nullptr)
Default constructor.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
INLINE bool isTestRelevant(const DiscreteVariable *var) const
Indicates wether or not, node has sufficient observation so that any statistic is relevant...
Definition: nodeDatabase.h:130
<agrum/multidim/core/testPolicy/Chi2TestPolicy.h>
<agrum/multidim/core/testPolicy/leastSquareTestPolicy.h>
INLINE double testOtherCriterion(const DiscreteVariable *var) const
Returns the performance of given variables according to selection secondary criterion (to break ties)...
Definition: nodeDatabase.h:146
The class for generic Hash Tables.
Definition: hashTable.h:676
Headers of the GTestPolicy.
Headers of the Chi2TestPolicy.
Representation of a setA Set is a structure that contains arbitrary elements.
Definition: set.h:162
virtual Size domainSize() const =0
std::string toString() const
void addObservation(const Observation *)
Nb observation taken into account by this instance.
INLINE double testValue(const DiscreteVariable *var) const
Returns the performance of given variables according to selection criterion.
Definition: nodeDatabase.h:138
<agrum/multidim/core/testPolicies/GTestPolicy.h>
Definition: GTestPolicy.h:50
Headers of the Observation class.
const HashTableConstIteratorSafe< ValueType, Idx > cbeginValues() const
Iterators on value count to recopy correctly its content.
Definition: nodeDatabase.h:174
ValueSelect< isScalar, double, Idx >::type ValueType
Definition: nodeDatabase.h:56
NodeDatabase< AttributeSelection, isScalar > & operator+=(const NodeDatabase< AttributeSelection, isScalar > &src)
Merges given NodeDatabase informations into current nDB.
Template implémentations of the NodeDatabase class.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Headers of the LeastSquareTestPolicy.
Size Idx
Type for indexes.
Definition: types.h:50
void * allocate(const size_t &objectSize)
Allocates a block.
INLINE Idx nbObservation() const
Nb observation taken into account by this instance.
Definition: nodeDatabase.h:117
Idx effectif(Idx moda) const
Definition: nodeDatabase.h:187
static SmallObjectAllocator & instance()
~NodeDatabase()
Default destructor.
Class hash tables iterators.
<agrum/FMDP/learning/datastructure/nodeDatabase.h>
Definition: nodeDatabase.h:55
HashTable< const DiscreteVariable *, TestPolicy< ValueType > *> __attrTable
Table giving for every variables its instantiation.
Definition: nodeDatabase.h:202