![]() |
aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
|
The databases' cell translators for discretized variables. More...
#include <agrum/base/database/DBTranslator4DiscretizedVariable.h>
Public Member Functions | |
Constructors / Destructors | |
| template<GUM_Numeric GUM_SCALAR> | |
| 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 | |
| template<GUM_Numeric GUM_SCALAR> | |
| DBTranslator4DiscretizedVariable (const DiscretizedVariable< GUM_SCALAR > &var, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max()) | |
| default constructor with a discretized variable as translator but without missing symbols | |
| DBTranslator4DiscretizedVariable (const IDiscretizedVariable &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 IDiscretized variable as translator | |
| DBTranslator4DiscretizedVariable (const IDiscretizedVariable &var, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max()) | |
| default constructor with a IDiscretized variable as translator but without missing symbols | |
| DBTranslator4DiscretizedVariable (const DBTranslator4DiscretizedVariable &from) | |
| copy constructor | |
| DBTranslator4DiscretizedVariable (DBTranslator4DiscretizedVariable &&from) | |
| move constructor | |
| DBTranslator4DiscretizedVariable * | clone () const override |
| virtual copy constructor | |
| ~DBTranslator4DiscretizedVariable () override | |
| destructor | |
Operators | |
| DBTranslator4DiscretizedVariable & | operator= (const DBTranslator4DiscretizedVariable &from) |
| copy operator | |
| DBTranslator4DiscretizedVariable & | operator= (DBTranslator4DiscretizedVariable &&from) |
| move operator | |
Accessors / Modifiers | |
| DBTranslatedValue | translate (std::string_view str) final |
| returns the translation of a string | |
| std::string | translateBack (const DBTranslatedValue translated_val) const final |
| returns the original value for a given translation | |
| std::size_t | domainSize () const final |
| returns the number of discretization intervals used for translations | |
| bool | hasEditableDictionary () const final |
| indicates that the translator is never in editable dictionary mode | |
| void | setEditableDictionaryMode (bool new_mode) final |
| sets/unset the editable dictionary mode | |
| bool | needsReordering () const final |
| indicates that the translations should never be reordered | |
| HashTable< std::size_t, std::size_t > | reorder () final |
| returns an empty HashTable to indicate that no reordering is needed. | |
| const IDiscretizedVariable * | variable () const final |
| returns the variable stored into the translator | |
| DBTranslatedValue | missingValue () const final |
| returns the translation of a missing value | |
Operators | |
| DBTranslatedValue | operator<< (std::string_view str) |
| alias for method translate | |
| std::string | operator>> (const DBTranslatedValue translated_val) |
| alias for method translateBack | |
Accessors / Modifiers | |
| virtual const Bijection< std::size_t, std::string > & | getDictionary () const |
| returns the translation from database indices to input strings | |
| const Set< std::string > & | missingSymbols () const |
| returns the set of missing symbols taken into account by the translator | |
| bool | isMissingSymbol (std::string_view str) const |
| indicates whether a string corresponds to a missing symbol | |
| void | setVariableName (std::string_view str) const |
| sets the name of the variable stored into the translator | |
| void | setVariableDescription (std::string_view str) const |
| sets the name of the variable stored into the translator | |
| DBTranslatedValueType | getValType () const |
| returns the type of values handled by the translator | |
| bool | isLossless () const |
| returns a Boolean indicating whether the translation is lossless or not | |
| bool | isMissingValue (const DBTranslatedValue &val) const |
| indicates whether a translated value corresponds to a missing value | |
Protected Attributes | |
| bool | is_lossless_ |
| indicates whether the translation is lossless (e.g., ranges) or not | |
| bool | is_dictionary_dynamic_ |
| indicates whether the dictionary can be updated or not | |
| std::size_t | max_dico_entries_ |
| the maximum number of entries that the dictionary is allowed to contain | |
| Set< std::string > | missing_symbols_ |
| the set of missing symbols | |
| Bijection< std::size_t, std::string > | back_dico_ |
| the bijection relating back translated values and their original strings. | |
| DBTranslatedValueType | val_type_ |
| the type of the values translated by the translator | |
The databases' cell translators for discretized variables.
Translators are used by DatabaseTable instances to transform datasets' strings into DBTranslatedValue instances. The point is that strings are not adequate for fast learning, they need to be preprocessed into a type that can be analyzed quickly (the so-called DBTranslatedValue type).
A DBTranslator4DiscretizedVariable is a translator that contains and exploits a DiscretizedVariable for translations. Each time a string needs be translated, we ask the DiscretizedVariable which discretization interval contains the number represented by the string. The DBTranslatedValue corresponding to the translation of the string contains in its discr_val field the index of this discretization interval.
Definition at line 139 of file DBTranslator4DiscretizedVariable.h.
| gum::learning::DBTranslator4DiscretizedVariable::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
| var | a discretized variable which will be used for translations. The translator keeps a copy of this variable |
| missing_symbols | the set of symbols in the dataset representing missing values |
| max_dico_entries | the max number of entries that the dictionary can contain. During the construction, we check that the discretized variable passed in argument has fewer discretization intervals than the admissible dictionary size |
Referenced by DBTranslator4DiscretizedVariable(), DBTranslator4DiscretizedVariable(), clone(), operator=(), and operator=().
| gum::learning::DBTranslator4DiscretizedVariable::DBTranslator4DiscretizedVariable | ( | const DiscretizedVariable< GUM_SCALAR > & | var, |
| std::size_t | max_dico_entries = std::numeric_limits< std::size_t >::max() ) |
default constructor with a discretized variable as translator but without missing symbols
| var | a discretized variable which will be used for translations. The translator keeps a copy of this variable |
| max_dico_entries | the max number of entries that the dictionary can contain. During the construction, we check that the discretized variable passed in argument has fewer discretization intervals than the admissible dictionary size |
| gum::learning::DBTranslator4DiscretizedVariable::DBTranslator4DiscretizedVariable | ( | const IDiscretizedVariable & | 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 IDiscretized variable as translator
| var | a IDiscretized variable which will be used for translations. The translator keeps a copy of this variable |
| missing_symbols | the set of symbols in the dataset representing missing values |
| max_dico_entries | the max number of entries that the dictionary can contain. During the construction, we check that the discretized variable passed in argument has fewer discretization intervals than the admissible dictionary size |
| gum::learning::DBTranslator4DiscretizedVariable::DBTranslator4DiscretizedVariable | ( | const IDiscretizedVariable & | var, |
| std::size_t | max_dico_entries = std::numeric_limits< std::size_t >::max() ) |
default constructor with a IDiscretized variable as translator but without missing symbols
| var | a discretized variable which will be used for translations. The translator keeps a copy of this variable |
| max_dico_entries | the max number of entries that the dictionary can contain. During the construction, we check that the discretized variable passed in argument has fewer discretization intervals than the admissible dictionary size |
| gum::learning::DBTranslator4DiscretizedVariable::DBTranslator4DiscretizedVariable | ( | const DBTranslator4DiscretizedVariable & | from | ) |
copy constructor
References DBTranslator4DiscretizedVariable().
| gum::learning::DBTranslator4DiscretizedVariable::DBTranslator4DiscretizedVariable | ( | DBTranslator4DiscretizedVariable && | from | ) |
move constructor
References DBTranslator4DiscretizedVariable().
|
override |
destructor
|
nodiscardoverridevirtual |
virtual copy constructor
Implements gum::learning::DBTranslator.
References DBTranslator4DiscretizedVariable().
|
finalvirtual |
returns the number of discretization intervals used for translations
Implements gum::learning::DBTranslator.
|
virtualinherited |
returns the translation from database indices to input strings
|
inherited |
returns the type of values handled by the translator
Referenced by gum::learning::BNDatabaseGenerator< GUM_SCALAR >::toDatabaseTable().
|
finalvirtual |
indicates that the translator is never in editable dictionary mode
Reimplemented from gum::learning::DBTranslator.
References hasEditableDictionary().
Referenced by hasEditableDictionary().
|
inherited |
returns a Boolean indicating whether the translation is lossless or not
Some translations can lose some information. For instance, a translator for a discretized variable will translate all the values of a discretization interval as the same value (the index of the interval). As such it looses some information because, knowing this index, it is impossible to get back to the original value that was translated. Method isLossless() indicates whether the translation never loses any information or not.
|
inherited |
indicates whether a string corresponds to a missing symbol
|
inherited |
indicates whether a translated value corresponds to a missing value
|
inherited |
returns the set of missing symbols taken into account by the translator
|
finalvirtual |
returns the translation of a missing value
Implements gum::learning::DBTranslator.
References missingValue().
Referenced by missingValue().
|
finalvirtual |
indicates that the translations should never be reordered
Implements gum::learning::DBTranslator.
References needsReordering().
Referenced by needsReordering().
|
inherited |
alias for method translate
| DBTranslator4DiscretizedVariable & gum::learning::DBTranslator4DiscretizedVariable::operator= | ( | const DBTranslator4DiscretizedVariable & | from | ) |
copy operator
References DBTranslator4DiscretizedVariable().
| DBTranslator4DiscretizedVariable & gum::learning::DBTranslator4DiscretizedVariable::operator= | ( | DBTranslator4DiscretizedVariable && | from | ) |
move operator
References DBTranslator4DiscretizedVariable().
|
inherited |
alias for method translateBack
|
finalvirtual |
returns an empty HashTable to indicate that no reordering is needed.
Implements gum::learning::DBTranslator.
References reorder().
Referenced by reorder().
|
finalvirtual |
sets/unset the editable dictionary mode
Reimplemented from gum::learning::DBTranslator.
References setEditableDictionaryMode().
Referenced by setEditableDictionaryMode().
|
inherited |
sets the name of the variable stored into the translator
|
inherited |
sets the name of the variable stored into the translator
|
finalvirtual |
returns the translation of a string
This method tries to translate a given string into the DBTranslatedValue that should be stored into a databaseTable. If the translator cannot find the translation in its current dictionary, then the translator raises either a TypeError if the string is not a number or a NotFound exception.
| UnknownLabelInDatabase | is raised if the translation cannot be found. |
| TypeError | is raised if the translation cannot be found and the translator and the string does not correspond to a number. |
Implements gum::learning::DBTranslator.
|
finalvirtual |
returns the original value for a given translation
| UnknownLabelInDatabase | is raised if this original value cannot be found |
Implements gum::learning::DBTranslator.
|
finalvirtual |
returns the variable stored into the translator
Implements gum::learning::DBTranslator.
References variable().
Referenced by variable().
|
mutableprotectedinherited |
the bijection relating back translated values and their original strings.
Note that the translated values considered here are of type std::size_t because only the values for discrete variables need be stored, those for continuous variables are actually identity mappings.
Definition at line 401 of file DBTranslator.h.
|
protectedinherited |
indicates whether the dictionary can be updated or not
Definition at line 387 of file DBTranslator.h.
|
protectedinherited |
indicates whether the translation is lossless (e.g., ranges) or not
Definition at line 384 of file DBTranslator.h.
|
protectedinherited |
the maximum number of entries that the dictionary is allowed to contain
Definition at line 390 of file DBTranslator.h.
|
protectedinherited |
the set of missing symbols
Definition at line 393 of file DBTranslator.h.
|
protectedinherited |
the type of the values translated by the translator
Definition at line 404 of file DBTranslator.h.