aGrUM  0.16.0
contingencyTable.h
Go to the documentation of this file.
1 
31 #ifndef GUM_CONTINGENCY_TABLE_H
32 #define GUM_CONTINGENCY_TABLE_H
33 
34 #include <agrum/core/math/math.h>
35 #include <agrum/core/hashTable.h>
36 #include <agrum/core/set.h>
38 
40 
42 
43 
44 namespace gum {
45 
56  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
58  public:
59  // ##########################################################################
61  // ##########################################################################
63 
64 
66 
68 
69 
71 
73 
74  // ============================================================================
76  // ============================================================================
77  void* operator new(size_t s) {
79  }
80  void operator delete(void* p) {
82  }
83 
85 
86 
88 
90 
91 
93 
94  void add(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB);
95 
96 
98 
99  Idx joint(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB) const {
100  return __jointTable.exists(
101  std::pair< GUM_SCALAR_A, GUM_SCALAR_B >(valueA, valueB))
102  ? __jointTable[std::pair< GUM_SCALAR_A, GUM_SCALAR_B >(valueA,
103  valueB)]
104  : 0;
105  }
106 
107 
109 
110  Idx attrAMarginal(GUM_SCALAR_A valueA) const {
111  return __attrAMarginalTable.exists(valueA) ? __attrAMarginalTable[valueA]
112  : 0;
113  }
114 
115 
117 
118  Idx attrBMarginal(GUM_SCALAR_B valueB) const {
119  return __attrAMarginalTable.exists(valueB) ? __attrAMarginalTable[valueB]
120  : 0;
121  }
122 
123 
125 
126  // Idx aMarginal( GUM_SCALAR_A iattr ) { return
127  // __attrMarginalTable[iattr]; }
130  }
133  }
134 
135 
137 
138  // Idx vMarginal( GUM_SCALAR_B ivalue ) { return
139  // __valueMarginalTable[ivalue]; }
142  }
145  }
146 
147 
149 
150  Idx attrASize() const { return __attrAMarginalTable.size(); }
151 
152 
154 
155  Idx attrBSize() const { return __attrBMarginalTable.size(); }
156 
158 
161 
162  std::string toString() const {
163  std::stringstream ss;
164  ss << "\t\t\t\t" << __attrAMarginalTable << std::endl
165  << "\t\t\t\t" << __attrBMarginalTable << std::endl
166  << "\t\t\t\t" << __jointTable << std::endl;
167  return ss.str();
168  }
169 
170  private:
183  };
184 
185 } /* namespace gum */
186 
188 #endif // GUM_CONTINGENCY_TABLE_H
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
HashTableConstIteratorSafe< GUM_SCALAR_B, Idx > attrBEndSafe() const
Increments the number of sample for case( iattr, ivalue )
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Idx attrBSize() const
Returns the number of samples for column ivalue.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
<agrum/FMDP/learning/core/contingencyTable.h>
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Size size() const noexcept
Returns the number of elements stored into the hashtable.
Idx attrAMarginal(GUM_SCALAR_A valueA) const
Returns the number of samples for case (iattr, ivalue)
const_iterator_safe cbeginSafe() const
Returns the safe const_iterator pointing to the beginning of the hashtable.
HashTable< GUM_SCALAR_B, Idx > __attrBMarginalTable
void add(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB)
Increments the number of sample for case( iattr, ivalue )
std::string toString() const
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< std::pair< GUM_SCALAR_A, GUM_SCALAR_B >, Idx > __jointTable
The contingency table used to compute the GStat Left Idx is for the attribute Right Idx for the value...
Idx joint(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB) const
Returns the number of samples for case (iattr, ivalue)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
~ContingencyTable()
Default destructor.
HashTableConstIteratorSafe< GUM_SCALAR_A, Idx > attrAEndSafe() const
Increments the number of sample for case( iattr, ivalue )
The class for generic Hash Tables.
Definition: hashTable.h:679
HashTableConstIteratorSafe< GUM_SCALAR_A, Idx > attrABeginSafe() const
Returns the number of samples for line iattr.
const const_iterator_safe & cendSafe() const noexcept
Returns the safe const_iterator pointing to the end of the hashtable.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
HashTable< GUM_SCALAR_A, Idx > __attrAMarginalTable
HashTableConstIteratorSafe< GUM_SCALAR_B, Idx > attrBBeginSafe() const
Returns the number of samples for column ivalue.
ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B > & operator+=(const ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B > &src)
Size Idx
Type for indexes.
Definition: types.h:53
void * allocate(const size_t &objectSize)
Allocates a block.
ContingencyTable()
Default constructor.
Idx attrASize() const
Returns the number of samples for line iattr.
static SmallObjectAllocator & instance()
Idx attrBMarginal(GUM_SCALAR_B valueB) const
Returns the number of samples for case (iattr, ivalue)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.