![]() |
aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
|
The databases' cell translators for range variables. More...
#include <agrum/base/database/DBTranslator4RangeVariable.h>
Public Member Functions | |
Constructors / Destructors | |
| 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 (std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max()) | |
| default constructor without any initial variable nor missing symbols | |
| 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 | |
| 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 | |
| DBTranslator4RangeVariable (const DBTranslator4RangeVariable &from) | |
| copy constructor | |
| DBTranslator4RangeVariable (DBTranslator4RangeVariable &&from) | |
| move constructor | |
| virtual DBTranslator4RangeVariable * | clone () const |
| virtual copy constructor | |
| virtual | ~DBTranslator4RangeVariable () |
| destructor | |
Operators | |
| DBTranslator4RangeVariable & | operator= (const DBTranslator4RangeVariable &from) |
| copy operator | |
| DBTranslator4RangeVariable & | operator= (DBTranslator4RangeVariable &&from) |
| move operator | |
Accessors / Modifiers | |
| virtual DBTranslatedValue | translate (const std::string &str) final |
| returns the translation of a string | |
| virtual std::string | translateBack (const DBTranslatedValue translated_val) const final |
| returns the original value for a given translation | |
| virtual std::size_t | domainSize () const final |
| returns the domain size of a variable corresponding to the translations | |
| virtual bool | needsReordering () const final |
| indicates whether a reordering is needed to make the translations sorted by increasing numbers | |
| 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 new ones. | |
| virtual const RangeVariable * | variable () const final |
| returns the variable stored into the translator | |
| virtual DBTranslatedValue | missingValue () const final |
| returns the translation of a missing value | |
Operators | |
| DBTranslatedValue | operator<< (const std::string &str) |
| alias for method translate | |
| std::string | operator>> (const DBTranslatedValue translated_val) |
| alias for method translateBack | |
Accessors / Modifiers | |
| virtual bool | hasEditableDictionary () const |
| indicates whether the translator has an editable dictionary or not | |
| virtual void | setEditableDictionaryMode (bool new_mode) |
| sets/unset the editable dictionary mode | |
| 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 (const std::string &str) const |
| indicates whether a string corresponds to a missing symbol | |
| void | setVariableName (const std::string &str) const |
| sets the name of the variable stored into the translator | |
| void | setVariableDescription (const std::string &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 range 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 DBTranslator4RangeVariable is a translator that contains and exploits a RangeVariable for translations. Each time a string needs be translated, we ask the RangeVariable whether its domain contains the integer value represented in the string. If this is the case, then the DBTranslatedValue corresponding to the translation of the string contains in its discr_val field this integer value.
Definition at line 149 of file DBTranslator4RangeVariable.h.
| gum::learning::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
When using this constructor, it is assumed implicitly that the dictionary contained into the translator is editable. So, when reading the database, if we observe a value that has not been encountered before, we update the range of the dictionary of the translator (hence that of the variable contained by the translator).
| 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. If we try to add new entries in the dictionary, this will be considered as an error and a SizeError exception will be raised |
Referenced by DBTranslator4RangeVariable(), DBTranslator4RangeVariable(), clone(), operator=(), and operator=().
| gum::learning::DBTranslator4RangeVariable::DBTranslator4RangeVariable | ( | std::size_t | max_dico_entries = std::numeric_limits< std::size_t >::max() | ) |
default constructor without any initial variable nor missing symbols
When using this constructor, it is assumed implicitly that the dictionary contained into the translator is editable. So, when reading the database, if we observe a value that has not been encountered before, we update the range of the dictionary of the translator (hence that of the variable contained by the translator).
| max_dico_entries | the max number of entries that the dictionary can contain. If we try to add new entries in the dictionary, this will be considered as an error and a SizeError exception will be raised |
| gum::learning::DBTranslator4RangeVariable::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
| var | a range 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 |
| editable_dictionary | the mode in which the translator will perform translations: when false (the default), the translation of a string that does not correspond to an integer within the range of var will raise a NotFound exception; when true, the translator will try to expand the domain of the RangeVariable so that the number represented in the string belongs to this domain ((and therefore to the dictionary) |
| max_dico_entries | the max number of entries that the dictionary can contain. If we try to add new entries in the dictionary, this will be considered as an error and a SizeError exception will be raised |
| gum::learning::DBTranslator4RangeVariable::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
| var | a range variable which will be used for translations. The translator keeps a copy of this variable |
| editable_dictionary | the mode in which the translator will perform translations: when false (the default), the translation of a string that does not correspond to an integer within the range of var will raise a NotFound exception; when true, the translator will try to expand the domain of the RangeVariable so that the number represented in the string belongs to this domain ((and therefore to the dictionary) |
| max_dico_entries | the max number of entries that the dictionary can contain. If we try to add new entries in the dictionary, this will be considered as an error and a SizeError exception will be raised |
| gum::learning::DBTranslator4RangeVariable::DBTranslator4RangeVariable | ( | const DBTranslator4RangeVariable & | from | ) |
| gum::learning::DBTranslator4RangeVariable::DBTranslator4RangeVariable | ( | DBTranslator4RangeVariable && | from | ) |
|
virtual |
destructor
|
virtual |
virtual copy constructor
Implements gum::learning::DBTranslator.
References DBTranslator4RangeVariable().
|
finalvirtual |
returns the domain size of a variable corresponding to the translations
Returns the size of the range of the variable.
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().
|
virtualinherited |
indicates whether the translator has an editable dictionary or not
Reimplemented in gum::learning::DBTranslator4DiscretizedVariable, gum::learning::DBTranslator4IntegerVariable, and gum::learning::DBTranslator4NumericalDiscreteVariable.
|
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 whether a reordering is needed to make the translations sorted by increasing numbers
When constructing dynamically its dictionary, the translator may assign wrong DBTranslatedValue values to strings. For instance, a translator reading sequentially integer strings 2, 1, 3, may map 2 into DBTranslatedValue{std::size_t(0)}, 1 into DBTranslatedValue{std::size_t(1)} and 3 into DBTranslatedValue{std::size_t(2)}, resulting in random variables having domain {2,1,3}. The user may prefer having domain {1,2,3}, i.e., a domain specified with increasing values. This requires a reordering. Method needsReodering() returns a Boolean indicating whether such a reordering should be performed or whether the current order is OK.
Implements gum::learning::DBTranslator.
References needsReordering().
Referenced by needsReordering().
|
inherited |
alias for method translate
| DBTranslator4RangeVariable & gum::learning::DBTranslator4RangeVariable::operator= | ( | const DBTranslator4RangeVariable & | from | ) |
| DBTranslator4RangeVariable & gum::learning::DBTranslator4RangeVariable::operator= | ( | DBTranslator4RangeVariable && | from | ) |
|
inherited |
alias for method translateBack
|
finalvirtual |
performs a reordering of the dictionary and returns a mapping from the old translated values to the new ones.
When a reordering is needed, i.e., string values must be translated differently, Method reorder() computes how the translations should be changed. It updates accordingly the dictionary and returns the mapping that enables changing the old dictionary values into the new ones.
Implements gum::learning::DBTranslator.
References reorder().
Referenced by reorder().
|
virtualinherited |
sets/unset the editable dictionary mode
Reimplemented in gum::learning::DBTranslator4DiscretizedVariable, gum::learning::DBTranslator4IntegerVariable, and gum::learning::DBTranslator4NumericalDiscreteVariable.
|
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 two situations can obtain:
| UnknownLabelInDatabase | is raised if the translation cannot be found and the translator is not in an editable dictionary mode. |
| SizeError | is raised if the number of entries (the range) in the dictionary has already reached its maximum. |
| TypeError | is raised if the translation cannot be found and the translator is in an editable dictionary mode and the string does not correspond to an integer. |
| OperationNotAllowed | exception is raised if the translation cannot be found and the insertion of the string into the translator's dictionary fails because it would induce incoherent behavior (e.g., a translator that contains a variable whose domain is {x,y,z,t} as well as a missing value symbol z). |
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 399 of file DBTranslator.h.
|
protectedinherited |
indicates whether the dictionary can be updated or not
Definition at line 385 of file DBTranslator.h.
|
protectedinherited |
indicates whether the translation is lossless (e.g., ranges) or not
Definition at line 382 of file DBTranslator.h.
|
protectedinherited |
the maximum number of entries that the dictionary is allowed to contain
Definition at line 388 of file DBTranslator.h.
|
protectedinherited |
the set of missing symbols
Definition at line 391 of file DBTranslator.h.
|
protectedinherited |
the type of the values translated by the translator
Definition at line 402 of file DBTranslator.h.