aGrUM 3.1.1
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-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#pragma once
42
43
49#include <agrum/base/database/DBTranslator4ContinuousVariable.h> // to ease IDE parser
50#ifndef DOXYGEN_SHOULD_SKIP_THIS
51
52# include <limits>
53# include <utility>
54# include <vector>
55
58
59namespace gum {
60
61 namespace learning {
62
64 template < GUM_Numeric GUM_SCALAR >
66 const ContinuousVariable< GUM_SCALAR >& var,
67 const std::vector< std::string >& missing_symbols,
68 const bool fit_range) :
69 DBTranslator(DBTranslatedValueType::CONTINUOUS, true, missing_symbols, fit_range, 1),
70 _variable_(var.name(), var.description()), _fit_range_(fit_range) {
71 // get the bounds of the range variable
72 const float lower_bound = float(var.lowerBound());
73 const float upper_bound = float(var.upperBound());
74 _variable_.setLowerBound(lower_bound);
75 _variable_.setUpperBound(upper_bound);
76
77 // remove all the missing symbols corresponding to a number between
78 // lower_bound and upper_bound
79 bool non_float_symbol_found = false;
80 for (auto iter = this->missing_symbols_.beginSafe(); iter != this->missing_symbols_.endSafe();
81 ++iter) {
82 if (DBCell::isReal(*iter)) {
83 const float missing_val = std::stof(*iter);
84 if ((missing_val >= lower_bound) && (missing_val <= upper_bound)) {
85 this->missing_symbols_.erase(iter);
86 } else _status_float_missing_symbols_.insert(*iter, false);
87 } else if (!non_float_symbol_found) {
88 non_float_symbol_found = true;
89 _nonfloat_missing_symbol_ = *iter;
90 }
91 }
92
93 // store a copy of the variable, that should be used by method variable ()
94 _real_variable_ = var.clone();
95
96 GUM_CONSTRUCTOR(DBTranslator4ContinuousVariable);
97 }
98
100 template < GUM_Numeric GUM_SCALAR >
101 DBTranslator4ContinuousVariable::DBTranslator4ContinuousVariable(
102 const ContinuousVariable< GUM_SCALAR >& var,
103 const bool fit_range) :
104 DBTranslator(DBTranslatedValueType::CONTINUOUS, true, fit_range, 1),
105 _variable_(var.name(), var.description()), _fit_range_(fit_range) {
106 // get the bounds of the range variable
107 const float lower_bound = float(var.lowerBound());
108 const float upper_bound = float(var.upperBound());
109 _variable_.setLowerBound(lower_bound);
110 _variable_.setUpperBound(upper_bound);
111
112 // store a copy of the variable, that should be used by method variable ()
113 _real_variable_ = var.clone();
114
115 GUM_CONSTRUCTOR(DBTranslator4ContinuousVariable);
116 }
117
118 } /* namespace learning */
119
120} /* namespace gum */
121
122
123#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:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46