aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B > Class Template Reference

<agrum/FMDP/learning/core/contingencyTable.h> More...

#include <contingencyTable.h>

Collaboration diagram for gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >:

Public Member Functions

ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B > & operator+= (const ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B > &src)
std::string toString () const
Constructor & destructor.
 ContingencyTable ()
 Default constructor.
 ~ContingencyTable ()
 Default destructor.
void * operator new (size_t s)
 Allocators and Deallocators redefinition.
void operator delete (void *p)
 Default constructor.
void add (GUM_SCALAR_A valueA, GUM_SCALAR_B valueB)
 Increments the number of sample for case( iattr, ivalue ).
Idx joint (GUM_SCALAR_A valueA, GUM_SCALAR_B valueB) const
 Returns the number of samples for case (iattr, ivalue).
Idx attrAMarginal (GUM_SCALAR_A valueA) const
 Returns the number of samples for case (iattr, ivalue).
Idx attrBMarginal (GUM_SCALAR_B valueB) const
 Returns the number of samples for case (iattr, ivalue).
HashTableConstIteratorSafe< GUM_SCALAR_A, IdxattrABeginSafe () const
 Returns the number of samples for line iattr.
HashTableConstIteratorSafe< GUM_SCALAR_A, IdxattrAEndSafe () const
 Increments the number of sample for case( iattr, ivalue ).
HashTableConstIteratorSafe< GUM_SCALAR_B, IdxattrBBeginSafe () const
 Returns the number of samples for column ivalue.
HashTableConstIteratorSafe< GUM_SCALAR_B, IdxattrBEndSafe () const
 Increments the number of sample for case( iattr, ivalue ).
Idx attrASize () const
 Returns the number of samples for line iattr.
Idx attrBSize () const
 Returns the number of samples for column ivalue.

Private Attributes

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.
HashTable< GUM_SCALAR_A, Idx_attrAMarginalTable_
HashTable< GUM_SCALAR_B, Idx_attrBMarginalTable_

Detailed Description

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
class gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >

<agrum/FMDP/learning/core/contingencyTable.h>

Definition at line 71 of file contingencyTable.h.

Constructor & Destructor Documentation

◆ ContingencyTable()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::ContingencyTable ( )

Default constructor.

Definition at line 65 of file contingencyTable_tpl.h.

65 {
67 }
<agrum/FMDP/learning/core/contingencyTable.h>
ContingencyTable()
Default constructor.

References ContingencyTable().

Referenced by ContingencyTable(), ~ContingencyTable(), operator delete(), and operator+=().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~ContingencyTable()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::~ContingencyTable ( )

Default destructor.

Definition at line 73 of file contingencyTable_tpl.h.

References ContingencyTable().

Here is the call graph for this function:

Member Function Documentation

◆ add()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
void gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::add ( GUM_SCALAR_A valueA,
GUM_SCALAR_B valueB )

Increments the number of sample for case( iattr, ivalue ).

Definition at line 85 of file contingencyTable_tpl.h.

86 {
87 // Updating
89 else _attrAMarginalTable_.insert(valueA, 1);
90
92 else _attrBMarginalTable_.insert(valueB, 1);
93
95 if (_jointTable_.exists(cell)) _jointTable_[cell]++;
96 else _jointTable_.insert(cell, 1);
97 }
HashTable< GUM_SCALAR_B, Idx > _attrBMarginalTable_
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...
HashTable< GUM_SCALAR_A, Idx > _attrAMarginalTable_

◆ attrABeginSafe()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
HashTableConstIteratorSafe< GUM_SCALAR_A, Idx > gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::attrABeginSafe ( ) const
inline

Returns the number of samples for line iattr.

Definition at line 133 of file contingencyTable.h.

133 {
134 return _attrAMarginalTable_.cbeginSafe();
135 }

References _attrAMarginalTable_.

Referenced by operator+=().

Here is the caller graph for this function:

◆ attrAEndSafe()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
HashTableConstIteratorSafe< GUM_SCALAR_A, Idx > gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::attrAEndSafe ( ) const
inline

Increments the number of sample for case( iattr, ivalue ).

Definition at line 137 of file contingencyTable.h.

137 {
138 return _attrAMarginalTable_.cendSafe();
139 }

References _attrAMarginalTable_.

Referenced by operator+=().

Here is the caller graph for this function:

◆ attrAMarginal()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
Idx gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::attrAMarginal ( GUM_SCALAR_A valueA) const
inline

Returns the number of samples for case (iattr, ivalue).

Definition at line 119 of file contingencyTable.h.

119 {
121 }

References _attrAMarginalTable_.

◆ attrASize()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
Idx gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::attrASize ( ) const
inline

Returns the number of samples for line iattr.

Definition at line 155 of file contingencyTable.h.

155{ return _attrAMarginalTable_.size(); }

References _attrAMarginalTable_.

◆ attrBBeginSafe()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
HashTableConstIteratorSafe< GUM_SCALAR_B, Idx > gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::attrBBeginSafe ( ) const
inline

Returns the number of samples for column ivalue.

Definition at line 145 of file contingencyTable.h.

145 {
146 return _attrBMarginalTable_.cbeginSafe();
147 }

References _attrBMarginalTable_.

◆ attrBEndSafe()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
HashTableConstIteratorSafe< GUM_SCALAR_B, Idx > gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::attrBEndSafe ( ) const
inline

