aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
DBTranslator4RangeVariable_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-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
50
#include <cstdio>
51
#include <limits>
52
#include <utility>
53
#include <vector>
54
55
#include <
agrum/base/database/DBCell.h
>
56
#include <
agrum/base/database/DBTranslator4RangeVariable.h
>
57
58
#ifndef DOXYGEN_SHOULD_SKIP_THIS
59
60
namespace
gum
{
61
62
namespace
learning
{
63
65
INLINE
DBTranslator4RangeVariable::~DBTranslator4RangeVariable
() {
66
GUM_DESTRUCTOR(
DBTranslator4RangeVariable
);
67
}
68
70
INLINE std::string
71
DBTranslator4RangeVariable::translateBack
(
const
DBTranslatedValue
translated_val)
const
{
72
try
{
73
return
this->
back_dico_
.
second
(translated_val.discr_val);
74
}
catch
(Exception
const
&) {
75
// check if this is a missing value
76
if
(translated_val.discr_val == std::numeric_limits< std::size_t >::max()) {
77
if
(!_nonint_missing_symbol_.empty())
return
_nonint_missing_symbol_;
78
if
(this->
missing_symbols_
.
empty
())
return
*(this->
missing_symbols_
.
begin
());
79
}
80
81
GUM_ERROR
(UnknownLabelInDatabase,
82
"The back translation of \""
<< translated_val.discr_val
83
<<
"\" could not be found"
);
84
}
85
}
86
88
90
INLINE std::size_t
DBTranslator4RangeVariable::domainSize
()
const
{
91
return
_variable_.domainSize();
92
}
93
95
INLINE
const
RangeVariable*
DBTranslator4RangeVariable::variable
()
const
{
return
&_variable_; }
96
98
INLINE
DBTranslatedValue
DBTranslator4RangeVariable::missingValue
()
const
{
99
return
DBTranslatedValue{std::numeric_limits< std::size_t >::max()};
100
}
101
102
103
}
/* namespace learning */
104
105
}
/* namespace gum */
106
107
108
#endif
/* DOXYGEN_SHOULD_SKIP_THIS */
DBCell.h
The class representing the original values of the cells of databases.
DBTranslator4RangeVariable.h
The databases' cell translators for range variables.
gum::BijectionImplementation< T1, T2, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::second
const T2 & second(const T1 &first) const
gum::Set::empty
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition
set_tpl.h:613
gum::Set::begin
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition
set_tpl.h:409
gum::learning::DBTranslator4RangeVariable::domainSize
std::size_t domainSize() const final
returns the domain size of a variable corresponding to the translations
gum::learning::DBTranslator4RangeVariable::DBTranslator4RangeVariable
DBTranslator4RangeVariable(const std::vector< std::string > &missing_symbols, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor without any initial variable
gum::learning::DBTranslator4RangeVariable::~DBTranslator4RangeVariable
~DBTranslator4RangeVariable() override
destructor
gum::learning::DBTranslator4RangeVariable::variable
const RangeVariable * variable() const final
returns the variable stored into the translator
gum::learning::DBTranslator4RangeVariable::missingValue
DBTranslatedValue missingValue() const final
returns the translation of a missing value
gum::learning::DBTranslator4RangeVariable::translateBack
std::string translateBack(const DBTranslatedValue translated_val) const final
returns the original value for a given translation
gum::learning::DBTranslator::back_dico_
Bijection< std::size_t, std::string > back_dico_
the bijection relating back translated values and their original strings.
Definition
DBTranslator.h:401
gum::learning::DBTranslator::missing_symbols_
Set< std::string > missing_symbols_
the set of missing symbols
Definition
DBTranslator.h:393
GUM_ERROR
#define GUM_ERROR(type, msg)
Definition
exceptions.h:76
gum::learning
include the inlined functions if necessary
Definition
CSVParser.h:55
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
gum::learning::DBTranslatedValue
The union class for storing the translated values in learning databases.
Definition
DBTranslatedValue.h:88
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0