aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
apriori_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 base class for all a prioris
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
/// default constructor
34
template
<
template
<
typename
>
class
ALLOC >
35
INLINE Apriori<
ALLOC
>::
Apriori
(
36
const
DatabaseTable
<
ALLOC
>&
database
,
37
const
Bijection
<
NodeId
,
std
::
size_t
,
ALLOC
<
std
::
size_t
> >&
nodeId2columns
,
38
const
typename
Apriori
<
ALLOC
>::
allocator_type
&
alloc
) :
39
ALLOC
<
NodeId
>(
alloc
),
40
database_
(&
database
),
nodeId2columns_
(
nodeId2columns
) {
41
GUM_CONSTRUCTOR
(
Apriori
);
42
}
43
44
45
/// copy constructor with a given allocator
46
template
<
template
<
typename
>
class
ALLOC
>
47
INLINE
Apriori
<
ALLOC
>::
Apriori
(
const
Apriori
<
ALLOC
>&
from
,
48
const
typename
Apriori
<
ALLOC
>::
allocator_type
&
alloc
) :
49
ALLOC
<
NodeId
>(
alloc
),
50
weight_
(
from
.
weight_
),
database_
(
from
.
database_
),
nodeId2columns_
(
from
.
nodeId2columns_
) {
51
GUM_CONS_CPY
(
Apriori
);
52
}
53
54
55
/// copy constructor
56
template
<
template
<
typename
>
class
ALLOC
>
57
INLINE
Apriori
<
ALLOC
>::
Apriori
(
const
Apriori
<
ALLOC
>&
from
) :
58
Apriori
(
from
,
from
.
getAllocator
()) {}
59
60
61
/// move constructor
62
template
<
template
<
typename
>
class
ALLOC
>
63
INLINE
Apriori
<
ALLOC
>::
Apriori
(
Apriori
<
ALLOC
>&&
from
,
64
const
typename
Apriori
<
ALLOC
>::
allocator_type
&
alloc
) :
65
ALLOC
<
NodeId
>(
alloc
),
66
weight_
(
from
.
weight_
),
database_
(
from
.
database_
),
67
nodeId2columns_
(
std
::
move
(
from
.
nodeId2columns_
)) {
68
GUM_CONS_MOV
(
Apriori
);
69
}
70
71
72
/// move constructor
73
template
<
template
<
typename
>
class
ALLOC
>
74
INLINE
Apriori
<
ALLOC
>::
Apriori
(
Apriori
<
ALLOC
>&&
from
) :
75
Apriori
(
std
::
move
(
from
),
from
.
getAllocator
()) {}
76
77
78
/// destructor
79
template
<
template
<
typename
>
class
ALLOC
>
80
INLINE
Apriori
<
ALLOC
>::~
Apriori
() {
81
GUM_DESTRUCTOR
(
Apriori
);
82
}
83
84
85
/// copy operator
86
template
<
template
<
typename
>
class
ALLOC
>
87
Apriori
<
ALLOC
>&
Apriori
<
ALLOC
>::
operator
=(
const
Apriori
<
ALLOC
>&
from
) {
88
if
(
this
!= &
from
) {
89
nodeId2columns_
=
from
.
nodeId2columns_
;
90
weight_
=
from
.
weight_
;
91
database_
=
from
.
database_
;
92
}
93
return
*
this
;
94
}
95
96
97
/// move operator
98
template
<
template
<
typename
>
class
ALLOC
>
99
Apriori
<
ALLOC
>&
Apriori
<
ALLOC
>::
operator
=(
Apriori
<
ALLOC
>&&
from
) {
100
if
(
this
!= &
from
) {
101
nodeId2columns_
=
std
::
move
(
from
.
nodeId2columns_
);
102
weight_
=
from
.
weight_
;
103
database_
=
from
.
database_
;
104
}
105
return
*
this
;
106
}
107
108
109
/// sets the weight of the a priori (kind of effective sample size)
110
template
<
template
<
typename
>
class
ALLOC
>
111
INLINE
void
Apriori
<
ALLOC
>::
setWeight
(
const
double
weight
) {
112
if
(
weight
< 0.0) {
113
GUM_ERROR
(
OutOfBounds
,
"A negative weight ("
<<
weight
<<
") is forbidden for an apriori"
);
114
}
115
weight_
=
weight
;
116
}
117
118
119
/// returns the weight assigned to the apriori
120
template
<
template
<
typename
>
class
ALLOC
>
121
INLINE
double
Apriori
<
ALLOC
>::
weight
()
const
{
122
return
weight_
;
123
}
124
125
126
/// returns the allocator used by the translator
127
template
<
template
<
typename
>
class
ALLOC
>
128
INLINE
typename
Apriori
<
ALLOC
>::
allocator_type
Apriori
<
ALLOC
>::
getAllocator
()
const
{
129
return
*
this
;
130
}
131
132
133
}
/* namespace learning */
134
135
}
/* namespace gum */
136
137
#
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