Increments the number of sample for case( iattr, ivalue ).

Definition at line 149 of file contingencyTable.h.

149 {
150 return _attrBMarginalTable_.cendSafe();
151 }

References _attrBMarginalTable_.

◆ attrBMarginal()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
Idx gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::attrBMarginal ( GUM_SCALAR_B valueB) const
inline

Returns the number of samples for case (iattr, ivalue).

Definition at line 125 of file contingencyTable.h.

125 {
127 }

References _attrAMarginalTable_.

◆ attrBSize()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
Idx gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::attrBSize ( ) const
inline

Returns the number of samples for column ivalue.

Definition at line 159 of file contingencyTable.h.

159{ return _attrBMarginalTable_.size(); }

References _attrBMarginalTable_.

◆ joint()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
Idx gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::joint ( GUM_SCALAR_A valueA,
GUM_SCALAR_B valueB ) const
inline

Returns the number of samples for case (iattr, ivalue).

Definition at line 111 of file contingencyTable.h.

References _jointTable_.

Referenced by gum::ContingencyTable< Idx, GUM_SCALAR >::add().

Here is the caller graph for this function:

◆ operator delete()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
void gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::operator delete ( void * p)
inline

Default constructor.

Definition at line 93 of file contingencyTable.h.

93 {
95 }
static SmallObjectAllocator & instance()
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.

References ContingencyTable(), gum::SmallObjectAllocator::deallocate(), and gum::SmallObjectAllocator::instance().

Here is the call graph for this function:

◆ operator new()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
void * gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::operator new ( size_t s)
inline

Allocators and Deallocators redefinition.

Definition at line 91 of file contingencyTable.h.

void * allocate(const size_t &objectSize)
Allocates a block.

References gum::SmallObjectAllocator::allocate(), and gum::SmallObjectAllocator::instance().

Here is the call graph for this function:

◆ operator+=()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B > & gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::operator+= ( const ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B > & src)

Definition at line 101 of file contingencyTable_tpl.h.

102 {
103 // Ajout dans marginal A et table joint des valeurs pour src
104 for (auto aTer = src.attrABeginSafe(); aTer != src.attrAEndSafe(); ++aTer) {
105 if (_attrAMarginalTable_.exists(aTer.key())) _attrAMarginalTable_[aTer.key()] += aTer.val();
106 else _attrAMarginalTable_.insert(aTer.key(), aTer.val());
107
108 for (auto bTer = src.attrBBeginSafe(); bTer != src.attrBEndSafe(); ++bTer) {
110 if (_jointTable_.exists(cell)) _jointTable_[cell] += src.joint(aTer.key(), bTer.key());
111 else _jointTable_.insert(cell, src.joint(aTer.key(), bTer.key()));
112 }
113 }
114
115 // Ajout dans marginal B des valeurs de src
116 for (auto bTer = src.attrBBeginSafe(); bTer != src.attrBEndSafe(); ++bTer) {
117 if (_attrBMarginalTable_.exists(bTer.key())) _attrBMarginalTable_[bTer.key()] += bTer.val();
118 else _attrBMarginalTable_.insert(bTer.key(), bTer.val());
119 }
120 return *this;
121 }
HashTableConstIteratorSafe< GUM_SCALAR_B, Idx > attrBEndSafe() 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.
HashTableConstIteratorSafe< GUM_SCALAR_A, Idx > attrAEndSafe() const
Increments the number of sample for case( iattr, ivalue ).
Idx joint(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB) const
Returns the number of samples for case (iattr, ivalue).
HashTableConstIteratorSafe< GUM_SCALAR_B, Idx > attrBBeginSafe() const
Returns the number of samples for column ivalue.

References ContingencyTable(), _attrAMarginalTable_, attrABeginSafe(), and attrAEndSafe().

Here is the call graph for this function:

◆ toString()

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
std::string gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::toString ( ) const
inline

Definition at line 166 of file contingencyTable.h.

166 {
168 ss << "\t\t\t\t" << _attrAMarginalTable_ << std::endl
169 << "\t\t\t\t" << _attrBMarginalTable_ << std::endl
170 << "\t\t\t\t" << _jointTable_ << std::endl;
171 return ss.str();
172 }

References _attrAMarginalTable_, _attrBMarginalTable_, and _jointTable_.

Member Data Documentation

◆ _attrAMarginalTable_

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
HashTable< GUM_SCALAR_A, Idx > gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::_attrAMarginalTable_
private

◆ _attrBMarginalTable_

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
HashTable< GUM_SCALAR_B, Idx > gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::_attrBMarginalTable_
private

Definition at line 186 of file contingencyTable.h.

Referenced by attrBBeginSafe(), attrBEndSafe(), attrBSize(), and toString().

◆ _jointTable_

template<typename GUM_SCALAR_A, typename GUM_SCALAR_B>
HashTable< std::pair< GUM_SCALAR_A, GUM_SCALAR_B >, Idx > gum::ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B >::_jointTable_
private

The contingency table used to compute the GStat Left Idx is for the attribute Right Idx for the value.

NB: This is a silly and in a hurry implementation of contingency table If someone ever use this class and has time to correctly implements a efficient contingency table, you're welcome

Definition at line 184 of file contingencyTable.h.

Referenced by joint(), and toString().


The documentation for this class was generated from the following files: