aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
DBTranslator4RangeVariable.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
41
47#ifndef GUM_LEARNING_DB_TRANSLATOR_4_RANGE_VARIABLE_H
48#define GUM_LEARNING_DB_TRANSLATOR_4_RANGE_VARIABLE_H
49
50#include <agrum/agrum.h>
51
54
55namespace gum {
56
57 namespace learning {
58
59
150 public:
151 // ##########################################################################
153 // ##########################################################################
154
156
158
169 DBTranslator4RangeVariable(const std::vector< std::string >& missing_symbols,
170 std::size_t max_dico_entries
171 = std::numeric_limits< std::size_t >::max());
172
174
183 DBTranslator4RangeVariable(std::size_t max_dico_entries
184 = std::numeric_limits< std::size_t >::max());
185
187
205 const std::vector< std::string >& missing_symbols,
206 const bool editable_dictionary = false,
207 std::size_t max_dico_entries
208 = std::numeric_limits< std::size_t >::max());
209
229 const bool editable_dictionary = false,
230 std::size_t max_dico_entries
231 = std::numeric_limits< std::size_t >::max());
232
235
238
241
244
246
247
248 // ##########################################################################
250 // ##########################################################################
251
253
256
259
261
262
263 // ##########################################################################
265 // ##########################################################################
266
268
270
310 virtual DBTranslatedValue translate(const std::string& str) final;
311
313
316 virtual std::string translateBack(const DBTranslatedValue translated_val) const final;
317
319
320 virtual std::size_t domainSize() const final;
321
337 virtual bool needsReordering() const final;
338
347 virtual HashTable< std::size_t, std::size_t > reorder() final;
348
350 virtual const RangeVariable* variable() const final;
351
353 virtual DBTranslatedValue missingValue() const final;
354
356
357
358#ifndef DOXYGEN_SHOULD_SKIP_THIS
359
360 private:
361 // the RangeVariable assigned to the translator, if any
362 RangeVariable _variable_;
363
364 // assign to each integer missing symbol a Boolean indicating whether
365 // we already translated it or not. If we translated it, then we cannot
366 // change the range of the variable so that this range contains the symbol.
367 HashTable< std::string, bool > _status_int_missing_symbols_;
368
369 // the set of translations of the integer missing symbols found so far
370 Set< long > _translated_int_missing_symbols_;
371
372 // a string containing a non int missing symbol
373 // (useful for back translations)
374 std::string _nonint_missing_symbol_;
375
376#endif /* DOXYGEN_SHOULD_SKIP_THIS */
377 };
378
379
380 } /* namespace learning */
381
382} /* namespace gum */
383
385#ifndef GUM_NO_INLINE
387#endif /* GUM_NO_INLINE */
388
389#endif /* GUM_LEARNING_DB_TRANSLATOR_4_RANGE_VARIABLE_H */
The databases' cell translators for range variables.
The base class for all the tabular databases' cell translators.
The class for generic Hash Tables.
Definition hashTable.h:637
Defines a discrete random variable over an integer interval.
Representation of a set.
Definition set.h:131
virtual const RangeVariable * variable() const final
returns the variable stored into the translator
DBTranslator4RangeVariable(const RangeVariable &var, const bool editable_dictionary=false, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor with a range variable as translator but without missing symbols
virtual DBTranslatedValue translate(const std::string &str) final
returns the translation of a string
DBTranslator4RangeVariable(const DBTranslator4RangeVariable &from)
copy constructor
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
DBTranslator4RangeVariable(const RangeVariable &var, const std::vector< std::string > &missing_symbols, const bool editable_dictionary=false, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor with a range variable as translator
virtual DBTranslatedValue missingValue() const final
returns the translation of a missing value
virtual std::size_t domainSize() const final
returns the domain size of a variable corresponding to the translations
virtual std::string translateBack(const DBTranslatedValue translated_val) const final
returns the original value for a given translation
virtual HashTable< std::size_t, std::size_t > reorder() final
performs a reordering of the dictionary and returns a mapping from the old translated values to the n...
virtual bool needsReordering() const final
indicates whether a reordering is needed to make the translations sorted by increasing numbers
DBTranslator4RangeVariable & operator=(DBTranslator4RangeVariable &&from)
move operator
DBTranslator4RangeVariable(std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor without any initial variable nor missing symbols
DBTranslator4RangeVariable & operator=(const DBTranslator4RangeVariable &from)
copy operator
DBTranslator4RangeVariable(DBTranslator4RangeVariable &&from)
move constructor
virtual ~DBTranslator4RangeVariable()
destructor
virtual DBTranslator4RangeVariable * clone() const
virtual copy constructor
DBTranslator(DBTranslatedValueType val_type, const bool is_lossless, const std::vector< std::string > &missing_symbols, const bool editable_dictionary=true, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max())
default constructor
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.
Header of gumRangeVariable.
The union class for storing the translated values in learning databases.