aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
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-2026 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-2026 *
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
54
#include <
agrum/FMDP/learning/observation.h
>
55
56
#include <
agrum/base/core/math/math_utils.h
>
57
58
namespace
gum
{
59
69
70
template
<
typename
GUM_ELEMENT_A,
typename
GUM_ELEMENT_B >
71
class
ContingencyTable
{
72
public
:
73
// ##########################################################################
75
// ##########################################################################
77
78
80
81
ContingencyTable
();
82
83
85
86
~ContingencyTable
();
87
88
// ============================================================================
90
// ============================================================================
91
void
*
operator
new
(
size_t
s);
92
93
void
operator
delete
(
void
* p);
94
96
97
99
101
102
104
105
void
add
(GUM_ELEMENT_A valueA, GUM_ELEMENT_B valueB);
106
108
109
Idx
joint
(GUM_ELEMENT_A valueA, GUM_ELEMENT_B valueB)
const
;
110
112
113
Idx
attrAMarginal
(GUM_ELEMENT_A valueA)
const
;
114
116
117
Idx
attrBMarginal
(GUM_ELEMENT_B valueB)
const
;
118
120
121
// Idx aMarginal( GUM_ELEMENT_A iattr ) { return
122
// _attrMarginalTable_[iattr]; }
123
HashTableConstIteratorSafe< GUM_ELEMENT_A, Idx >
attrABeginSafe
()
const
;
124
125
HashTableConstIteratorSafe< GUM_ELEMENT_A, Idx >
attrAEndSafe
()
const
;
126
128
129
// Idx vMarginal( GUM_ELEMENT_B ivalue ) { return
130
// _valueMarginalTable_[ivalue]; }
131
HashTableConstIteratorSafe< GUM_ELEMENT_B, Idx >
attrBBeginSafe
()
const
;
132
133
HashTableConstIteratorSafe< GUM_ELEMENT_B, Idx >
attrBEndSafe
()
const
;
134
136
137
Idx
attrASize
()
const
;
138
140
141
Idx
attrBSize
()
const
;
142
144
145
ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >
&
146
operator+=
(
const
ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B >
& src);
147
148
std::string
toString
()
const
;
149
150
private
:
160
HashTable< std::pair< GUM_ELEMENT_A, GUM_ELEMENT_B >
,
Idx
>
_jointTable_
;
161
HashTable< GUM_ELEMENT_A, Idx >
_attrAMarginalTable_
;
162
HashTable< GUM_ELEMENT_B, Idx >
_attrBMarginalTable_
;
163
};
164
165
}
/* namespace gum */
166
167
#include <
agrum/FMDP/learning/core/contingencyTable_tpl.h
>
168
#endif
// GUM_CONTINGENCY_TABLE_H
gum::ContingencyTable::_attrBMarginalTable_
HashTable< GUM_ELEMENT_B, Idx > _attrBMarginalTable_
Definition
contingencyTable.h:162
gum::ContingencyTable::attrBEndSafe
HashTableConstIteratorSafe< GUM_ELEMENT_B, Idx > attrBEndSafe() const
Increments the number of sample for case( iattr, ivalue ).
Definition
contingencyTable_tpl.h:172
gum::ContingencyTable::add
void add(GUM_ELEMENT_A valueA, GUM_ELEMENT_B valueB)
Increments the number of sample for case( iattr, ivalue ).
Definition
contingencyTable_tpl.h:86
gum::ContingencyTable::toString
std::string toString() const
Definition
contingencyTable_tpl.h:187
gum::ContingencyTable::_attrAMarginalTable_
HashTable< GUM_ELEMENT_A, Idx > _attrAMarginalTable_
Definition
contingencyTable.h:161
gum::ContingencyTable::ContingencyTable
ContingencyTable()
Default constructor.
Definition
contingencyTable_tpl.h:66
gum::ContingencyTable::attrBMarginal
Idx attrBMarginal(GUM_ELEMENT_B valueB) const
Returns the number of samples for case (iattr, ivalue).
Definition
contingencyTable_tpl.h:148
gum::ContingencyTable::attrBBeginSafe
HashTableConstIteratorSafe< GUM_ELEMENT_B, Idx > attrBBeginSafe() const
Returns the number of samples for column ivalue.
Definition
contingencyTable_tpl.h:166
gum::ContingencyTable::attrAMarginal
Idx attrAMarginal(GUM_ELEMENT_A valueA) const
Returns the number of samples for case (iattr, ivalue).
Definition
contingencyTable_tpl.h:143
gum::ContingencyTable::attrAEndSafe
HashTableConstIteratorSafe< GUM_ELEMENT_A, Idx > attrAEndSafe() const
Increments the number of sample for case( iattr, ivalue ).
Definition
contingencyTable_tpl.h:160
gum::ContingencyTable::attrASize
Idx attrASize() const
Returns the number of samples for line iattr.
Definition
contingencyTable_tpl.h:177
gum::ContingencyTable::_jointTable_
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...
Definition
contingencyTable.h:160
gum::ContingencyTable::attrBSize
Idx attrBSize() const
Returns the number of samples for column ivalue.
Definition
contingencyTable_tpl.h:182
gum::ContingencyTable::attrABeginSafe
HashTableConstIteratorSafe< GUM_ELEMENT_A, Idx > attrABeginSafe() const
Returns the number of samples for line iattr.
Definition
contingencyTable_tpl.h:154
gum::ContingencyTable::joint
Idx joint(GUM_ELEMENT_A valueA, GUM_ELEMENT_B valueB) const
Returns the number of samples for case (iattr, ivalue).
Definition
contingencyTable_tpl.h:135
gum::ContingencyTable::operator+=
ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B > & operator+=(const ContingencyTable< GUM_ELEMENT_A, GUM_ELEMENT_B > &src)
Definition
contingencyTable_tpl.h:102
gum::HashTableConstIteratorSafe< GUM_ELEMENT_A, Idx >
gum::HashTable
The class for generic Hash Tables.
Definition
hashTable.h:640
contingencyTable_tpl.h
Template implementations for the ContingencyTable class.
gum::Idx
Size Idx
Type for indexes.
Definition
types.h:79
math_utils.h
Useful macros for maths.
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
observation.h
Headers of the Observation class.
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0