31 #ifndef GUM_CONTINGENCY_TABLE_H 32 #define GUM_CONTINGENCY_TABLE_H 34 #include <agrum/tools/core/math/math_utils.h> 35 #include <agrum/tools/core/hashTable.h> 36 #include <agrum/tools/core/set.h> 37 #include <agrum/tools/core/smallobjectallocator/smallObjectAllocator.h> 39 #include <agrum/FMDP/learning/observation.h> 41 #include <agrum/tools/variables/discreteVariable.h> 56 template <
typename GUM_SCALAR_A,
typename GUM_SCALAR_B >
77 void*
operator new(size_t s) {
return SmallObjectAllocator::instance().allocate(s); }
79 SmallObjectAllocator::instance().deallocate(p,
sizeof(ContingencyTable));
92 void add(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB);
98 return _jointTable_.exists(std::pair< GUM_SCALAR_A, GUM_SCALAR_B >(valueA, valueB))
99 ? _jointTable_[std::pair< GUM_SCALAR_A, GUM_SCALAR_B >(valueA, valueB)]
107 return _attrAMarginalTable_.exists(valueA) ? _attrAMarginalTable_[valueA] : 0;
114 return _attrAMarginalTable_.exists(valueB) ? _attrAMarginalTable_[valueB] : 0;
123 return _attrAMarginalTable_.cbeginSafe();
126 return _attrAMarginalTable_.cendSafe();
135 return _attrBMarginalTable_.cbeginSafe();
138 return _attrBMarginalTable_.cendSafe();
157 std::stringstream ss;
158 ss <<
"\t\t\t\t" << _attrAMarginalTable_ << std::endl
159 <<
"\t\t\t\t" << _attrBMarginalTable_ << std::endl
160 <<
"\t\t\t\t" << _jointTable_ << std::endl;
181 #include <agrum/FMDP/learning/core/contingencyTable_tpl.h> HashTable< GUM_SCALAR_B, Idx > _attrBMarginalTable_
HashTableConstIteratorSafe< GUM_SCALAR_B, Idx > attrBEndSafe() const
Increments the number of sample for case( iattr, ivalue )
Idx attrBSize() const
Returns the number of samples for column ivalue.
Idx attrAMarginal(GUM_SCALAR_A valueA) const
Returns the number of samples for case (iattr, ivalue)
INLINE void emplace(Args &&... args)
void add(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB)
Increments the number of sample for case( iattr, ivalue )
std::string toString() const
Idx joint(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB) const
Returns the number of samples for case (iattr, ivalue)
~ContingencyTable()
Default destructor.
HashTableConstIteratorSafe< GUM_SCALAR_A, Idx > attrAEndSafe() const
Increments the number of sample for case( iattr, ivalue )
HashTableConstIteratorSafe< GUM_SCALAR_A, Idx > attrABeginSafe() const
Returns the number of samples for line iattr.
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...
void * operator new(size_t s)
Allocators and Deallocators redefinition.
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)
ContingencyTable()
Default constructor.
Idx attrASize() const
Returns the number of samples for line iattr.
HashTable< GUM_SCALAR_A, Idx > _attrAMarginalTable_
Idx attrBMarginal(GUM_SCALAR_B valueB) const
Returns the number of samples for case (iattr, ivalue)
void operator delete(void *p)
Default constructor.