aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
DBRowGenerator4CompleteRows_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright (c) 2005-2021 by 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
> >
column_types
,
48
const
typename
DBRowGenerator4CompleteRows
<
ALLOC
>::
allocator_type
&
alloc
) :
49
DBRowGenerator
<
ALLOC
>(
column_types
,
50
DBRowGeneratorGoal
::
ONLY_REMOVE_MISSING_VALUES
,
51
alloc
) {
52
GUM_CONSTRUCTOR
(
DBRowGenerator4CompleteRows
);
53
}
54
55
56
/// copy constructor with a given allocator
57
template
<
template
<
typename
>
class
ALLOC
>
58
DBRowGenerator4CompleteRows
<
ALLOC
>::
DBRowGenerator4CompleteRows
(
59
const
DBRowGenerator4CompleteRows
<
ALLOC
>&
from
,
60
const
typename
DBRowGenerator4CompleteRows
<
ALLOC
>::
allocator_type
&
alloc
) :
61
DBRowGenerator
<
ALLOC
>(
from
,
alloc
),
62
_input_row_
(
from
.
_input_row_
) {
63
GUM_CONS_CPY
(
DBRowGenerator4CompleteRows
);
64
}
65
66
67
/// copy constructor
68
template
<
template
<
typename
>
class
ALLOC
>
69
DBRowGenerator4CompleteRows
<
ALLOC
>::
DBRowGenerator4CompleteRows
(
70
const
DBRowGenerator4CompleteRows
<
ALLOC
>&
from
) :
71
DBRowGenerator4CompleteRows
<
ALLOC
>(
from
,
from
.
getAllocator
()) {}
72
73
74
/// move constructor with a given allocator
75
template
<
template
<
typename
>
class
ALLOC
>
76
DBRowGenerator4CompleteRows
<
ALLOC
>::
DBRowGenerator4CompleteRows
(
77
DBRowGenerator4CompleteRows
<
ALLOC
>&&
from
,
78
const
typename
DBRowGenerator4CompleteRows
<
ALLOC
>::
allocator_type
&
alloc
) :
79
DBRowGenerator
<
ALLOC
>(
std
::
move
(
from
),
alloc
),
80
_input_row_
(
from
.
_input_row_
) {
81
GUM_CONS_MOV
(
DBRowGenerator4CompleteRows
);
82
}
83
84
85
/// move constructor
86
template
<
template
<
typename
>
class
ALLOC
>
87
DBRowGenerator4CompleteRows
<
ALLOC
>::
DBRowGenerator4CompleteRows
(
88
DBRowGenerator4CompleteRows
<
ALLOC
>&&
from
) :
89
DBRowGenerator4CompleteRows
<
ALLOC
>(
std
::
move
(
from
),
from
.
getAllocator
()) {}
90
91
92
/// virtual copy constructor with a given allocator
93
template
<
template
<
typename
>
class
ALLOC
>
94
DBRowGenerator4CompleteRows
<
ALLOC
>*
DBRowGenerator4CompleteRows
<
ALLOC
>::
clone
(
95
const
typename
DBRowGenerator4CompleteRows
<
ALLOC
>::
allocator_type
&
alloc
)
const
{
96
ALLOC
<
DBRowGenerator4CompleteRows
<
ALLOC
> >
allocator
(
alloc
);
97
DBRowGenerator4CompleteRows
<
ALLOC
>*
generator
=
allocator
.
allocate
(1);
98
try
{
99
allocator
.
construct
(
generator
, *
this
,
alloc
);
100
}
catch
(...) {
101
allocator
.
deallocate
(
generator
, 1);
102
throw
;
103
}
104
return
generator
;
105
}
106
107
108
/// virtual copy constructor
109
template
<
template
<
typename
>
class
ALLOC
>
110
DBRowGenerator4CompleteRows
<
ALLOC
>*
DBRowGenerator4CompleteRows
<
ALLOC
>::
clone
()
const
{
111
return
clone
(
this
->
getAllocator
());
112
}
113
114
115
/// destructor
116
template
<
template
<
typename
>
class
ALLOC
>
117
DBRowGenerator4CompleteRows
<
ALLOC
>::~
DBRowGenerator4CompleteRows
() {
118
GUM_DESTRUCTOR
(
DBRowGenerator4CompleteRows
);
119
}
120
121
122
/// copy operator
123
template
<
template
<
typename
>
class
ALLOC
>
124
DBRowGenerator4CompleteRows
<
ALLOC
>&
DBRowGenerator4CompleteRows
<
ALLOC
>::
operator
=(
125
const
DBRowGenerator4CompleteRows
<
ALLOC
>&
from
) {
126
DBRowGenerator
<
ALLOC
>::
operator
=(
from
);
127
_input_row_
=
from
.
_input_row_
;
128
return
*
this
;
129
}
130
131
132
/// move operator
133
template
<
template
<
typename
>
class
ALLOC
>
134
DBRowGenerator4CompleteRows
<
ALLOC
>&
DBRowGenerator4CompleteRows
<
ALLOC
>::
operator
=(
135
DBRowGenerator4CompleteRows
<
ALLOC
>&&
from
) {
136
DBRowGenerator
<
ALLOC
>::
operator
=(
std
::
move
(
from
));
137
_input_row_
=
from
.
_input_row_
;
138
return
*
this
;
139
}
140
141
142
/// generates new lines from those the generator gets in input
143
template
<
template
<
typename
>
class
ALLOC
>
144
INLINE
const
DBRow
<
DBTranslatedValue
,
ALLOC
>&
145
DBRowGenerator4CompleteRows
<
ALLOC
>::
generate
() {
146
this
->
decreaseRemainingRows
();
147
return
*
_input_row_
;
148
}
149
150
151
/// computes the rows it will provide in output
152
template
<
template
<
typename
>
class
ALLOC
>
153
INLINE
std
::
size_t
DBRowGenerator4CompleteRows
<
ALLOC
>::
computeRows_
(
154
const
DBRow
<
DBTranslatedValue
,
ALLOC
>&
row
) {
155
// check that all the values are observed
156
const
auto
&
xrow
=
row
.
row
();
157
for
(
const
auto
col
:
this
->
columns_of_interest_
) {
158
switch
(
this
->
column_types_
[
col
]) {
159
case
DBTranslatedValueType
::
DISCRETE
:
160
if
(
xrow
[
col
].
discr_val
==
std
::
numeric_limits
<
std
::
size_t
>::
max
()) {
161
_input_row_
=
nullptr
;
162
return
std
::
size_t
(0);
163
}
164
break
;
165
166
case
DBTranslatedValueType
::
CONTINUOUS
:
167
if
(
xrow
[
col
].
cont_val
==
std
::
numeric_limits
<
float
>::
max
()) {
168
_input_row_
=
nullptr
;
169
return
std
::
size_t
(0);
170
}
171
break
;
172
173
default
:
174
GUM_ERROR
(
NotImplementedYet
,
175
"DBTranslatedValueType "
<<
int
(
this
->
column_types_
[
col
])
176
<<
" is not supported yet"
);
177
break
;
178
}
179
}
180
_input_row_
= &
row
;
181
return
std
::
size_t
(1);
182
}
183
184
185
}
/* namespace learning */
186
187
}
/* namespace gum */
188
189
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643
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