aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
scoringCache_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 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
>&
ScoringCache
<
ALLOC
>::
operator
=(
ScoringCache
<
ALLOC
>&&
from
) {
127
if
(&
from
!=
this
) {
_scores_
=
std
::
move
(
from
.
_scores_
); }
128
return
*
this
;
129
}
130
131
132
/// insert a new score into the cache
133
template
<
template
<
typename
>
class
ALLOC
>
134
INLINE
void
ScoringCache
<
ALLOC
>::
insert
(
const
IdCondSet
<
ALLOC
>&
idset
,
double
score
) {
135
_scores_
.
insert
(
idset
,
score
);
136
}
137
138
139
/// insert a new score into the cache
140
template
<
template
<
typename
>
class
ALLOC
>
141
INLINE
void
ScoringCache
<
ALLOC
>::
insert
(
IdCondSet
<
ALLOC
>&&
idset
,
double
score
) {
142
_scores_
.
insert
(
std
::
move
(
idset
),
std
::
move
(
score
));
143
}
144
145
146
/// removes a score (if it exists)
147
template
<
template
<
typename
>
class
ALLOC
>
148
INLINE
void
ScoringCache
<
ALLOC
>::
erase
(
const
IdCondSet
<
ALLOC
>&
idset
) {
149
_scores_
.
erase
(
idset
);
150
}
151
152
153
/// indicates whether a given score exists
154
template
<
template
<
typename
>
class
ALLOC
>
155
INLINE
bool
ScoringCache
<
ALLOC
>::
exists
(
const
IdCondSet
<
ALLOC
>&
idset
) {
156
return
_scores_
.
exists
(
idset
);
157
}
158
159
160
/// returns a given score
161
template
<
template
<
typename
>
class
ALLOC
>
162
INLINE
double
ScoringCache
<
ALLOC
>::
score
(
const
IdCondSet
<
ALLOC
>&
idset
) {
163
return
_scores_
[
idset
];
164
}
165
166
167
/// removes all the stored scores
168
template
<
template
<
typename
>
class
ALLOC
>
169
INLINE
void
ScoringCache
<
ALLOC
>::
clear
() {
170
_scores_
.
clear
();
171
}
172
173
174
/// returns the number of scores saved in the cache
175
template
<
template
<
typename
>
class
ALLOC
>
176
INLINE
std
::
size_t
ScoringCache
<
ALLOC
>::
size
()
const
{
177
return
_scores_
.
size
();
178
}
179
180
181
}
/* namespace learning */
182
183
}
/* namespace gum */
184
185
#
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