aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
continuousVariable.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_CONTINUOUS_VARIABLE_H
49#define GUM_CONTINUOUS_VARIABLE_H
50
51#include <iostream>
52#include <limits>
53#include <sstream>
54#include <string>
55
56#include <agrum/agrum.h>
57
59
60#include <string_view>
61
62namespace gum {
63
68 template < GUM_Numeric GUM_SCALAR = float >
70 public:
71 // ##########################################################################
73 // ##########################################################################
74
76
78
81 ContinuousVariable(std::string_view aName,
82 std::string_view aDesc,
83 GUM_SCALAR lower_bound = -std::numeric_limits< GUM_SCALAR >::infinity(),
84 GUM_SCALAR upper_bound = std::numeric_limits< GUM_SCALAR >::infinity());
85
88
90 template < typename TX_VAL >
92
95
98
101 [[nodiscard]] ContinuousVariable< GUM_SCALAR >* clone() const override;
102
104
105
106 // ##########################################################################
108 // ##########################################################################
109
111
114
116 template < typename TX_VAL >
118
121
123
126 GUM_SCALAR operator[](std::string_view str) const;
127
129
130
131 // ##########################################################################
133 // ##########################################################################
134
136
138 GUM_SCALAR lowerBound() const;
139
141 double lowerBoundAsDouble() const override;
142
144 GUM_SCALAR upperBound() const;
145
147 double upperBoundAsDouble() const override;
148
150
152 void setLowerBound(const GUM_SCALAR& new_bound);
153
155
157 void setLowerBoundFromDouble(const double new_bound) override;
158
160
162 void setUpperBound(const GUM_SCALAR& new_bound);
163
165
167 void setUpperBoundFromDouble(const double new_bound) override;
168
170
175 virtual std::string label(const GUM_SCALAR& value) const;
176
178 bool belongs(const GUM_SCALAR& value) const;
179
181 std::string domain() const final;
182
184 VarType varType() const override;
185
187 std::string toString() const;
188
191
193
194
195 private:
197
200 bool _checkSameDomain_(const Variable& aRV) const final;
201
202 // the lower bound.
203 GUM_SCALAR _lower_bound_;
204
205 // the upper bound.
206 GUM_SCALAR _upper_bound_;
207
208 template < GUM_Numeric TX_VAL >
210 };
211
213 template < typename T_VAL >
214 std::ostream& operator<<(std::ostream&, const ContinuousVariable< T_VAL >&);
215
216
217 // specialized operator[] for real numbers
218 template <>
219 float ContinuousVariable< float >::operator[](std::string_view str) const;
220
221 template <>
222 double ContinuousVariable< double >::operator[](std::string_view str) const;
223
224
225} /* namespace gum */
226
227// always include the template implementation
228#include <agrum/base/variables/continuousVariable_tpl.h>
229
230#ifndef GUM_NO_INLINE
232#endif /* GUM_NO_INLINE */
233
234#endif /* GUM_CONTINUOUS_VARIABLE_H */
Header of IContinuousVariable.
Defines a continuous random variable.
std::string domain() const final
returns the domain of the variable as a string
void setLowerBound(const GUM_SCALAR &new_bound)
updates the lower bound of the domain of the variable
std::string toStringWithDescription() const
string version of *this using description attribute instead of name.
bool belongs(const GUM_SCALAR &value) const
Returns true if the param belongs to the domain of the variable.
GUM_SCALAR upperBound() const
returns the upper bound of the domain of the variable
ContinuousVariable(const ContinuousVariable< GUM_SCALAR > &from)
Copy Constructor.
ContinuousVariable< GUM_SCALAR > * clone() const override
Copy Factory.
virtual std::string label(const GUM_SCALAR &value) const
returns a string containing the value of the variable passed in argument
std::string toString() const
string version of *this
void setUpperBound(const GUM_SCALAR &new_bound)
updates the lower bound of the domain of the variable
void setLowerBoundFromDouble(const double new_bound) override
updates the lower bound of the domain of the variable
GUM_SCALAR lowerBound() const
returns the lower bound of the domain of the variable
ContinuousVariable(const ContinuousVariable< TX_VAL > &from)
generalized copy constructor
ContinuousVariable< GUM_SCALAR > & operator=(ContinuousVariable< GUM_SCALAR > &&from)
move operator
VarType varType() const override
returns the type of the variable
ContinuousVariable< GUM_SCALAR > & operator=(const ContinuousVariable< GUM_SCALAR > &from)
copy operator
bool _checkSameDomain_(const Variable &aRV) const final
check the domain
double upperBoundAsDouble() const override
returns the upper bound of the domain of the variable as a double
ContinuousVariable(std::string_view aName, std::string_view aDesc, GUM_SCALAR lower_bound=-std::numeric_limits< GUM_SCALAR >::infinity(), GUM_SCALAR upper_bound=std::numeric_limits< GUM_SCALAR >::infinity())
Default constructor.
ContinuousVariable< GUM_SCALAR > & operator=(const ContinuousVariable< TX_VAL > &from)
generalized copy operator
double lowerBoundAsDouble() const override
returns the lower bound of the domain of the variable as a double
~ContinuousVariable() override
destructor
ContinuousVariable(ContinuousVariable< GUM_SCALAR > &&from)
move constructor
GUM_SCALAR operator[](std::string_view str) const
returns the T_VAL corresponding to a string
void setUpperBoundFromDouble(const double new_bound) override
updates the lower bound of the domain of the variable
IContinuousVariable(std::string_view aName, std::string_view aDesc)
Default constructor.
Base class for every random variable.
Definition variable.h:81
Complete concept for GUM_SCALAR template parameter.
Definition concepts.h:148
The databases' cell translators for continuous variables.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
VarType
Definition variable.h:62
STL namespace.