aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
discreteVariable.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
48#ifndef GUM_DISCRETE_VARIABLE_H
49#define GUM_DISCRETE_VARIABLE_H
50
51#include <ostream>
52#include <string>
53
54#include <agrum/agrum.h>
55
56#include <agrum/base/core/set.h>
58
59#include <string_view>
60
61namespace gum {
62 /* ===========================================================================
63 */
64 /* ===========================================================================
65 */
66 /* === GUM_DISCRETE_VARIABLE ===
67 */
68 /* ===========================================================================
69 */
70 /* ===========================================================================
71 */
77 /* ===========================================================================
78 */
79
80 class DiscreteVariable: public Variable {
81 public:
82 // ############################################################################
84 // ############################################################################
86
88
89 DiscreteVariable(std::string_view aName, std::string_view aDesc);
90
92
99
102
105 [[nodiscard]] DiscreteVariable* clone() const override = 0;
106
108
109 // ############################################################################
111 // ############################################################################
113
115 bool empty() const;
116
118 virtual Size domainSize() const = 0;
119
121 std::vector< std::string > labels() const;
122
124 virtual double numerical(Idx indice) const = 0;
125
126 virtual bool isEmpirical() const;
127
129 bool isNumerical() const;
130
132 virtual Idx closestIndex(double val) const = 0;
134 virtual std::string closestLabel(double val) const;
135
137 VarType varType() const override = 0;
138
139 // returns the variable in fast syntax
140 virtual std::string toFast() const = 0;
141
143
144 // ############################################################################
146 // ############################################################################
148
150
152
154
156
161 Idx operator[](std::string_view label) const;
162
163 virtual Idx index(std::string_view label) const = 0;
164
166
169 virtual std::string label(Idx i) const = 0;
170
172 std::string toString() const;
173
175 std::string toStringWithDescription() const;
176
178 std::string domain() const override = 0;
179
181 virtual std::string stype() const = 0;
182
183 protected:
186 };
187
189
190 std::ostream& operator<<(std::ostream&, const DiscreteVariable&);
191
193} /* namespace gum */
194
195#ifndef GUM_NO_INLINE
197#endif /* GUM_NO_INLINE */
198
199#endif /* GUM_DISCRETE_VARIABLE_H */
Base class for discrete random variable.
std::string toStringWithDescription() const
string version of *this using description attribute instead of name.
DiscreteVariable(std::string_view aName, std::string_view aDesc)
Default constructor.
virtual bool isEmpirical() const
virtual std::string toFast() const =0
DiscreteVariable()
(protected) Default constructor
virtual Idx closestIndex(double val) const =0
for numerical variables, returns the closest index for the value
std::string toString() const
string version of *this
virtual double numerical(Idx indice) const =0
get a numerical representation of the indice-th value.
DiscreteVariable & operator=(const DiscreteVariable &aRV)
Copy operator.
std::vector< std::string > labels() const
vector of labels
VarType varType() const override=0
returns the varType of variable
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
virtual std::string closestLabel(double val) const
for numerical variables, returns the closest label for the value
Idx operator[](std::string_view label) const
from the label to its index in var.
virtual Idx index(std::string_view label) const =0
~DiscreteVariable() override
destructor
bool isNumerical() const
virtual std::string stype() const =0
string represent the type of the variable
DiscreteVariable * clone() const override=0
Copy Factory.
DiscreteVariable(const DiscreteVariable &aDRV)
Copy constructor.
virtual Size domainSize() const =0
std::string domain() const override=0
string represent the domain of the variable
Representation of a set.
Definition set.h:129
Variable()
(protected) Default constructor
Definition variable.h:145
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
VarType
Definition variable.h:62
Sets of elements (i.e.
Base class for random variable.