aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
DBRowGenerator4CompleteRows_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4
* info_at_agrum_dot_org
5
*
6
* This library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
22
/** @file
23
* @brief A DBRowGenerator class that returns the rows that are complete
24
* (fully observed) w.r.t. the nodes of interest
25
*
26
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27
*/
28
#
include
<
agrum
/
tools
/
database
/
DBRowGenerator4CompleteRows
.
h
>
29
30
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
31
32
namespace
gum
{
33
34
namespace
learning
{
35
36
/// returns the allocator used
37
template
<
template
<
typename
>
class
ALLOC
>
38
INLINE
typename
DBRowGenerator4CompleteRows
<
ALLOC
>::
allocator_type
39
DBRowGenerator4CompleteRows
<
ALLOC
>::
getAllocator
()
const
{
40
return
DBRowGenerator
<
ALLOC
>::
getAllocator
();
41
}
42
43
44
/// default constructor
45
template
<
template
<
typename
>
class
ALLOC
>
46
DBRowGenerator4CompleteRows
<
ALLOC
>::
DBRowGenerator4CompleteRows
(
47
const
std
::
vector
<
DBTranslatedValueType
,
ALLOC
<
DBTranslatedValueType
> >
48
column_types
,
49
const
typename
DBRowGenerator4CompleteRows
<
ALLOC
>::
allocator_type
&
50
alloc
) :
51
DBRowGenerator
<
ALLOC
>(
column_types
,
52
DBRowGeneratorGoal
::
ONLY_REMOVE_MISSING_VALUES
,
53
alloc
) {
54
GUM_CONSTRUCTOR
(
DBRowGenerator4CompleteRows
);
55
}
56
57
58
/// copy constructor with a given allocator
59
template
<
template
<
typename
>
class
ALLOC
>
60
DBRowGenerator4CompleteRows
<
ALLOC
>::
DBRowGenerator4CompleteRows
(
61
const
DBRowGenerator4CompleteRows
<
ALLOC
>&
from
,
62
const
typename
DBRowGenerator4CompleteRows
<
ALLOC
>::
allocator_type
&
63
alloc
) :
64
DBRowGenerator
<
ALLOC
>(
from
,
alloc
),
65
input_row__
(
from
.
input_row__
) {
66
GUM_CONS_CPY
(
DBRowGenerator4CompleteRows
);
67
}
68
69
70
/// copy constructor
71
template
<
template
<
typename
>
class
ALLOC
>
72
DBRowGenerator4CompleteRows
<
ALLOC
>::
DBRowGenerator4CompleteRows
(
73
const
DBRowGenerator4CompleteRows
<
ALLOC
>&
from
) :
74
DBRowGenerator4CompleteRows
<
ALLOC
>(
from
,
from
.
getAllocator
()) {}
75
76
77
/// move constructor with a given allocator
78
template
<
template
<
typename
>
class
ALLOC
>
79
DBRowGenerator4CompleteRows
<
ALLOC
>::
DBRowGenerator4CompleteRows
(
80
DBRowGenerator4CompleteRows
<
ALLOC
>&&
from
,
81
const
typename
DBRowGenerator4CompleteRows
<
ALLOC
>::
allocator_type
&
82
alloc
) :
83
DBRowGenerator
<
ALLOC
>(
std
::
move
(
from
),
alloc
),
84
input_row__
(
from
.
input_row__
) {
85
GUM_CONS_MOV
(
DBRowGenerator4CompleteRows
);
86
}
87
88
89
/// move constructor
90
template
<
template
<
typename
>
class
ALLOC
>
91
DBRowGenerator4CompleteRows
<
ALLOC
>::
DBRowGenerator4CompleteRows
(
92
DBRowGenerator4CompleteRows
<
ALLOC
>&&
from
) :
93
DBRowGenerator4CompleteRows
<
ALLOC
>(
std
::
move
(
from
),
94
from
.
getAllocator
()) {}
95
96
97
/// virtual copy constructor with a given allocator
98
template
<
template
<
typename
>
class
ALLOC
>
99
DBRowGenerator4CompleteRows
<
ALLOC
>*
100
DBRowGenerator4CompleteRows
<
ALLOC
>::
clone
(
101
const
typename
DBRowGenerator4CompleteRows
<
ALLOC
>::
allocator_type
&
102
alloc
)
const
{
103
ALLOC
<
DBRowGenerator4CompleteRows
<
ALLOC
> >
allocator
(
alloc
);
104
DBRowGenerator4CompleteRows
<
ALLOC
>*
generator
=
allocator
.
allocate
(1);
105
try
{
106
allocator
.
construct
(
generator
, *
this
,
alloc
);
107
}
catch
(...) {
108
allocator
.
deallocate
(
generator
, 1);
109
throw
;
110
}
111
return
generator
;
112
}
113
114
115
/// virtual copy constructor
116
template
<
template
<
typename
>
class
ALLOC
>
117
DBRowGenerator4CompleteRows
<
ALLOC
>*
118
DBRowGenerator4CompleteRows
<
ALLOC
>::
clone
()
const
{
119
return
clone
(
this
->
getAllocator
());
120
}
121
122
123
/// destructor
124
template
<
template
<
typename
>
class
ALLOC
>
125
DBRowGenerator4CompleteRows
<
ALLOC
>::~
DBRowGenerator4CompleteRows
() {
126
GUM_DESTRUCTOR
(
DBRowGenerator4CompleteRows
);
127
}
128
129
130
/// copy operator
131
template
<
template
<
typename
>
class
ALLOC
>
132
DBRowGenerator4CompleteRows
<
ALLOC
>&
133
DBRowGenerator4CompleteRows
<
ALLOC
>::
operator
=(
134
const
DBRowGenerator4CompleteRows
<
ALLOC
>&
from
) {
135
DBRowGenerator
<
ALLOC
>::
operator
=(
from
);
136
input_row__
=
from
.
input_row__
;
137
return
*
this
;
138
}
139
140
141
/// move operator
142
template
<
template
<
typename
>
class
ALLOC
>
143
DBRowGenerator4CompleteRows
<
ALLOC
>&
144
DBRowGenerator4CompleteRows
<
ALLOC
>::
operator
=(
145
DBRowGenerator4CompleteRows
<
ALLOC
>&&
from
) {
146
DBRowGenerator
<
ALLOC
>::
operator
=(
std
::
move
(
from
));
147
input_row__
=
from
.
input_row__
;
148
return
*
this
;
149
}
150
151
152
/// generates new lines from those the generator gets in input
153
template
<
template
<
typename
>
class
ALLOC
>
154
INLINE
const
DBRow
<
DBTranslatedValue
,
ALLOC
>&
155
DBRowGenerator4CompleteRows
<
ALLOC
>::
generate
() {
156
this
->
decreaseRemainingRows
();
157
return
*
input_row__
;
158
}
159
160
161
/// computes the rows it will provide in output
162
template
<
template
<
typename
>
class
ALLOC
>
163
INLINE
std
::
size_t
DBRowGenerator4CompleteRows
<
ALLOC
>::
computeRows_
(
164
const
DBRow
<
DBTranslatedValue
,
ALLOC
>&
row
) {
165
// check that all the values are observed
166
const
auto
&
xrow
=
row
.
row
();
167
for
(
const
auto
col
:
this
->
columns_of_interest_
) {
168
switch
(
this
->
column_types_
[
col
]) {
169
case
DBTranslatedValueType
::
DISCRETE
:
170
if
(
xrow
[
col
].
discr_val
==
std
::
numeric_limits
<
std
::
size_t
>::
max
()) {
171
input_row__
=
nullptr
;
172
return
std
::
size_t
(0);
173
}
174
break
;
175
176
case
DBTranslatedValueType
::
CONTINUOUS
:
177
if
(
xrow
[
col
].
cont_val
==
std
::
numeric_limits
<
float
>::
max
()) {
178
input_row__
=
nullptr
;
179
return
std
::
size_t
(0);
180
}
181
break
;
182
183
default
:
184
GUM_ERROR
(
NotImplementedYet
,
185
"DBTranslatedValueType "
<<
int
(
this
->
column_types_
[
col
])
186
<<
" is not supported yet"
);
187
break
;
188
}
189
}
190
input_row__
= &
row
;
191
return
std
::
size_t
(1);
192
}
193
194
195
}
/* namespace learning */
196
197
}
/* namespace gum */
198
199
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669
gum::learning::genericBNLearner::Database::Database
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
Definition:
genericBNLearner_tpl.h:31