aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B > Class Template Reference

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

#include <contingencyTable.h>

Collaboration diagram for gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >:

Public Member Functions

ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B > & operator+= (const ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_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_ELEMENT_A valueA, GUM_ELEMENT_B valueB)
 Increments the number of sample for case( iattr, ivalue ).
Idx joint (GUM_ELEMENT_A valueA, GUM_ELEMENT_B valueB) const
 Returns the number of samples for case (iattr, ivalue).
Idx attrAMarginal (GUM_ELEMENT_A valueA) const
 Returns the number of samples for case (iattr, ivalue).
Idx attrBMarginal (GUM_ELEMENT_B valueB) const
 Returns the number of samples for case (iattr, ivalue).
HashTableConstIteratorSafe< GUM_ELEMENT_A, IdxattrABeginSafe () const
 Returns the number of samples for line iattr.
HashTableConstIteratorSafe< GUM_ELEMENT_A, IdxattrAEndSafe () const
 Increments the number of sample for case( iattr, ivalue ).
HashTableConstIteratorSafe< GUM_ELEMENT_B, IdxattrBBeginSafe () const
 Returns the number of samples for column ivalue.
HashTableConstIteratorSafe< GUM_ELEMENT_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_ELEMENT_A, GUM_ELEMENT_B >, Idx_jointTable_
 The contingency table used to compute the GStat Left Idx is for the attribute Right Idx for the value.
HashTable< GUM_ELEMENT_A, Idx_attrAMarginalTable_
HashTable< GUM_ELEMENT_B, Idx_attrBMarginalTable_

Detailed Description

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
class gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >

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

Definition at line 71 of file contingencyTable.h.

Constructor & Destructor Documentation

◆ ContingencyTable()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::ContingencyTable ( )

Default constructor.

Definition at line 66 of file contingencyTable_tpl.h.

66 {
68 }
<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_ELEMENT_A, typename GUM_ELEMENT_B>
gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::~ContingencyTable ( )

Default destructor.

Definition at line 74 of file contingencyTable_tpl.h.

References ContingencyTable().

Here is the call graph for this function:

Member Function Documentation

◆ add()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
void gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::add ( GUM_ELEMENT_A valueA,
GUM_ELEMENT_B valueB )

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

Definition at line 86 of file contingencyTable_tpl.h.

87 {
88 // Updating
90 else _attrAMarginalTable_.insert(valueA, 1);
91
93 else _attrBMarginalTable_.insert(valueB, 1);
94
96 if (_jointTable_.exists(cell)) _jointTable_[cell]++;
97 else _jointTable_.insert(cell, 1);
98 }
HashTable< GUM_ELEMENT_B, Idx > _attrBMarginalTable_
HashTable< GUM_ELEMENT_A, Idx > _attrAMarginalTable_
HashTable< std::pair< GUM_ELEMENT_A, GUM_ELEMENT_B >, Idx > _jointTable_
The contingency table used to compute the GStat Left Idx is for the attribute Right Idx for the value...

References _attrAMarginalTable_.

◆ attrABeginSafe()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
HashTableConstIteratorSafe< GUM_ELEMENT_A, Idx > gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::attrABeginSafe ( ) const

Returns the number of samples for line iattr.

Definition at line 154 of file contingencyTable_tpl.h.

154 {
155 return _attrAMarginalTable_.cbeginSafe();
156 }

References _attrAMarginalTable_.

◆ attrAEndSafe()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
HashTableConstIteratorSafe< GUM_ELEMENT_A, Idx > gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::attrAEndSafe ( ) const

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

Definition at line 160 of file contingencyTable_tpl.h.

160 {
161 return _attrAMarginalTable_.cendSafe();
162 }

References _attrAMarginalTable_.

◆ attrAMarginal()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
Idx gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::attrAMarginal ( GUM_ELEMENT_A valueA) const

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

Definition at line 143 of file contingencyTable_tpl.h.

143 {
145 }

References _attrAMarginalTable_.

◆ attrASize()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
Idx gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::attrASize ( ) const

Returns the number of samples for line iattr.

Definition at line 177 of file contingencyTable_tpl.h.

177 {
178 return _attrAMarginalTable_.size();
179 }

References _attrAMarginalTable_.

◆ attrBBeginSafe()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
HashTableConstIteratorSafe< GUM_ELEMENT_B, Idx > gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::attrBBeginSafe ( ) const

Returns the number of samples for column ivalue.

Definition at line 166 of file contingencyTable_tpl.h.

166 {
167 return _attrBMarginalTable_.cbeginSafe();
168 }

References _attrBMarginalTable_.

◆ attrBEndSafe()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
HashTableConstIteratorSafe< GUM_ELEMENT_B, Idx > gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::attrBEndSafe ( ) const

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

Definition at line 172 of file contingencyTable_tpl.h.

172 {
173 return _attrBMarginalTable_.cendSafe();
174 }

References _attrBMarginalTable_.

◆ attrBMarginal()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
Idx gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::attrBMarginal ( GUM_ELEMENT_B valueB) const

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

Definition at line 148 of file contingencyTable_tpl.h.

148 {
150 }

References _attrAMarginalTable_.

◆ attrBSize()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
Idx gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::attrBSize ( ) const

Returns the number of samples for column ivalue.

Definition at line 182 of file contingencyTable_tpl.h.

182 {
183 return _attrBMarginalTable_.size();
184 }

References _attrBMarginalTable_.

◆ joint()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
Idx gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::joint ( GUM_ELEMENT_A valueA,
GUM_ELEMENT_B valueB ) const

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

Definition at line 135 of file contingencyTable_tpl.h.

Referenced by gum::ContingencyTable< Idx, GUM_ELEMENT >::joint().

Here is the caller graph for this function:

◆ operator delete()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
void gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::operator delete ( void * p)

Default constructor.

Definition at line 130 of file contingencyTable_tpl.h.

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

References ContingencyTable().

Here is the call graph for this function:

◆ operator new()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
void * gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::operator new ( size_t s)

Allocators and Deallocators redefinition.

Definition at line 125 of file contingencyTable_tpl.h.

125 {
127 }
void * allocate(const size_t &objectSize)
Allocates a block.

◆ operator+=()

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

Definition at line 102 of file contingencyTable_tpl.h.

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

References ContingencyTable().

Here is the call graph for this function:

◆ toString()

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
std::string gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::toString ( ) const

Definition at line 187 of file contingencyTable_tpl.h.

187 {
189 ss << "\t\t\t\t" << _attrAMarginalTable_ << "\n"
190 << "\t\t\t\t" << _attrBMarginalTable_ << "\n"
191 << "\t\t\t\t" << _jointTable_ << "\n";
192 return ss.str();
193 }

References _attrAMarginalTable_, _attrBMarginalTable_, and _jointTable_.

Member Data Documentation

◆ _attrAMarginalTable_

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
HashTable< GUM_ELEMENT_A, Idx > gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::_attrAMarginalTable_
private

◆ _attrBMarginalTable_

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
HashTable< GUM_ELEMENT_B, Idx > gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >::_attrBMarginalTable_
private

Definition at line 162 of file contingencyTable.h.

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

◆ _jointTable_

template<typename GUM_ELEMENT_A, typename GUM_ELEMENT_B>
HashTable< std::pair< GUM_ELEMENT_A, GUM_ELEMENT_B >, Idx > gum::ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_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 160 of file contingencyTable.h.

Referenced by toString().


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