aGrUM  0.16.0
contingencyTable_tpl.h
Go to the documentation of this file.
1 
29 // =========================================================================
31 // =========================================================================
32 
33 
34 namespace gum {
35 
36  // ##########################################################################
37  // Constructor & destructor.
38  // ##########################################################################
39 
40  // ==========================================================================
41  // Default constructor
42  // ==========================================================================
43  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
45  GUM_CONSTRUCTOR(ContingencyTable);
46  }
47 
48 
49  // ==========================================================================
50  // Default destructor
51  // ==========================================================================
52  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
54  GUM_DESTRUCTOR(ContingencyTable);
55  }
56 
57 
58  // ##########################################################################
59  //
60  // ##########################################################################
61 
62  // ==========================================================================
63  //
64  // ==========================================================================
65  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
67  GUM_SCALAR_B valueB) {
68  // Updating
69  if (__attrAMarginalTable.exists(valueA))
70  __attrAMarginalTable[valueA]++;
71  else
72  __attrAMarginalTable.insert(valueA, 1);
73 
74  if (__attrBMarginalTable.exists(valueB))
75  __attrBMarginalTable[valueB]++;
76  else
77  __attrBMarginalTable.insert(valueB, 1);
78 
79  std::pair< GUM_SCALAR_A, GUM_SCALAR_B > cell(valueA, valueB);
80  if (__jointTable.exists(cell))
81  __jointTable[cell]++;
82  else
83  __jointTable.insert(cell, 1);
84  }
85 
86  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
90  // Ajout dans marginal A et table joint des valeurs pour src
91  for (auto aTer = src.attrABeginSafe(); aTer != src.attrAEndSafe(); ++aTer) {
92  if (__attrAMarginalTable.exists(aTer.key()))
93  __attrAMarginalTable[aTer.key()] += aTer.val();
94  else
95  __attrAMarginalTable.insert(aTer.key(), aTer.val());
96 
97  for (auto bTer = src.attrBBeginSafe(); bTer != src.attrBEndSafe(); ++bTer) {
98  std::pair< GUM_SCALAR_A, GUM_SCALAR_B > cell(aTer.key(), bTer.key());
99  if (__jointTable.exists(cell))
100  __jointTable[cell] += src.joint(aTer.key(), bTer.key());
101  else
102  __jointTable.insert(cell, src.joint(aTer.key(), bTer.key()));
103  }
104  }
105 
106  // Ajout dans marginal B des valeurs de src
107  for (auto bTer = src.attrBBeginSafe(); bTer != src.attrBEndSafe(); ++bTer) {
108  if (__attrBMarginalTable.exists(bTer.key()))
109  __attrBMarginalTable[bTer.key()] += bTer.val();
110  else
111  __attrBMarginalTable.insert(bTer.key(), bTer.val());
112  }
113  return *this;
114  }
115 
116 } // End of namespace gum
HashTableConstIteratorSafe< GUM_SCALAR_B, Idx > attrBEndSafe() const
Increments the number of sample for case( iattr, ivalue )
<agrum/FMDP/learning/core/contingencyTable.h>
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)
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
~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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.