aGrUM  0.14.2
contingencyTable_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 // =========================================================================
28 // =========================================================================
29 
30 
31 namespace gum {
32 
33  // ##########################################################################
34  // Constructor & destructor.
35  // ##########################################################################
36 
37  // ==========================================================================
38  // Default constructor
39  // ==========================================================================
40  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
42  GUM_CONSTRUCTOR(ContingencyTable);
43  }
44 
45 
46  // ==========================================================================
47  // Default destructor
48  // ==========================================================================
49  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
51  GUM_DESTRUCTOR(ContingencyTable);
52  }
53 
54 
55  // ##########################################################################
56  //
57  // ##########################################################################
58 
59  // ==========================================================================
60  //
61  // ==========================================================================
62  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
64  GUM_SCALAR_B valueB) {
65  // Updating
66  if (__attrAMarginalTable.exists(valueA))
67  __attrAMarginalTable[valueA]++;
68  else
69  __attrAMarginalTable.insert(valueA, 1);
70 
71  if (__attrBMarginalTable.exists(valueB))
72  __attrBMarginalTable[valueB]++;
73  else
74  __attrBMarginalTable.insert(valueB, 1);
75 
76  std::pair< GUM_SCALAR_A, GUM_SCALAR_B > cell(valueA, valueB);
77  if (__jointTable.exists(cell))
78  __jointTable[cell]++;
79  else
80  __jointTable.insert(cell, 1);
81  }
82 
83  template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
87  // Ajout dans marginal A et table joint des valeurs pour src
88  for (auto aTer = src.attrABeginSafe(); aTer != src.attrAEndSafe(); ++aTer) {
89  if (__attrAMarginalTable.exists(aTer.key()))
90  __attrAMarginalTable[aTer.key()] += aTer.val();
91  else
92  __attrAMarginalTable.insert(aTer.key(), aTer.val());
93 
94  for (auto bTer = src.attrBBeginSafe(); bTer != src.attrBEndSafe(); ++bTer) {
95  std::pair< GUM_SCALAR_A, GUM_SCALAR_B > cell(aTer.key(), bTer.key());
96  if (__jointTable.exists(cell))
97  __jointTable[cell] += src.joint(aTer.key(), bTer.key());
98  else
99  __jointTable.insert(cell, src.joint(aTer.key(), bTer.key()));
100  }
101  }
102 
103  // Ajout dans marginal B des valeurs de src
104  for (auto bTer = src.attrBBeginSafe(); bTer != src.attrBEndSafe(); ++bTer) {
105  if (__attrBMarginalTable.exists(bTer.key()))
106  __attrBMarginalTable[bTer.key()] += bTer.val();
107  else
108  __attrBMarginalTable.insert(bTer.key(), bTer.val());
109  }
110  return *this;
111  }
112 
113 } // 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)
gum is the global namespace for all aGrUM entities
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.
Headers of the ContingencyTable class.
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.