aGrUM 2.3.2
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-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_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
60namespace gum {
61
66 template < typename GUM_SCALAR = float >
68 public:
69 // ##########################################################################
71 // ##########################################################################
72
74
76
79 ContinuousVariable(const std::string& aName,
80 const std::string& aDesc,
81 GUM_SCALAR lower_bound = -std::numeric_limits< GUM_SCALAR >::infinity(),
82 GUM_SCALAR upper_bound = std::numeric_limits< GUM_SCALAR >::infinity());
83
86
88 template < typename TX_VAL >
90
93
96
100
102
103
104 // ##########################################################################
106 // ##########################################################################
107
109
112
114 template < typename TX_VAL >
116
119
121
124 GUM_SCALAR operator[](const std::string& str) const;
125
127
128
129 // ##########################################################################
131 // ##########################################################################
132
134
136 GUM_SCALAR lowerBound() const;
137
139 virtual double lowerBoundAsDouble() const;
140
142 GUM_SCALAR upperBound() const;
143
145 virtual double upperBoundAsDouble() const;
146
148
150 void setLowerBound(const GUM_SCALAR& new_bound);
151
153
155 virtual void setLowerBoundFromDouble(const double new_bound);
156
158
160 void setUpperBound(const GUM_SCALAR& new_bound);
161
163
165 virtual void setUpperBoundFromDouble(const double new_bound);
166
168
173 virtual std::string label(const GUM_SCALAR& value) const;
174
176 bool belongs(const GUM_SCALAR& value) const;
177
179 std::string domain() const final;
180
182 virtual VarType varType() const;
183
185 std::string toString() const;
186
189
191
192
193 private:
195
198 bool _checkSameDomain_(const Variable& aRV) const final;
199
200 // the lower bound.
201 GUM_SCALAR _lower_bound_;
202
203 // the upper bound.
204 GUM_SCALAR _upper_bound_;
205
206 template < typename TX_VAL >
208 };
209
211 template < typename T_VAL >
212 std::ostream& operator<<(std::ostream&, const ContinuousVariable< T_VAL >&);
213
214
215 // specialized operator[] for real numbers
216 template <>
217 float ContinuousVariable< float >::operator[](const std::string& str) const;
218
219 template <>
220 double ContinuousVariable< double >::operator[](const std::string& str) const;
221
222
223} /* namespace gum */
224
225// always include the template implementation
226#include <agrum/base/variables/continuousVariable_tpl.h>
227
228#ifndef GUM_NO_INLINE
230#endif /* GUM_NO_INLINE */
231
232#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.
virtual VarType varType() const
returns the type of the variable
virtual double lowerBoundAsDouble() const
returns the lower bound of the domain of the variable as a double
GUM_SCALAR upperBound() const
returns the upper bound of the domain of the variable
ContinuousVariable(const ContinuousVariable< GUM_SCALAR > &from)
Copy Constructor.
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
GUM_SCALAR operator[](const std::string &str) const
returns the T_VAL corresponding to a string
ContinuousVariable(const std::string &aName, const std::string &aDesc, GUM_SCALAR lower_bound=-std::numeric_limits< GUM_SCALAR >::infinity(), GUM_SCALAR upper_bound=std::numeric_limits< GUM_SCALAR >::infinity())
Default constructor.
GUM_SCALAR lowerBound() const
returns the lower bound of the domain of the variable
ContinuousVariable(const ContinuousVariable< TX_VAL > &from)
generalized copy constructor
virtual void setUpperBoundFromDouble(const double new_bound)
updates the lower bound of the domain of the variable
ContinuousVariable< GUM_SCALAR > & operator=(ContinuousVariable< GUM_SCALAR > &&from)
move operator
virtual void setLowerBoundFromDouble(const double new_bound)
updates the lower bound of the domain of the variable
virtual ~ContinuousVariable()
destructor
ContinuousVariable< GUM_SCALAR > & operator=(const ContinuousVariable< GUM_SCALAR > &from)
copy operator
bool _checkSameDomain_(const Variable &aRV) const final
check the domain
virtual ContinuousVariable< GUM_SCALAR > * clone() const
Copy Factory.
ContinuousVariable< GUM_SCALAR > & operator=(const ContinuousVariable< TX_VAL > &from)
generalized copy operator
ContinuousVariable(ContinuousVariable< GUM_SCALAR > &&from)
move constructor
virtual double upperBoundAsDouble() const
returns the upper bound of the domain of the variable as a double
IContinuousVariable(const std::string &aName, const std::string &aDesc)
Default constructor.
Base class for every random variable.
Definition variable.h:79
The databases' cell translators for continuous variables.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
VarType
Definition variable.h:60
STL namespace.