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