aGrUM  0.20.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. More...
 
 ~ContingencyTable ()
 Default destructor. More...
 
void * operator new (size_t s)
 Allocators and Deallocators redefinition. More...
 
void operator delete (void *p)
 Default constructor. More...
 
void add (GUM_SCALAR_A valueA, GUM_SCALAR_B valueB)
 Increments the number of sample for case( iattr, ivalue ) More...
 
Idx joint (GUM_SCALAR_A valueA, GUM_SCALAR_B valueB) const
 Returns the number of samples for case (iattr, ivalue) More...
 
Idx attrAMarginal (GUM_SCALAR_A valueA) const
 Returns the number of samples for case (iattr, ivalue) More...
 
Idx attrBMarginal (GUM_SCALAR_B valueB) const
 Returns the number of samples for case (iattr, ivalue) More...
 
HashTableConstIteratorSafe< GUM_SCALAR_A, IdxattrABeginSafe () const
 Returns the number of samples for line iattr. More...
 
HashTableConstIteratorSafe< GUM_SCALAR_A, IdxattrAEndSafe () const
 Increments the number of sample for case( iattr, ivalue ) More...
 
HashTableConstIteratorSafe< GUM_SCALAR_B, IdxattrBBeginSafe () const
 Returns the number of samples for column ivalue. More...
 
HashTableConstIteratorSafe< GUM_SCALAR_B, IdxattrBEndSafe () const
 Increments the number of sample for case( iattr, ivalue ) More...
 
Idx attrASize () const
 Returns the number of samples for line iattr. More...
 
Idx attrBSize () const
 Returns the number of samples for column ivalue. More...
 

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 57 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 43 of file contingencyTable_tpl.h.

43  {
44  GUM_CONSTRUCTOR(ContingencyTable);
45  }
ContingencyTable()
Default constructor.

◆ ~ContingencyTable()

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

Default destructor.

Definition at line 52 of file contingencyTable_tpl.h.

52  {
53  GUM_DESTRUCTOR(ContingencyTable);
54  }
ContingencyTable()
Default constructor.

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 65 of file contingencyTable_tpl.h.

66  {
67  // Updating
68  if (attrAMarginalTable__.exists(valueA))
69  attrAMarginalTable__[valueA]++;
70  else
71  attrAMarginalTable__.insert(valueA, 1);
72 
73  if (attrBMarginalTable__.exists(valueB))
74  attrBMarginalTable__[valueB]++;
75  else
76  attrBMarginalTable__.insert(valueB, 1);
77 
78  std::pair< GUM_SCALAR_A, GUM_SCALAR_B > cell(valueA, valueB);
79  if (jointTable__.exists(cell))
80  jointTable__[cell]++;
81  else
82  jointTable__.insert(cell, 1);
83  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< GUM_SCALAR_A, Idx > attrAMarginalTable__
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...
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ 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 128 of file contingencyTable.h.

128  {
130  }
const_iterator_safe cbeginSafe() const
Returns the safe const_iterator pointing to the beginning of the hashtable.
HashTable< GUM_SCALAR_A, Idx > attrAMarginalTable__

◆ 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 131 of file contingencyTable.h.

131  {
133  }
HashTable< GUM_SCALAR_A, Idx > attrAMarginalTable__
const const_iterator_safe & cendSafe() const noexcept
Returns the safe const_iterator pointing to the end of the hashtable.

◆ 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 110 of file contingencyTable.h.

110  {
111  return attrAMarginalTable__.exists(valueA) ? attrAMarginalTable__[valueA]
112  : 0;
113  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< GUM_SCALAR_A, Idx > 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 150 of file contingencyTable.h.

150 { return attrAMarginalTable__.size(); }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable< GUM_SCALAR_A, Idx > 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 140 of file contingencyTable.h.

140  {
142  }
const_iterator_safe cbeginSafe() const
Returns the safe const_iterator pointing to the beginning of the hashtable.
HashTable< GUM_SCALAR_B, Idx > 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 143 of file contingencyTable.h.

143  {
145  }
HashTable< GUM_SCALAR_B, Idx > attrBMarginalTable__
const const_iterator_safe & cendSafe() const noexcept
Returns the safe const_iterator pointing to the end of the hashtable.

◆ 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 118 of file contingencyTable.h.

118  {
119  return attrAMarginalTable__.exists(valueB) ? attrAMarginalTable__[valueB]
120  : 0;
121  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< GUM_SCALAR_A, Idx > 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 155 of file contingencyTable.h.

155 { return attrBMarginalTable__.size(); }
Size size() const noexcept
Returns the number of elements stored into the hashtable.
HashTable< GUM_SCALAR_B, Idx > 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 99 of file contingencyTable.h.

99  {
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  }
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...

◆ 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 80 of file contingencyTable.h.

80  {
82  }
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
ContingencyTable()
Default constructor.
static SmallObjectAllocator & instance()

◆ 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 77 of file contingencyTable.h.

77  {
79  }
void * allocate(const size_t &objectSize)
Allocates a block.
static SmallObjectAllocator & instance()

◆ 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 87 of file contingencyTable_tpl.h.

88  {
89  // Ajout dans marginal A et table joint des valeurs pour src
90  for (auto aTer = src.attrABeginSafe(); aTer != src.attrAEndSafe(); ++aTer) {
91  if (attrAMarginalTable__.exists(aTer.key()))
92  attrAMarginalTable__[aTer.key()] += aTer.val();
93  else
94  attrAMarginalTable__.insert(aTer.key(), aTer.val());
95 
96  for (auto bTer = src.attrBBeginSafe(); bTer != src.attrBEndSafe(); ++bTer) {
97  std::pair< GUM_SCALAR_A, GUM_SCALAR_B > cell(aTer.key(), bTer.key());
98  if (jointTable__.exists(cell))
99  jointTable__[cell] += src.joint(aTer.key(), bTer.key());
100  else
101  jointTable__.insert(cell, src.joint(aTer.key(), bTer.key()));
102  }
103  }
104 
105  // Ajout dans marginal B des valeurs de src
106  for (auto bTer = src.attrBBeginSafe(); bTer != src.attrBEndSafe(); ++bTer) {
107  if (attrBMarginalTable__.exists(bTer.key()))
108  attrBMarginalTable__[bTer.key()] += bTer.val();
109  else
110  attrBMarginalTable__.insert(bTer.key(), bTer.val());
111  }
112  return *this;
113  }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< GUM_SCALAR_A, Idx > attrAMarginalTable__
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...
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.

◆ 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 162 of file contingencyTable.h.

162  {
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  }
HashTable< GUM_SCALAR_A, Idx > attrAMarginalTable__
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...

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

Definition at line 181 of file contingencyTable.h.

◆ 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 182 of file contingencyTable.h.

◆ 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 180 of file contingencyTable.h.


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