aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
discretizedVariable.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
42#ifndef GUM_DISCRETIZED_VARIABLE_H
43#define GUM_DISCRETIZED_VARIABLE_H
44
45#include <vector>
46
47#include <agrum/agrum.h>
48
50
51namespace gum {
75 template < typename T_TICKS >
77 private:
78 std::vector< T_TICKS > _ticks_; // Array from 0 to domainSize-2
79
80 protected:
86
92 Idx pos_(const T_TICKS& target) const;
93
94 public:
98
104 DiscretizedVariable(const std::string& aName, const std::string& aDesc);
105
114 DiscretizedVariable(const std::string& aName,
115 const std::string& aDesc,
116 const std::vector< T_TICKS >& ticks,
117 bool is_empirical = false);
118
124
128 ~DiscretizedVariable() override final;
129
131
133 DiscretizedVariable< T_TICKS >* clone() const override;
134
136 VarType varType() const override;
137
143 DiscretizedVariable< T_TICKS >& operator=(const DiscretizedVariable< T_TICKS >& aDRV);
144
150 bool isTick(const T_TICKS& aTick) const;
151
157 DiscretizedVariable& addTick(const T_TICKS& aTick);
158
163
169 std::string label(Idx i) const override;
170
172 double numerical(Idx indice) const override;
173
175 double draw(Idx indice) const override;
176
179 Idx index(const std::string& label) const override;
182 Idx index(const T_TICKS tick) const;
183
188 Size domainSize() const override;
189
190 std::string domain() const override;
191
193 std::string stype() const override final { return "Discretized"; };
194
197 const T_TICKS& tick(Idx i) const;
198
200 const std::vector< T_TICKS >& ticks() const;
201
203 std::vector< double > ticksAsDoubles() const override;
204
206 Idx closestIndex(double val) const override;
207
208 // returns the variable in fast syntax
209 std::string toFast() const override;
210
211 private:
213
216 bool _checkSameDomain_(const Variable& aRV) const override;
217 };
218
219} /* namespace gum */
220
223
224#endif /* GUM_DISCRETIZED_VARIABLE_H */
VarType varType() const override
returns the type of variable
DiscretizedVariable< T_TICKS > * clone() const override
a virtual clone
std::string label(Idx i) const override
const T_TICKS & tick(Idx i) const
from the index to the tick.
std::vector< T_TICKS > _ticks_
Size domainSize() const override
std::string domain() const override
string represent the domain of the variable
Idx index(const std::string &label) const override
from the label to its index in var.
DiscretizedVariable(const std::string &aName, const std::string &aDesc)
Constructor.
~DiscretizedVariable() override final
Destructor.
double numerical(Idx indice) const override
get a (deterministic) numerical representation of he indice-the value.
bool isTick(const T_TICKS &aTick) const
const std::vector< T_TICKS > & ticks() const
Return the list of ticks.
void copy_(const DiscretizedVariable< T_TICKS > &aDRV)
make a copy
double draw(Idx indice) const override
get a random value in the intervall indice
DiscretizedVariable(const DiscretizedVariable< T_TICKS > &aDRV)
Copy constructor.
void eraseTicks()
erase all the Ticks
Idx pos_(const T_TICKS &target) const
search the class of target (internally use dichotomy_)
Idx closestIndex(double val) const override
returns the closest index of the value
bool _checkSameDomain_(const Variable &aRV) const override
check the domain
DiscretizedVariable(const std::string &aName, const std::string &aDesc, const std::vector< T_TICKS > &ticks, bool is_empirical=false)
Constructor.
std::string toFast() const override
std::string stype() const override final
string represent the type of the variable
std::vector< double > ticksAsDoubles() const override
return the list of ticks as a vector of doubles
DiscretizedVariable & addTick(const T_TICKS &aTick)
add a tick.
IDiscretizedVariable(const std::string &aName, const std::string &aDesc)
Default constructor.
Base class for every random variable.
Definition variable.h:79
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
VarType
Definition variable.h:60
STL namespace.