aGrUM 3.1.1
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-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
57
58namespace gum::learning {
65
66 constexpr const char* priorTypeToString(PriorType e) noexcept {
67 switch (e) {
68 case PriorType::NoPriorType : return "No prior";
69 case PriorType::DirichletPriorType : return "Dirichlet prior";
70 case PriorType::SmoothingPriorType : return "TriSmoothing prior";
71 case PriorType::BDeuPriorType : return "BDeu prior";
72 }
73 return "Error in prior";
74 }
75
81 class Prior {
82 public:
83 // ##########################################################################
85 // ##########################################################################
87
89
99 explicit Prior(const DatabaseTable& database,
100 const Bijection< NodeId, std::size_t >& nodeId2columns
102
104 [[nodiscard]] virtual Prior* clone() const = 0;
105
107 virtual ~Prior();
108
110
111 // ##########################################################################
113 // ##########################################################################
115
117 virtual void setWeight(double weight);
118
120 double weight() const;
121
123 virtual PriorType getType() const = 0;
124
126
133 virtual bool isInformative() const = 0;
134
136
141 virtual void addJointPseudoCount(const IdCondSet& idset, std::vector< double >& counts) = 0;
142
148 virtual void addConditioningPseudoCount(const IdCondSet& idset, std::vector< double >& counts)
149 = 0;
150
152
153
154 protected:
156 double weight_{1.0};
157
160
164
165
167 Prior(const Prior& from);
168
170 Prior(Prior&& from) noexcept;
171
173 Prior& operator=(const Prior& from);
174
176 Prior& operator=(Prior&& from) noexcept;
177 };
178
179} /* namespace gum::learning */
180
181// include the inlined functions if necessary
182// constexpr priorTypeToString must be visible in all TUs — include unconditionally
183#ifndef GUM_NO_INLINE
185#endif // GUM_NO_INLINE
186
187#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 potentially informative
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:159
Prior & operator=(Prior &&from) noexcept
move operator
double weight_
the weight of the prior
Definition prior.h:156
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:163
virtual Prior * clone() const =0
virtual copy constructor
double weight() const
returns the weight assigned to the prior
Prior(Prior &&from) noexcept
move constructor
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:55
constexpr const char * priorTypeToString(PriorType e) noexcept
Definition prior.h:66
the base class for all a prioris