aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DBTranslator4ContinuousVariable_inl.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#pragma once
41
42
43#ifndef DOXYGEN_SHOULD_SKIP_THIS
44
46
47namespace gum {
48
49 namespace learning {
50
53 if (_real_variable_ != nullptr) delete _real_variable_;
54
55 GUM_DESTRUCTOR(DBTranslator4ContinuousVariable);
56 }
57
60 const DBTranslatedValue translated_val) const {
61 if (translated_val.cont_val == std::numeric_limits< float >::max()) {
62 if (!_nonfloat_missing_symbol_.empty()) return _nonfloat_missing_symbol_;
63 if (this->missing_symbols_.empty()) return *(this->missing_symbols_.begin());
64 }
65
66 if ((translated_val.cont_val < _variable_.lowerBound())
67 || (translated_val.cont_val > _variable_.upperBound())) {
68 GUM_ERROR(UnknownLabelInDatabase,
69 "The back translation of "
70 << translated_val.cont_val
71 << " could not be found because the value is outside the "
72 << "domain of the continuous variable");
73 }
74
75 char buffer[100];
76 snprintf(buffer, 100, "%g", translated_val.cont_val);
77 return std::string(buffer);
78 }
79
81 INLINE bool DBTranslator4ContinuousVariable::needsReordering() const { return false; }
82
84 INLINE HashTable< std::size_t, std::size_t > DBTranslator4ContinuousVariable::reorder() {
85 return HashTable< std::size_t, std::size_t >();
86 }
87
89 INLINE std::size_t DBTranslator4ContinuousVariable::domainSize() const {
90 return std::numeric_limits< std::size_t >::max();
91 }
92
94 INLINE const IContinuousVariable* DBTranslator4ContinuousVariable::variable() const {
95 _real_variable_->setLowerBoundFromDouble(_variable_.lowerBound());
96 _real_variable_->setUpperBoundFromDouble(_variable_.upperBound());
97 return _real_variable_;
98 }
99
102 return DBTranslatedValue{std::numeric_limits< float >::max()};
103 }
104
105 } /* namespace learning */
106
107} /* namespace gum */
108
109#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The class representing the original values of the cells of databases.
virtual void setLowerBoundFromDouble(const double new_bound)=0
updates the lower bound of the domain of the variable
DBTranslator4ContinuousVariable(const std::vector< std::string > &missing_symbols, const bool fit_range=false)
default constructor without any initial variable
virtual DBTranslatedValue missingValue() const final
returns the translation of a missing value
virtual HashTable< std::size_t, std::size_t > reorder() final
returns an empty mapping, indicating that old tanslations are equal to the newly reordered ones.
virtual bool needsReordering() const final
indicates that the translations should never be reordered
virtual std::string translateBack(const DBTranslatedValue translated_val) const final
returns the original value for a given translation
virtual const IContinuousVariable * variable() const final
returns the variable stored into the translator
virtual std::size_t domainSize() const final
returns std::numeric_limits<std::size_t>::max ()
Set< std::string > missing_symbols_
the set of missing symbols
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
The union class for storing the translated values in learning databases.