aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
prior.h
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 by *
5
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
6
* - Christophe GONZALES(_at_AMU) *
7
* *
8
* The aGrUM/pyAgrum library is free software; you can redistribute it *
9
* and/or modify it under the terms of either : *
10
* *
11
* - the GNU Lesser General Public License as published by *
12
* the Free Software Foundation, either version 3 of the License, *
13
* or (at your option) any later version, *
14
* - the MIT license (MIT), *
15
* - or both in dual license, as here. *
16
* *
17
* (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18
* *
19
* This aGrUM/pyAgrum library is distributed in the hope that it will be *
20
* useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26
* OTHER DEALINGS IN THE SOFTWARE. *
27
* *
28
* See LICENCES for more details. *
29
* *
30
* SPDX-FileCopyrightText: Copyright 2005-2026 *
31
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
32
* - Christophe GONZALES(_at_AMU) *
33
* SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34
* *
35
* Contact : info_at_agrum_dot_org *
36
* homepage : http://agrum.gitlab.io *
37
* gitlab : https://gitlab.com/agrumery/agrum *
38
* *
39
****************************************************************************/
40
41
47
#ifndef GUM_LEARNING_PRIOR_H
48
#define GUM_LEARNING_PRIOR_H
49
50
#include <string>
51
#include <vector>
52
53
#include <
agrum/agrum.h
>
54
55
#include <
agrum/base/database/databaseTable.h
>
56
#include <
agrum/base/stattests/idCondSet.h
>
57
58
namespace
gum::learning
{
59
enum class
PriorType
: uint8_t {
60
DirichletPriorType
,
61
SmoothingPriorType
,
62
NoPriorType
,
63
BDeuPriorType
,
64
};
65
66
// constexpr requires the full definition to be visible in every TU that
67
// evaluates it at compile time, so -- unlike an ordinary INLINE method --
68
// this cannot be moved to prior_inl.h behind the GUM_NO_INLINE toggle.
69
constexpr
const
char
*
priorTypeToString
(
PriorType
e)
noexcept
{
70
switch
(e) {
71
case
PriorType::NoPriorType
:
return
"No prior"
;
72
case
PriorType::DirichletPriorType
:
return
"Dirichlet prior"
;
73
case
PriorType::SmoothingPriorType
:
return
"TriSmoothing prior"
;
74
case
PriorType::BDeuPriorType
:
return
"BDeu prior"
;
75
}
76
return
"Error in prior"
;
77
}
78
84
class
GUM_SHARED_PUBLIC
Prior
{
85
public
:
86
// ##########################################################################
88
// ##########################################################################
90
92
102
explicit
Prior
(
const
DatabaseTable
& database,
103
const
Bijection< NodeId, std::size_t >
& nodeId2columns
104
=
Bijection< NodeId, std::size_t >
());
105
107
[[nodiscard]]
virtual
Prior
*
clone
()
const
= 0;
108
110
virtual
~Prior
();
111
113
114
// ##########################################################################
116
// ##########################################################################
118
120
virtual
void
setWeight
(
double
weight
);
121
123
double
weight
()
const
;
124
126
virtual
PriorType
getType
()
const
= 0;
127
129
136
virtual
bool
isInformative
()
const
= 0;
137
139
144
virtual
void
addJointPseudoCount
(
const
IdCondSet
& idset, std::vector< double >& counts) = 0;
145
151
virtual
void
addConditioningPseudoCount
(
const
IdCondSet
& idset, std::vector< double >& counts)
152
= 0;
153
155
156
157
protected
:
159
double
weight_
{1.0};
160
162
const
DatabaseTable
*
database_
;
163
166
Bijection< NodeId, std::size_t >
nodeId2columns_
;
167
168
170
Prior
(
const
Prior
& from);
171
173
Prior
(
Prior
&& from)
noexcept
;
174
176
Prior
&
operator=
(
const
Prior
& from);
177
179
Prior
&
operator=
(
Prior
&& from)
noexcept
;
180
};
181
182
}
/* namespace gum::learning */
183
184
// include the inlined functions if necessary
185
#ifndef GUM_NO_INLINE
186
# include <
agrum/base/stattests/priors/prior_inl.h
>
187
#endif
// GUM_NO_INLINE
188
189
#endif
/* GUM_LEARNING_PRIOR_H */
agrum.h
gum::Bijection< NodeId, std::size_t >
gum::learning::DatabaseTable
The class representing a tabular database as used by learning tasks.
Definition
databaseTable.h:200
gum::learning::IdCondSet
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
Definition
idCondSet.h:214
gum::learning::Prior::isInformative
virtual bool isInformative() const =0
indicates whether the prior is potentially informative
gum::learning::Prior::addJointPseudoCount
virtual void addJointPseudoCount(const IdCondSet &idset, std::vector< double > &counts)=0
adds the prior to a counting vector corresponding to the idset
gum::learning::Prior::operator=
Prior & operator=(const Prior &from)
copy operator
gum::learning::Prior::setWeight
virtual void setWeight(double weight)
sets the weight of the a prior(kind of effective sample size)
gum::learning::Prior::Prior
Prior(const Prior &from)
copy constructor
gum::learning::Prior::Prior
Prior(const DatabaseTable &database, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
gum::learning::Prior::database_
const DatabaseTable * database_
a reference to the database in order to have access to its variables
Definition
prior.h:162
gum::learning::Prior::operator=
Prior & operator=(Prior &&from) noexcept
move operator
gum::learning::Prior::weight_
double weight_
the weight of the prior
Definition
prior.h:159
gum::learning::Prior::getType
virtual PriorType getType() const =0
returns the type of the prior
gum::learning::Prior::~Prior
virtual ~Prior()
destructor
gum::learning::Prior::nodeId2columns_
Bijection< NodeId, std::size_t > nodeId2columns_
a mapping from the NodeIds of the variables to the indices of the columns in the database
Definition
prior.h:166
gum::learning::Prior::clone
virtual Prior * clone() const =0
virtual copy constructor
gum::learning::Prior::weight
double weight() const
returns the weight assigned to the prior
gum::learning::Prior::Prior
Prior(Prior &&from) noexcept
move constructor
gum::learning::Prior::addConditioningPseudoCount
virtual void addConditioningPseudoCount(const IdCondSet &idset, std::vector< double > &counts)=0
adds the prior to a counting vector defined over the right hand side of the idset
databaseTable.h
The class representing a tabular database stored in RAM.
idCondSet.h
A class used by learning caches to represent uniquely sets of variables.
gum::learning
include the inlined functions if necessary
Definition
CSVParser.h:55
gum::learning::PriorType
PriorType
Definition
prior.h:59
gum::learning::PriorType::SmoothingPriorType
@ SmoothingPriorType
Definition
prior.h:61
gum::learning::PriorType::BDeuPriorType
@ BDeuPriorType
Definition
prior.h:63
gum::learning::PriorType::NoPriorType
@ NoPriorType
Definition
prior.h:62
gum::learning::PriorType::DirichletPriorType
@ DirichletPriorType
Definition
prior.h:60
gum::learning::priorTypeToString
constexpr const char * priorTypeToString(PriorType e) noexcept
Definition
prior.h:69
prior_inl.h
the base class for all a prioris
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0