aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
DBTranslatedValue.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief The union class for storing the translated values in learning databases
24  *
25  * When learning models from databases, it is necessary to preprocess the
26  * data, i.e., transform them in such a way that their analysis can be
27  * performed as quickly as possible. The purpose of the DBTranslatedValue type
28  * is to enable such a fast analysis.
29  *
30  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
31  */
32 #ifndef GUM_LEARNING_DB_TRANSLATED_VALUE_H
33 #define GUM_LEARNING_DB_TRANSLATED_VALUE_H
34 
35 #include <cstddef>
36 #include <agrum/agrum.h>
37 
38 
39 namespace gum {
40 
41  namespace learning {
42 
43  /** @union DBTranslatedValue
44  * @headerfile DBTranslatedValue.h <agrum/tools/database/DBTranslatedValue.h>
45  * @brief The union class for storing the translated values in learning
46  * databases
47  *
48  * In aGrUM, learning is performed on datasets that are preprocessed, i.e.,
49  * their values are encoded in such a way that learning is fast. More
50  * precisely, the values of discrete random variables are encoded as
51  * integers ranging from 0 to the domain size minus 1 of the variable, and
52  * the values of continuous random variables are encoded as floating point
53  * numbers. Missing values are encoded as std::numeric_limits<>::max() over
54  * these types. The DBTranslatedValue class is the representation of these
55  * types.
56  *
57  * @par Usage example:
58  * @code
59  * // create a discrete value equal to 3 and a continuous value equal to 4.5
60  * gum::learning::DBTranslatedValue x1 { std::size_t(3) };
61  * gum::learning::DBTranslatedValue x2 { 4.5f };
62  *
63  * // access these elements and display them
64  * std::cout << x1.discr_val << " " << x2.cont_val << std::endl;
65  * @endcode
66  *
67  * @ingroup learning_database */
69  /// the field for storing discrete values
70  std::size_t discr_val;
71 
72  /// the field for storing continuous values
73  float cont_val;
74 
75 
76  // ##########################################################################
77  /// @name Constructors / Destructors
78  // ##########################################################################
79 
80  /// @{
81 
82  /// default constructor: stores discrete value 0
83  constexpr DBTranslatedValue() : discr_val{std::size_t(0)} {}
84 
85  /// the constructor for storing a continuous value
86  constexpr DBTranslatedValue(const float& val) : cont_val{val} {}
87 
88  /// the constructor for storing a discrete value
89  constexpr DBTranslatedValue(const std::size_t& val) : discr_val{val} {}
90 
91  /// destructor
93 
94  /// @}
95  };
96 
97 
98  /** @enum DBTranslatedValueType
99  * @headerfile DBTranslatedValue.h <agrum/tools/database/DBTranslatedValue.h>
100  * @brief The nature of the elements handled by translators (discrete,
101  * continuous).
102  *
103  * @code
104  * #include <agrum/tools/database/DBTranslatedValue.h>
105  * @endcode
106  *
107  * Currently, a DBTranslatorType is one of:
108  * - DBTranslatedValueType::DISCRETE
109  * - DBTranslatedValueType::CONTINUOUS
110  *
111  * Each DBTranslator has a DBTranslatedValueType that indicates whether it
112  * handles a discrete or a continuous variable. As a result, when the
113  * DBTranslator translates a string into a DBTranslatedValue, to access the
114  * content of the latter, you should use either the discr_val field of the
115  * DBTranslatedValue if the DBTranslatedValueType of the translator is
116  * DISCRETE or the cont_val field if the translator is CONTINUOUS.
117  *
118  * @ingroup learning_database
119  */
120  enum class DBTranslatedValueType : char
121  {
122  DISCRETE,
123  CONTINUOUS
124  };
125 
126 
127  } /* namespace learning */
128 
129 } /* namespace gum */
130 
131 #endif /* GUM_LEARNING_DB_TRANSLATED_VALUE_H */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
std::size_t discr_val
the field for storing discrete values
The union class for storing the translated values in learning databases.
float cont_val
the field for storing continuous values
constexpr DBTranslatedValue()
default constructor: stores discrete value 0
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
constexpr DBTranslatedValue(const std::size_t &val)
the constructor for storing a discrete value
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
constexpr DBTranslatedValue(const float &val)
the constructor for storing a continuous value