57#ifndef DOXYGEN_SHOULD_SKIP_THIS
65 template < GUM_Numeric GUM_SCALAR >
67 const DiscretizedVariable< GUM_SCALAR >& var,
68 const std::vector< std::string >& missing_symbols,
69 std::size_t max_dico_entries) :
75 _variable_(var.name(), var.description()) {
77 if (var.domainSize() > max_dico_entries) {
78 GUM_ERROR(SizeError,
"the dictionary induced by the variable is too large")
82 const auto& ticks = var.ticks();
83 for (
const auto tick: ticks) {
84 _variable_.addTick((
float)tick);
88 const auto lower_bound = (float)ticks[0];
89 const auto upper_bound = (float)ticks.back();
93 for (
auto iter = this->missing_symbols_.beginSafe(); iter != this->missing_symbols_.endSafe();
95 if (DBCell::isReal(*iter)) {
96 const float missing_val = std::stof(*iter);
97 if ((missing_val >= lower_bound) && (missing_val <= upper_bound)) {
98 this->missing_symbols_.erase(iter);
104 std::size_t size = 0;
105 for (
const auto& label: var.labels()) {
111 if (this->missing_symbols_.exists(label)) { this->missing_symbols_.erase(label); }
118 _real_variable_ = var.clone();
120 GUM_CONSTRUCTOR(DBTranslator4DiscretizedVariable);
124 template < GUM_Numeric GUM_SCALAR >
125 DBTranslator4DiscretizedVariable::DBTranslator4DiscretizedVariable(
126 const DiscretizedVariable< GUM_SCALAR >& var,
127 std::size_t max_dico_entries) :
128 DBTranslator(DBTranslatedValueType::
DISCRETE, false, false, max_dico_entries),
129 _variable_(var.name(), var.description()) {
131 if (var.domainSize() > max_dico_entries) {
132 GUM_ERROR(SizeError,
"the dictionary induced by the variable is too large")
136 const auto& ticks = var.ticks();
137 for (
const auto tick: ticks) {
138 _variable_.addTick((
float)tick);
142 std::size_t size = 0;
143 for (
const auto& label: var.labels()) {
144 this->back_dico_.insert(size, label);
149 _real_variable_ = var.clone();
151 GUM_CONSTRUCTOR(DBTranslator4DiscretizedVariable);
The class representing the original values of the cells of databases.
The databases' cell translators for discretized variables.
void insert(const T1 &first, const T2 &second)
DBTranslator4DiscretizedVariable(const DiscretizedVariable< GUM_SCALAR > &var, const std::vector< std::string > &missing_symbols, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor with a discretized variable as translator
The base class for all the tabular database cell translators.
Bijection< std::size_t, std::string > back_dico_
the bijection relating back translated values and their original strings.
DBTranslatedValueType
The nature of the elements handled by translators (discrete, continuous).
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities