aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
scheduleProjectionBasic_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 generic class to project efficiently a ScheduleMultiDim over a
24
*subset
25
* of its variables
26
*
27
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
28
*/
29
30
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
31
32
#
include
<
agrum
/
agrum
.
h
>
33
#
include
<
agrum
/
tools
/
graphicalModels
/
inference
/
scheduler
/
scheduleProject
.
h
>
34
#
include
<
limits
>
35
36
namespace
gum
{
37
38
/// default constructor
39
template
<
typename
GUM_SCALAR >
40
ScheduleProjectionBasic< GUM_SCALAR >::ScheduleProjectionBasic(
41
MultiDimImplementation
<
GUM_SCALAR
>* (*
proj
)(
const
MultiDimImplementation
<
GUM_SCALAR
>&,
42
const
Set
<
const
DiscreteVariable
* >&)) :
43
ScheduleProjection
<
GUM_SCALAR
>(),
44
proj_
(
proj
) {
45
/// for debugging purposes
46
GUM_CONSTRUCTOR
(
ScheduleProjectionBasic
);
47
}
48
49
/// copy constructor
50
template
<
typename
GUM_SCALAR
>
51
ScheduleProjectionBasic
<
GUM_SCALAR
>::
ScheduleProjectionBasic
(
52
const
ScheduleProjectionBasic
<
GUM_SCALAR
>&
from
) :
53
ScheduleProjection
<
GUM_SCALAR
>(
from
),
54
proj_
(
from
.
proj_
) {
55
/// for debugging purposes
56
GUM_CONS_CPY
(
ScheduleProjectionBasic
);
57
}
58
59
/// destructor
60
template
<
typename
GUM_SCALAR
>
61
ScheduleProjectionBasic
<
GUM_SCALAR
>::~
ScheduleProjectionBasic
() {
62
/// for debugging purposes
63
GUM_DESTRUCTOR
(
ScheduleProjectionBasic
);
64
}
65
66
/// virtual constructor
67
template
<
typename
GUM_SCALAR
>
68
ScheduleProjectionBasic
<
GUM_SCALAR
>*
ScheduleProjectionBasic
<
GUM_SCALAR
>::
newFactory
()
const
{
69
return
new
ScheduleProjectionBasic
<
GUM_SCALAR
>(*
this
);
70
}
71
72
/// creates and returns the projection of the table over a subset of its vars
73
template
<
typename
GUM_SCALAR
>
74
ScheduleMultiDim
<
GUM_SCALAR
>
75
ScheduleProjectionBasic
<
GUM_SCALAR
>::
project
(
const
ScheduleMultiDim
<
GUM_SCALAR
>&
table
,
76
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
77
Schedule
<
GUM_SCALAR
>&
schedule
) {
78
// create the projection that will be performed later on
79
ScheduleProject
<
GUM_SCALAR
>
proj
(
table
,
del_vars
,
proj_
);
80
schedule
.
insert
(
proj
);
81
82
return
proj
.
result
();
83
}
84
85
/// creates and returns the projection of the table over a subset of its vars
86
template
<
typename
GUM_SCALAR
>
87
INLINE
ScheduleMultiDim
<
GUM_SCALAR
>
ScheduleProjectionBasic
<
GUM_SCALAR
>::
project
(
88
const
MultiDimImplementation
<
GUM_SCALAR
>&
table
,
89
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
90
Schedule
<
GUM_SCALAR
>&
schedule
) {
91
return
ScheduleProjection
<
GUM_SCALAR
>::
project
(
table
,
del_vars
,
schedule
);
92
}
93
94
/// creates and returns the projection of the table over a subset of its vars
95
template
<
typename
GUM_SCALAR
>
96
template
<
template
<
typename
>
class
TABLE
>
97
INLINE
ScheduleMultiDim
<
GUM_SCALAR
>
98
ScheduleProjectionBasic
<
GUM_SCALAR
>::
project
(
const
TABLE
<
GUM_SCALAR
>&
table
,
99
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
100
Schedule
<
GUM_SCALAR
>&
schedule
) {
101
return
ScheduleProjection
<
GUM_SCALAR
>::
project
(
table
,
del_vars
,
schedule
);
102
}
103
104
/// changes the function used for projecting tables
105
template
<
typename
GUM_SCALAR
>
106
void
ScheduleProjectionBasic
<
GUM_SCALAR
>::
setProjectFunction
(
107
MultiDimImplementation
<
GUM_SCALAR
>* (*
proj
)(
const
MultiDimImplementation
<
GUM_SCALAR
>&,
108
const
Set
<
const
DiscreteVariable
* >&)) {
109
proj_
=
proj
;
110
}
111
112
/// returns the projection function currently used by the projector
113
template
<
typename
GUM_SCALAR
>
114
INLINE
MultiDimImplementation
<
GUM_SCALAR
>* (
115
*
ScheduleProjectionBasic
<
GUM_SCALAR
>::
projectFunction
())(
116
const
MultiDimImplementation
<
GUM_SCALAR
>&,
117
const
Set
<
const
DiscreteVariable
* >&) {
118
return
proj_
;
119
}
120
121
/** @brief returns a rough estimate of the number of operations that will be
122
* performed to compute the projection */
123
template
<
typename
GUM_SCALAR
>
124
float
ScheduleProjectionBasic
<
GUM_SCALAR
>::
nbOperations
(
125
const
ScheduleMultiDim
<
GUM_SCALAR
>&
table
,
126
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
127
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
128
const
Sequence
<
const
DiscreteVariable
* >&
vars
=
table
.
variablesSequence
();
129
130
float
res
= 1.0f;
131
132
for
(
const
auto
var
:
vars
)
133
res
*=
var
->
domainSize
();
134
135
return
res
;
136
}
137
138
/** @brief returns a rough estimate of the number of operations that will be
139
* performed to compute the projection */
140
template
<
typename
GUM_SCALAR
>
141
INLINE
float
ScheduleProjectionBasic
<
GUM_SCALAR
>::
nbOperations
(
142
const
MultiDimImplementation
<
GUM_SCALAR
>&
table
,
143
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
144
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
145
return
ScheduleProjection
<
GUM_SCALAR
>::
nbOperations
(
table
,
del_vars
,
schedule
);
146
}
147
148
/** @brief returns a rough estimate of the number of operations that will be
149
* performed to compute the projection */
150
template
<
typename
GUM_SCALAR
>
151
template
<
template
<
typename
>
class
TABLE
>
152
INLINE
float
ScheduleProjectionBasic
<
GUM_SCALAR
>::
nbOperations
(
153
const
TABLE
<
GUM_SCALAR
>&
table
,
154
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
155
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
156
return
ScheduleProjection
<
GUM_SCALAR
>::
nbOperations
(
table
,
del_vars
,
schedule
);
157
}
158
159
/// returns the memory consumption used during the projection
160
template
<
typename
GUM_SCALAR
>
161
std
::
pair
<
long
,
long
>
ScheduleProjectionBasic
<
GUM_SCALAR
>::
memoryUsage
(
162
const
ScheduleMultiDim
<
GUM_SCALAR
>&
table
,
163
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
164
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
165
const
Sequence
<
const
DiscreteVariable
* >&
vars
=
table
.
variablesSequence
();
166
long
res
= 1;
167
168
for
(
const
auto
var
:
vars
)
169
if
(!
del_vars
.
contains
(
var
)) {
170
if
(
std
::
numeric_limits
<
long
>::
max
() / (
long
)
var
->
domainSize
() <
res
) {
171
GUM_ERROR
(
OutOfBounds
,
"memory usage out of long int range"
)
172
}
173
174
res
*=
long
(
var
->
domainSize
());
175
}
176
177
return
std
::
pair
<
long
,
long
>(
res
,
res
);
178
}
179
180
/// returns the memory consumption used during the projection
181
template
<
typename
GUM_SCALAR
>
182
INLINE
std
::
pair
<
long
,
long
>
ScheduleProjectionBasic
<
GUM_SCALAR
>::
memoryUsage
(
183
const
MultiDimImplementation
<
GUM_SCALAR
>&
table
,
184
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
185
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
186
return
ScheduleProjection
<
GUM_SCALAR
>::
memoryUsage
(
table
,
del_vars
,
schedule
);
187
}
188
189
/// returns the memory consumption used during the projection
190
template
<
typename
GUM_SCALAR
>
191
template
<
template
<
typename
>
class
TABLE
>
192
INLINE
std
::
pair
<
long
,
long
>
ScheduleProjectionBasic
<
GUM_SCALAR
>::
memoryUsage
(
193
const
TABLE
<
GUM_SCALAR
>&
table
,
194
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
195
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
196
return
ScheduleProjection
<
GUM_SCALAR
>::
memoryUsage
(
table
,
del_vars
,
schedule
);
197
}
198
199
}
/* namespace gum */
200
201
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643