aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
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-2025 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-2025 *
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
57
58namespace gum {
59
60 namespace learning {
67
68 constexpr const char* priorTypeToString(PriorType e) noexcept {
69 switch (e) {
70 case PriorType::NoPriorType : return "No prior";
71 case PriorType::DirichletPriorType : return "Dirichlet prior";
72 case PriorType::SmoothingPriorType : return "TriSmoothing prior";
73 case PriorType::BDeuPriorType : return "BDeu prior";
74 }
75 return "Error in prior";
76 }
77
83 class Prior {
84 public:
85 // ##########################################################################
87 // ##########################################################################
89
91
101 explicit Prior(const DatabaseTable& database,
102 const Bijection< NodeId, std::size_t >& nodeId2columns
104
106 virtual Prior* clone() const = 0;
107
109 virtual ~Prior();
110
112
113 // ##########################################################################
115 // ##########################################################################
117
119 virtual void setWeight(double weight);
120
122 double weight() const;
123
125 virtual PriorType getType() const = 0;
126
128
135 virtual bool isInformative() const = 0;
136
138
143 virtual void addJointPseudoCount(const IdCondSet& idset, std::vector< double >& counts) = 0;
144
150 virtual void addConditioningPseudoCount(const IdCondSet& idset, std::vector< double >& counts)
151 = 0;
152
154
155
156 protected:
158 double weight_{1.0};
159
162
166
167
169 Prior(const Prior& from);
170
172 Prior(Prior&& from);
173
175 Prior& operator=(const Prior& from);
176
179 };
180
181 } /* namespace learning */
182
183} /* namespace gum */
184
185// include the inlined functions if necessary
186#ifndef GUM_NO_INLINE
188#endif /* GUM_NO_INLINE */
189
190#endif /* GUM_LEARNING_PRIOR_H */
The class representing a tabular database as used by learning tasks.
A class for storing a pair of sets of NodeIds, the second one corresponding to a conditional set.
Definition idCondSet.h:214
virtual bool isInformative() const =0
indicates whether the prior is tensorly informative
Prior(Prior &&from)
move constructor
virtual void addJointPseudoCount(const IdCondSet &idset, std::vector< double > &counts)=0
adds the prior to a counting vector corresponding to the idset
Prior & operator=(const Prior &from)
copy operator
virtual void setWeight(double weight)
sets the weight of the a prior(kind of effective sample size)
Prior(const Prior &from)
copy constructor
Prior(const DatabaseTable &database, const Bijection< NodeId, std::size_t > &nodeId2columns=Bijection< NodeId, std::size_t >())
default constructor
const DatabaseTable * database_
a reference to the database in order to have access to its variables
Definition prior.h:161
double weight_
the weight of the prior
Definition prior.h:158
virtual PriorType getType() const =0
returns the type of the prior
virtual ~Prior()
destructor
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:165
Prior & operator=(Prior &&from)
move operator
virtual Prior * clone() const =0
virtual copy constructor
double weight() const
returns the weight assigned to the prior
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
The class representing a tabular database stored in RAM.
A class used by learning caches to represent uniquely sets of variables.
include the inlined functions if necessary
Definition CSVParser.h:54
constexpr const char * priorTypeToString(PriorType e) noexcept
Definition prior.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
the base class for all a prioris