![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
The databases' cell translators for labelized variables. More...
#include <agrum/tools/database/DBTranslator4LabelizedVariable.h>
Public Member Functions | |
Constructors / Destructors | |
template<template< typename > class XALLOC> | |
DBTranslator4LabelizedVariable (const std::vector< std::string, XALLOC< std::string > > &missing_symbols, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max(), const allocator_type &alloc=allocator_type()) | |
default constructor without any initial variable More... | |
DBTranslator4LabelizedVariable (std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max(), const allocator_type &alloc=allocator_type()) | |
default constructor without any initial variable nor missing symbols More... | |
template<template< typename > class XALLOC> | |
DBTranslator4LabelizedVariable (const LabelizedVariable &var, const std::vector< std::string, XALLOC< std::string > > &missing_symbols, const bool editable_dictionary=false, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max(), const allocator_type &alloc=allocator_type()) | |
default constructor with a labelized variable as translator More... | |
DBTranslator4LabelizedVariable (const LabelizedVariable &var, const bool editable_dictionary=false, std::size_t max_dico_entries=std::numeric_limits< std::size_t >::max(), const allocator_type &alloc=allocator_type()) | |
default constructor with a labelized variable as translator but without missing symbols More... | |
DBTranslator4LabelizedVariable (const DBTranslator4LabelizedVariable< ALLOC > &from) | |
copy constructor More... | |
DBTranslator4LabelizedVariable (const DBTranslator4LabelizedVariable< ALLOC > &from, const allocator_type &alloc) | |
copy constructor with a given allocator More... | |
DBTranslator4LabelizedVariable (DBTranslator4LabelizedVariable< ALLOC > &&from) | |
move constructor More... | |
DBTranslator4LabelizedVariable (DBTranslator4LabelizedVariable< ALLOC > &&from, const allocator_type &alloc) | |
move constructor with a given allocator More... | |
virtual DBTranslator4LabelizedVariable< ALLOC > * | clone () const |
virtual copy constructor More... | |
virtual DBTranslator4LabelizedVariable< ALLOC > * | clone (const allocator_type &alloc) const |
virtual copy constructor with a given allocator More... | |
virtual | ~DBTranslator4LabelizedVariable () |
destructor More... | |
Operators | |
DBTranslator4LabelizedVariable< ALLOC > & | operator= (const DBTranslator4LabelizedVariable< ALLOC > &from) |
copy operator More... | |
DBTranslator4LabelizedVariable< ALLOC > & | operator= (DBTranslator4LabelizedVariable< ALLOC > &&from) |
move operator More... | |
Accessors / Modifiers | |
virtual DBTranslatedValue | translate (const std::string &str) final |
returns the translation of a string More... | |
virtual std::string | translateBack (const DBTranslatedValue translated_val) const final |
returns the original value for a given translation More... | |
virtual std::size_t | domainSize () const final |
returns the domain size of a variable corresponding to the translations More... | |
virtual bool | needsReordering () const final |
indicates whether a reordering is needed to make the translations sorted More... | |
virtual HashTable< std::size_t, std::size_t, ALLOC< std::pair< 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. More... | |
virtual const LabelizedVariable * | variable () const final |
returns the variable stored into the translator More... | |
virtual DBTranslatedValue | missingValue () const final |
returns the translation of a missing value More... | |
Operators | |
DBTranslatedValue | operator<< (const std::string &str) |
alias for method translate More... | |
std::string | operator>> (const DBTranslatedValue translated_val) |
alias for method translateBack More... | |
Accessors / Modifiers | |
virtual bool | hasEditableDictionary () const |
indicates whether the translator has an editable dictionary or not More... | |
virtual void | setEditableDictionaryMode (bool new_mode) |
sets/unset the editable dictionary mode More... | |
const Set< std::string, ALLOC< std::string > > & | missingSymbols () const |
returns the set of missing symbols taken into account by the translator More... | |
bool | isMissingSymbol (const std::string &str) const |
indicates whether a string corresponds to a missing symbol More... | |
void | setVariableName (const std::string &str) const |
sets the name of the variable stored into the translator More... | |
void | setVariableDescription (const std::string &str) const |
sets the name of the variable stored into the translator More... | |
DBTranslatedValueType | getValType () const |
returns the type of values handled by the translator More... | |
allocator_type | getAllocator () const |
returns the allocator used by the translator More... | |
bool | isMissingValue (const DBTranslatedValue &val) const |
indicates whether a translated value corresponds to a missing value More... | |
Public Types | |
using | allocator_type = typename DBTranslator< ALLOC >::allocator_type |
type for the allocators passed in arguments of methods More... | |
Protected Attributes | |
bool | is_dictionary_dynamic_ |
indicates whether the dictionary can be updated or not More... | |
std::size_t | max_dico_entries_ |
the maximum number of entries that the dictionary is allowed to contain More... | |
Set< std::string, ALLOC< std::string > > | missing_symbols_ |
the set of missing symbols More... | |
Bijection< std::size_t, std::string, ALLOC< std::pair< float, std::string > > > | back_dico_ |
the bijection relating back translated values and their original strings. More... | |
DBTranslatedValueType | val_type_ |
the type of the values translated by the translator More... | |
The databases' cell translators for labelized 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 DBTranslator4LabelizedVariable is a translator that contains and exploits a LabelizedVariable for translations. Each time a string needs be translated, we ask the LabelizedVariable to provide the index of the label corresponding to the string. This index, when encoded into a DBTranslatedValue, is precisely the translation of the string.
Definition at line 134 of file DBTranslator4LabelizedVariable.h.
using gum::learning::DBTranslator4LabelizedVariable< ALLOC >::allocator_type = typename DBTranslator< ALLOC >::allocator_type |
type for the allocators passed in arguments of methods
Definition at line 137 of file DBTranslator4LabelizedVariable.h.
gum::learning::DBTranslator4LabelizedVariable< ALLOC >::DBTranslator4LabelizedVariable | ( | const std::vector< std::string, XALLOC< std::string > > & | missing_symbols, |
std::size_t | max_dico_entries = std::numeric_limits< std::size_t >::max() , |
||
const allocator_type & | alloc = allocator_type() |
||
) |
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 label that has not been encountered before, we add it into the dictionary of the translator (hence into the variable contained by the translator).
missing_symbols | the set of symbols in the database 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 |
alloc | The allocator used to allocate memory for all the fields of the DBTranslator4LabelizedVariable |
gum::learning::DBTranslator4LabelizedVariable< ALLOC >::DBTranslator4LabelizedVariable | ( | std::size_t | max_dico_entries = std::numeric_limits< std::size_t >::max() , |
const allocator_type & | alloc = allocator_type() |
||
) |
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 label that has not been encountered before, we add it into the dictionary of the translator (hence into 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 |
alloc | The allocator used to allocate memory for all the fields of the DBTranslator4LabelizedVariable |
gum::learning::DBTranslator4LabelizedVariable< ALLOC >::DBTranslator4LabelizedVariable | ( | const LabelizedVariable & | var, |
const std::vector< std::string, XALLOC< std::string > > & | missing_symbols, | ||
const bool | editable_dictionary = false , |
||
std::size_t | max_dico_entries = std::numeric_limits< std::size_t >::max() , |
||
const allocator_type & | alloc = allocator_type() |
||
) |
default constructor with a labelized variable as translator
var | a labelized variable whose labels will be used for translations. The translator keeps a copy of this variable |
missing_symbols | the set of symbols in the database 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 a label of var will raise a NotFound exception; when true, the translator will try to add the string as a new label into var (and therefore into 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 |
alloc | The allocator used to allocate memory for all the fields of the DBTranslator4LabelizedVariable |
gum::learning::DBTranslator4LabelizedVariable< ALLOC >::DBTranslator4LabelizedVariable | ( | const LabelizedVariable & | var, |
const bool | editable_dictionary = false , |
||
std::size_t | max_dico_entries = std::numeric_limits< std::size_t >::max() , |
||
const allocator_type & | alloc = allocator_type() |
||
) |
default constructor with a labelized variable as translator but without missing symbols
var | a labelized variable whose labels 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 a label of var will raise a NotFound exception; when true, the translator will try to add the string as a new label into var (and therefore into 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 |
alloc | The allocator used to allocate memory for all the fields of the DBTranslator4LabelizedVariable |
gum::learning::DBTranslator4LabelizedVariable< ALLOC >::DBTranslator4LabelizedVariable | ( | const DBTranslator4LabelizedVariable< ALLOC > & | from | ) |
copy constructor
gum::learning::DBTranslator4LabelizedVariable< ALLOC >::DBTranslator4LabelizedVariable | ( | const DBTranslator4LabelizedVariable< ALLOC > & | from, |
const allocator_type & | alloc | ||
) |
copy constructor with a given allocator
gum::learning::DBTranslator4LabelizedVariable< ALLOC >::DBTranslator4LabelizedVariable | ( | DBTranslator4LabelizedVariable< ALLOC > && | from | ) |
move constructor
gum::learning::DBTranslator4LabelizedVariable< ALLOC >::DBTranslator4LabelizedVariable | ( | DBTranslator4LabelizedVariable< ALLOC > && | from, |
const allocator_type & | alloc | ||
) |
move constructor with a given allocator
|
virtual |
destructor
|
virtual |
virtual copy constructor
Implements gum::learning::DBTranslator< ALLOC >.
|
virtual |
virtual copy constructor with a given allocator
Implements gum::learning::DBTranslator< ALLOC >.
|
finalvirtual |
returns the domain size of a variable corresponding to the translations
Assume that the translator has been fed with the observed values of a random variable. Then it has produced a set of translated values. The latter define the domain of the variable. The domainSize is the size of this domain. In other words, this corresponds to the number of labels of the LabelizedVariable contained in the translator. Note that missing values are not taken into account in the domain sizes.
Implements gum::learning::DBTranslator< ALLOC >.
|
inherited |
returns the allocator used by the translator
|
inherited |
returns the type of values handled by the translator
|
virtualinherited |
indicates whether the translator has an editable dictionary or not
Reimplemented in gum::learning::DBTranslator4DiscretizedVariable< ALLOC >.
|
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< ALLOC >.
|
finalvirtual |
indicates whether a reordering is needed to make the translations sorted
If the strings represented by the translations are only numbers, translations are considered to be sorted if and only if they are sorted by increasing number. If the strings do not only represent numbers, then translations are considered to be sorted if and only if they are sorted lexicographically.
When constructing dynamically its dictionary, the translator may assign wrong DBTranslatedValue values to strings. For instance, a translator reading sequentially integer strings 4, 1, 3, may map 4 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 {4,1,3}. The user may prefer having domain {1,3,4}, 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< ALLOC >.
|
inherited |
alias for method translate
DBTranslator4LabelizedVariable< ALLOC >& gum::learning::DBTranslator4LabelizedVariable< ALLOC >::operator= | ( | const DBTranslator4LabelizedVariable< ALLOC > & | from | ) |
copy operator
DBTranslator4LabelizedVariable< ALLOC >& gum::learning::DBTranslator4LabelizedVariable< ALLOC >::operator= | ( | DBTranslator4LabelizedVariable< ALLOC > && | from | ) |
move operator
|
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< ALLOC >.
|
virtualinherited |
sets/unset the editable dictionary mode
Reimplemented in gum::learning::DBTranslator4DiscretizedVariable< ALLOC >.
|
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:
str | the string that the translator will try to translate |
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 in the dictionary has already reached its maximum. |
Implements gum::learning::DBTranslator< ALLOC >.
|
finalvirtual |
returns the original value for a given translation
translated_val | a DBTranslatedValue which is supposed to contain the index of a label of the LabelizedVariable contained in the translator. The method should return this label |
UnknownLabelInDatabase | is raised if this original value cannot be found |
Implements gum::learning::DBTranslator< ALLOC >.
|
finalvirtual |
returns the variable stored into the translator
Implements gum::learning::DBTranslator< ALLOC >.
|
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 388 of file DBTranslator.h.
|
protectedinherited |
indicates whether the dictionary can be updated or not
Definition at line 373 of file DBTranslator.h.
|
protectedinherited |
the maximum number of entries that the dictionary is allowed to contain
Definition at line 376 of file DBTranslator.h.
|
protectedinherited |
the set of missing symbols
Definition at line 379 of file DBTranslator.h.
|
protectedinherited |
the type of the values translated by the translator
Definition at line 391 of file DBTranslator.h.