aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
aprioriK2_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 the internal apriori for the K2 score = Laplace Apriori
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
/// default constructor
35
template
<
template
<
typename
>
class
ALLOC >
36
INLINE AprioriK2<
ALLOC
>::
AprioriK2
(
37
const
DatabaseTable
<
ALLOC
>&
database
,
38
const
Bijection
<
NodeId
,
std
::
size_t
,
ALLOC
<
std
::
size_t
> >&
39
nodeId2columns
,
40
const
typename
AprioriK2
<
ALLOC
>::
allocator_type
&
alloc
) :
41
AprioriSmoothing
<
ALLOC
>(
database
,
nodeId2columns
,
alloc
) {
42
GUM_CONSTRUCTOR
(
AprioriK2
);
43
}
44
45
46
/// copy constructor with a given allocator
47
template
<
template
<
typename
>
class
ALLOC
>
48
INLINE
AprioriK2
<
ALLOC
>::
AprioriK2
(
49
const
AprioriK2
<
ALLOC
>&
from
,
50
const
typename
AprioriK2
<
ALLOC
>::
allocator_type
&
alloc
) :
51
AprioriSmoothing
<
ALLOC
>(
from
,
alloc
) {
52
GUM_CONS_CPY
(
AprioriK2
);
53
}
54
55
56
/// copy constructor
57
template
<
template
<
typename
>
class
ALLOC
>
58
INLINE
AprioriK2
<
ALLOC
>::
AprioriK2
(
const
AprioriK2
<
ALLOC
>&
from
) :
59
AprioriK2
<
ALLOC
>(
from
,
from
.
getAllocator
()) {}
60
61
62
/// move constructor with a given allocator
63
template
<
template
<
typename
>
class
ALLOC
>
64
INLINE
AprioriK2
<
ALLOC
>::
AprioriK2
(
65
AprioriK2
<
ALLOC
>&&
from
,
66
const
typename
AprioriK2
<
ALLOC
>::
allocator_type
&
alloc
) :
67
AprioriSmoothing
<
ALLOC
>(
std
::
move
(
from
),
alloc
) {
68
GUM_CONS_MOV
(
AprioriK2
);
69
}
70
71
72
/// move constructor
73
template
<
template
<
typename
>
class
ALLOC
>
74
INLINE
AprioriK2
<
ALLOC
>::
AprioriK2
(
AprioriK2
<
ALLOC
>&&
from
) :
75
AprioriK2
<
ALLOC
>(
std
::
move
(
from
),
from
.
getAllocator
()) {}
76
77
78
/// virtual copy constructor with a given allocator
79
template
<
template
<
typename
>
class
ALLOC
>
80
AprioriK2
<
ALLOC
>*
AprioriK2
<
ALLOC
>::
clone
(
81
const
typename
AprioriK2
<
ALLOC
>::
allocator_type
&
alloc
)
const
{
82
ALLOC
<
AprioriK2
<
ALLOC
> >
allocator
(
alloc
);
83
AprioriK2
<
ALLOC
>*
apriori
=
allocator
.
allocate
(1);
84
try
{
85
allocator
.
construct
(
apriori
, *
this
,
alloc
);
86
}
catch
(...) {
87
allocator
.
deallocate
(
apriori
, 1);
88
throw
;
89
}
90
91
return
apriori
;
92
}
93
94
95
/// virtual copy constructor
96
template
<
template
<
typename
>
class
ALLOC
>
97
INLINE
AprioriK2
<
ALLOC
>*
AprioriK2
<
ALLOC
>::
clone
()
const
{
98
return
clone
(
this
->
getAllocator
());
99
}
100
101
102
/// destructor
103
template
<
template
<
typename
>
class
ALLOC
>
104
INLINE
AprioriK2
<
ALLOC
>::~
AprioriK2
() {
105
GUM_DESTRUCTOR
(
AprioriK2
);
106
}
107
108
109
/// copy operator
110
template
<
template
<
typename
>
class
ALLOC
>
111
INLINE
AprioriK2
<
ALLOC
>&
112
AprioriK2
<
ALLOC
>::
operator
=(
const
AprioriK2
<
ALLOC
>&
from
) {
113
AprioriSmoothing
<
ALLOC
>::
operator
=(
from
);
114
return
*
this
;
115
}
116
117
118
/// move operator
119
template
<
template
<
typename
>
class
ALLOC
>
120
INLINE
AprioriK2
<
ALLOC
>&
121
AprioriK2
<
ALLOC
>::
operator
=(
AprioriK2
<
ALLOC
>&&
from
) {
122
AprioriSmoothing
<
ALLOC
>::
operator
=(
std
::
move
(
from
));
123
return
*
this
;
124
}
125
126
127
/// dummy set weight function: in K2, weights are always equal to 1
128
template
<
template
<
typename
>
class
ALLOC
>
129
INLINE
void
AprioriK2
<
ALLOC
>::
setWeight
(
const
double
weight
) {}
130
131
132
}
/* namespace learning */
133
134
}
/* namespace gum */
135
136
#
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