aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DBTranslator4ContinuousVariable_tpl.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
48#ifndef DOXYGEN_SHOULD_SKIP_THIS
49
50# include <limits>
51# include <utility>
52# include <vector>
53
56
57namespace gum {
58
59 namespace learning {
60
62 template < typename GUM_SCALAR >
64 const ContinuousVariable< GUM_SCALAR >& var,
65 const std::vector< std::string >& missing_symbols,
66 const bool fit_range) :
67 DBTranslator(DBTranslatedValueType::CONTINUOUS, true, missing_symbols, fit_range, 1),
68 _variable_(var.name(), var.description()), _fit_range_(fit_range) {
69 // get the bounds of the range variable
70 const float lower_bound = float(var.lowerBound());
71 const float upper_bound = float(var.upperBound());
72 _variable_.setLowerBound(lower_bound);
73 _variable_.setUpperBound(upper_bound);
74
75 // remove all the missing symbols corresponding to a number between
76 // lower_bound and upper_bound
77 bool non_float_symbol_found = false;
78 for (auto iter = this->missing_symbols_.beginSafe(); iter != this->missing_symbols_.endSafe();
79 ++iter) {
80 if (DBCell::isReal(*iter)) {
81 const float missing_val = std::stof(*iter);
82 if ((missing_val >= lower_bound) && (missing_val <= upper_bound)) {
83 this->missing_symbols_.erase(iter);
84 } else _status_float_missing_symbols_.insert(*iter, false);
85 } else if (!non_float_symbol_found) {
86 non_float_symbol_found = true;
87 _nonfloat_missing_symbol_ = *iter;
88 }
89 }
90
91 // store a copy of the variable, that should be used by method variable ()
92 _real_variable_ = var.clone();
93
94 GUM_CONSTRUCTOR(DBTranslator4ContinuousVariable);
95 }
96
98 template < typename GUM_SCALAR >
99 DBTranslator4ContinuousVariable::DBTranslator4ContinuousVariable(
100 const ContinuousVariable< GUM_SCALAR >& var,
101 const bool fit_range) :
102 DBTranslator(DBTranslatedValueType::CONTINUOUS, true, fit_range, 1),
103 _variable_(var.name(), var.description()), _fit_range_(fit_range) {
104 // get the bounds of the range variable
105 const float lower_bound = float(var.lowerBound());
106 const float upper_bound = float(var.upperBound());
107 _variable_.setLowerBound(lower_bound);
108 _variable_.setUpperBound(upper_bound);
109
110 // store a copy of the variable, that should be used by method variable ()
111 _real_variable_ = var.clone();
112
113 GUM_CONSTRUCTOR(DBTranslator4ContinuousVariable);
114 }
115
116 } /* namespace learning */
117
118} /* namespace gum */
119
120
121#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The class representing the original values of the cells of databases.
The databases' cell translators for continuous variables.
DBTranslator4ContinuousVariable(const std::vector< std::string > &missing_symbols, const bool fit_range=false)
default constructor without any initial variable
The base class for all the tabular database cell translators.
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46