aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
contingencyTable.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
49
50
51#ifndef GUM_CONTINGENCY_TABLE_H
52#define GUM_CONTINGENCY_TABLE_H
53
55
57
58namespace gum {
59
69
70 template < typename GUM_SCALAR_A, typename GUM_SCALAR_B >
72 public:
73 // ##########################################################################
75 // ##########################################################################
77
78
80
82
83
85
87
88 // ============================================================================
90 // ============================================================================
91 void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
92
93 void operator delete(void* p) {
95 }
96
98
99
101
103
104
106
107 void add(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB);
108
110
111 Idx joint(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB) const {
112 return _jointTable_.exists(std::pair< GUM_SCALAR_A, GUM_SCALAR_B >(valueA, valueB))
113 ? _jointTable_[std::pair< GUM_SCALAR_A, GUM_SCALAR_B >(valueA, valueB)]
114 : 0;
115 }
116
118
119 Idx attrAMarginal(GUM_SCALAR_A valueA) const {
120 return _attrAMarginalTable_.exists(valueA) ? _attrAMarginalTable_[valueA] : 0;
121 }
122
124
125 Idx attrBMarginal(GUM_SCALAR_B valueB) const {
126 return _attrAMarginalTable_.exists(valueB) ? _attrAMarginalTable_[valueB] : 0;
127 }
128
130
131 // Idx aMarginal( GUM_SCALAR_A iattr ) { return
132 // _attrMarginalTable_[iattr]; }
136
140
142
143 // Idx vMarginal( GUM_SCALAR_B ivalue ) { return
144 // _valueMarginalTable_[ivalue]; }
148
152
154
155 Idx attrASize() const { return _attrAMarginalTable_.size(); }
156
158
159 Idx attrBSize() const { return _attrBMarginalTable_.size(); }
160
162
165
166 std::string toString() const {
167 std::stringstream ss;
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 }
173
174 private:
187 };
188
189} /* namespace gum */
190
192#endif // GUM_CONTINGENCY_TABLE_H
<agrum/FMDP/learning/core/contingencyTable.h>
Idx attrAMarginal(GUM_SCALAR_A valueA) const
Returns the number of samples for case (iattr, ivalue).
Idx attrBSize() const
Returns the number of samples for column ivalue.
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...
Idx attrASize() const
Returns the number of samples for line iattr.
void add(GUM_SCALAR_A valueA, GUM_SCALAR_B valueB)
Increments the number of sample for case( iattr, ivalue ).
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 ).
std::string toString() const
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.
ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B > & operator+=(const ContingencyTable< GUM_SCALAR_A, GUM_SCALAR_B > &src)
Idx attrBMarginal(GUM_SCALAR_B valueB) const
Returns the number of samples for case (iattr, ivalue).
~ContingencyTable()
Default destructor.
ContingencyTable()
Default constructor.
HashTable< GUM_SCALAR_A, Idx > _attrAMarginalTable_
The class for generic Hash Tables.
Definition hashTable.h:637
static SmallObjectAllocator & instance()
void * allocate(const size_t &objectSize)
Allocates a block.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Template implementations for the ContingencyTable class.
Size Idx
Type for indexes.
Definition types.h:79
Useful macros for maths.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Headers of the Observation class.