aGrUM 2.3.2
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-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
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
59namespace gum {
60 /* ===========================================================================
61 */
62 /* ===========================================================================
63 */
64 /* === GUM_DISCRETE_VARIABLE ===
65 */
66 /* ===========================================================================
67 */
68 /* ===========================================================================
69 */
75 /* ===========================================================================
76 */
77
78 class DiscreteVariable: public Variable {
79 public:
80 // ############################################################################
82 // ############################################################################
84
86
87 DiscreteVariable(const std::string& aName, const std::string& aDesc);
88
90
97
100
103 DiscreteVariable* clone() const override = 0;
104
106
107 // ############################################################################
109 // ############################################################################
111
113 bool empty() const;
114
116 virtual Size domainSize() const = 0;
117
119 std::vector< std::string > labels() const;
120
122 virtual double numerical(Idx indice) const = 0;
123
124 virtual bool isEmpirical() const { return false; };
125
127 virtual Idx closestIndex(double val) const = 0;
129 std::string closestLabel(double val) const;
130
132 VarType varType() const override = 0;
133
134 // returns the variable in fast syntax
135 virtual std::string toFast() const = 0;
136
138
139 // ############################################################################
141 // ############################################################################
143
145
147
149
151
156 Idx operator[](const std::string& label) const { return index(label); };
157
158 virtual Idx index(const std::string& label) const = 0;
159
161
164 virtual std::string label(Idx i) const = 0;
165
167 std::string toString() const;
168
170 std::string toStringWithDescription() const;
171
173 std::string domain() const override = 0;
174
176 virtual std::string stype() const = 0;
177
178 protected:
180 DiscreteVariable() { GUM_CONSTRUCTOR(DiscreteVariable) }
181 };
182
184
185 std::ostream& operator<<(std::ostream&, const DiscreteVariable&);
186
188} /* namespace gum */
189
190#ifndef GUM_NO_INLINE
192#endif /* GUM_NO_INLINE */
193
194#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.
virtual bool isEmpirical() const
virtual std::string toFast() const =0
DiscreteVariable(const std::string &aName, const std::string &aDesc)
Default constructor.
virtual Idx index(const std::string &label) 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.
Idx operator[](const std::string &label) const
from the label to its index in var.
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.
~DiscreteVariable() override
destructor
std::string closestLabel(double val) const
for numerical variables, returns the closest label for the value
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:131
Variable()
(protected) Default constructor
Definition variable.h:143
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
Definition AVLTree.h:913
VarType
Definition variable.h:60
Sets of elements (i.e.
Base class for random variable.