aGrUM  0.14.2
contingencyTable.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  ***************************************************************************/
28 #ifndef GUM_CONTINGENCY_TABLE_H
29 #define GUM_CONTINGENCY_TABLE_H
30 
31 #include <agrum/core/math/math.h>
32 #include <agrum/core/hashTable.h>
33 #include <agrum/core/set.h>
35 
37 
39 
40 
41 namespace gum {
42 
53  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
55  public:
56  // ##########################################################################
58  // ##########################################################################
60 
61 
63 
65 
66 
68 
70 
71  // ============================================================================
73  // ============================================================================
74  void* operator new(size_t s) {
76  }
77  void operator delete(void* p) {
79  }
80 
82 
83 
85 
87 
88 
90 
91  void add(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB);
92 
93 
95 
96  Idx joint(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB) const {
97  return __jointTable.exists(
98  std::pair< GUM_SCALAR_A, GUM_SCALAR_B >(valueA, valueB))
99  ? __jointTable[std::pair< GUM_SCALAR_A, GUM_SCALAR_B >(valueA,
100  valueB)]
101  : 0;
102  }
103 
104 
106 
107  Idx attrAMarginal(GUM_SCALAR_A valueA) const {
108  return __attrAMarginalTable.exists(valueA) ? __attrAMarginalTable[valueA]
109  : 0;
110  }
111 
112 
114 
115  Idx attrBMarginal(GUM_SCALAR_B valueB) const {
116  return __attrAMarginalTable.exists(valueB) ? __attrAMarginalTable[valueB]
117  : 0;
118  }
119 
120 
122 
123  // Idx aMarginal( GUM_SCALAR_A iattr ) { return
124  // __attrMarginalTable[iattr]; }
127  }
130  }
131 
132 
134 
135  // Idx vMarginal( GUM_SCALAR_B ivalue ) { return
136  // __valueMarginalTable[ivalue]; }
139  }
142  }
143 
144 
146 
147  Idx attrASize() const { return __attrAMarginalTable.size(); }
148 
149 
151 
152  Idx attrBSize() const { return __attrBMarginalTable.size(); }
153 
155 
158 
159  std::string toString() const {
160  std::stringstream ss;
161  ss << "\t\t\t\t" << __attrAMarginalTable << std::endl
162  << "\t\t\t\t" << __attrBMarginalTable << std::endl
163  << "\t\t\t\t" << __jointTable << std::endl;
164  return ss.str();
165  }
166 
167  private:
180  };
181 
182 } /* namespace gum */
183 
185 #endif // GUM_CONTINGENCY_TABLE_H
Useful macros for maths.
Headers of gum::SmallObjectAllocator.
HashTableConstIteratorSafe< GUM_SCALAR_B, Idx > attrBEndSafe() const
Increments the number of sample for case( iattr, ivalue )
Base class for discrete random variable.
Idx attrBSize() const
Returns the number of samples for column ivalue.
Sets of elements (i.e.
<agrum/FMDP/learning/core/contingencyTable.h>
Template implementations for the ContingencyTable class.
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)
gum is the global namespace for all aGrUM entities
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:676
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.
Headers of the Observation class.
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:50
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)
Class hash tables iterators.