aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
scoringCache_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 cache for caching scores and independence tests results
24
*
25
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26
*/
27
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
28
29
namespace
gum
{
30
31
namespace
learning
{
32
33
34
/// returns the allocator used by the translator
35
template
<
template
<
typename
>
class
ALLOC
>
36
INLINE
typename
ScoringCache
<
ALLOC
>::
allocator_type
37
ScoringCache
<
ALLOC
>::
getAllocator
()
const
{
38
return
*
this
;
39
}
40
41
42
/// default constructor
43
template
<
template
<
typename
>
class
ALLOC
>
44
INLINE
ScoringCache
<
ALLOC
>::
ScoringCache
(
45
const
typename
ScoringCache
<
ALLOC
>::
allocator_type
&
alloc
) :
46
ALLOC
<
NodeId
>(
alloc
) {
47
GUM_CONSTRUCTOR
(
ScoringCache
);
48
}
49
50
51
/// copy constructor with a given allocator
52
template
<
template
<
typename
>
class
ALLOC
>
53
INLINE
ScoringCache
<
ALLOC
>::
ScoringCache
(
54
const
ScoringCache
<
ALLOC
>&
from
,
55
const
typename
ScoringCache
<
ALLOC
>::
allocator_type
&
alloc
) :
56
ALLOC
<
NodeId
>(
alloc
),
57
scores__
(
from
.
scores__
) {
58
GUM_CONS_CPY
(
ScoringCache
);
59
}
60
61
62
/// copy constructor
63
template
<
template
<
typename
>
class
ALLOC
>
64
INLINE
ScoringCache
<
ALLOC
>::
ScoringCache
(
const
ScoringCache
<
ALLOC
>&
from
) :
65
ScoringCache
<
ALLOC
>(
from
,
from
.
getAllocator
()) {}
66
67
68
/// move constructor with a given allocator
69
template
<
template
<
typename
>
class
ALLOC
>
70
INLINE
ScoringCache
<
ALLOC
>::
ScoringCache
(
71
ScoringCache
<
ALLOC
>&&
from
,
72
const
typename
ScoringCache
<
ALLOC
>::
allocator_type
&
alloc
) :
73
ALLOC
<
NodeId
>(
alloc
),
74
scores__
(
std
::
move
(
from
.
scores__
)) {
75
GUM_CONS_MOV
(
ScoringCache
);
76
}
77
78
79
/// move constructor
80
template
<
template
<
typename
>
class
ALLOC
>
81
INLINE
ScoringCache
<
ALLOC
>::
ScoringCache
(
ScoringCache
<
ALLOC
>&&
from
) :
82
ScoringCache
<
ALLOC
>(
std
::
move
(
from
),
from
.
getAllocator
()) {}
83
84
85
/// virtual copy constructor with a given allocator
86
template
<
template
<
typename
>
class
ALLOC
>
87
ScoringCache
<
ALLOC
>*
ScoringCache
<
ALLOC
>::
clone
(
88
const
typename
ScoringCache
<
ALLOC
>::
allocator_type
&
alloc
)
const
{
89
ALLOC
<
ScoringCache
<
ALLOC
> >
allocator
(
alloc
);
90
ScoringCache
<
ALLOC
>*
cache
=
allocator
.
allocate
(1);
91
try
{
92
allocator
.
construct
(
cache
, *
this
,
alloc
);
93
}
catch
(...) {
94
allocator
.
deallocate
(
cache
, 1);
95
throw
;
96
}
97
return
cache
;
98
}
99
100
101
/// virtual copy constructor
102
template
<
template
<
typename
>
class
ALLOC
>
103
ScoringCache
<
ALLOC
>*
ScoringCache
<
ALLOC
>::
clone
()
const
{
104
return
clone
(
this
->
getAllocator
());
105
}
106
107
108
/// destructor
109
template
<
template
<
typename
>
class
ALLOC
>
110
INLINE
ScoringCache
<
ALLOC
>::~
ScoringCache
() {
111
GUM_DESTRUCTOR
(
ScoringCache
);
112
}
113
114
115
/// copy operator
116
template
<
template
<
typename
>
class
ALLOC
>
117
INLINE
ScoringCache
<
ALLOC
>&
118
ScoringCache
<
ALLOC
>::
operator
=(
const
ScoringCache
<
ALLOC
>&
from
) {
119
if
(&
from
!=
this
) {
scores__
=
from
.
scores__
; }
120
return
*
this
;
121
}
122
123
124
/// move operator
125
template
<
template
<
typename
>
class
ALLOC
>
126
INLINE
ScoringCache
<
ALLOC
>&
127
ScoringCache
<
ALLOC
>::
operator
=(
ScoringCache
<
ALLOC
>&&
from
) {
128
if
(&
from
!=
this
) {
scores__
=
std
::
move
(
from
.
scores__
); }
129
return
*
this
;
130
}
131
132
133
/// insert a new score into the cache
134
template
<
template
<
typename
>
class
ALLOC
>
135
INLINE
void
ScoringCache
<
ALLOC
>::
insert
(
const
IdCondSet
<
ALLOC
>&
idset
,
136
double
score
) {
137
scores__
.
insert
(
idset
,
score
);
138
}
139
140
141
/// insert a new score into the cache
142
template
<
template
<
typename
>
class
ALLOC
>
143
INLINE
void
ScoringCache
<
ALLOC
>::
insert
(
IdCondSet
<
ALLOC
>&&
idset
,
144
double
score
) {
145
scores__
.
insert
(
std
::
move
(
idset
),
std
::
move
(
score
));
146
}
147
148
149
/// removes a score (if it exists)
150
template
<
template
<
typename
>
class
ALLOC
>
151
INLINE
void
ScoringCache
<
ALLOC
>::
erase
(
const
IdCondSet
<
ALLOC
>&
idset
) {
152
scores__
.
erase
(
idset
);
153
}
154
155
156
/// indicates whether a given score exists
157
template
<
template
<
typename
>
class
ALLOC
>
158
INLINE
bool
ScoringCache
<
ALLOC
>::
exists
(
const
IdCondSet
<
ALLOC
>&
idset
) {
159
return
scores__
.
exists
(
idset
);
160
}
161
162
163
/// returns a given score
164
template
<
template
<
typename
>
class
ALLOC
>
165
INLINE
double
ScoringCache
<
ALLOC
>::
score
(
const
IdCondSet
<
ALLOC
>&
idset
) {
166
return
scores__
[
idset
];
167
}
168
169
170
/// removes all the stored scores
171
template
<
template
<
typename
>
class
ALLOC
>
172
INLINE
void
ScoringCache
<
ALLOC
>::
clear
() {
173
scores__
.
clear
();
174
}
175
176
177
/// returns the number of scores saved in the cache
178
template
<
template
<
typename
>
class
ALLOC
>
179
INLINE
std
::
size_t
ScoringCache
<
ALLOC
>::
size
()
const
{
180
return
scores__
.
size
();
181
}
182
183
184
}
/* namespace learning */
185
186
}
/* namespace gum */
187
188
#
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