aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::LabelizedVariable Class Referencefinal

class LabelizedVariable More...

#include <labelizedVariable.h>

Inheritance diagram for gum::LabelizedVariable:
Collaboration diagram for gum::LabelizedVariable:

Public Member Functions

Idx operator[] (const std::string &label) const
 from the label to its index in var.
std::string toString () const
 string version of *this
std::string toStringWithDescription () const
 string version of *this using description attribute instead of name.
Constructors / Destructors
 LabelizedVariable (const std::string &aName, const std::string &aDesc="", const Size nbrLabel=2)
 constructor
 LabelizedVariable (const std::string &aName, const std::string &aDesc, const std::vector< std::string > &labels)
 constructor
 LabelizedVariable (const LabelizedVariable &aLDRV)
 Copy constructor.
 ~LabelizedVariable () final
 destructor
LabelizedVariableclone () const final
 a virtual clone ...
Operators
LabelizedVariableoperator= (const LabelizedVariable &aLDRV)
 copy operator
Idx index (const std::string &label) const final
 returns the index of a given label
Accessors / Modifiers
bool isLabel (const std::string &aLabel) const
 indicates whether the variable already has the label passed in argument
LabelizedVariableaddLabel (const std::string &aLabel)
 add a label with a new index (we assume that we will NEVER remove a label)
void changeLabel (Idx pos, const std::string &aLabel) const
 change a label for this index
void eraseLabels ()
 erase all the labels
std::string label (Idx i) const final
 returns the ith label
Idx posLabel (const std::string &label) const
 return the pos from label
double numerical (Idx index) const final
 get a numerical representation of the index-the value.
Idx closestIndex (double val) const final
 returns the closest index of the value
Size domainSize () const final
 returns the size of the random discrete variable domain
VarType varType () const final
 returns the type of variable
std::string domain () const final
 Returns the domain.
std::string stype () const final
 string represent the type of the variable
std::string toFast () const final
 indicates whether the variable already has the label passed in argument
Accessors / Modifiers
bool empty () const
std::vector< std::string > labels () const
 vector of labels
virtual bool isEmpirical () const
std::string closestLabel (double val) const
 for numerical variables, returns the closest label for the value
Operators
bool operator== (const Variable &aRV) const
 equality operator
Accessors / Modifiers
void setName (const std::string &theValue)
 sets the name of the variable
const std::string & name () const
 returns the name of the variable
void setDescription (const std::string &theValue) const
 sets the description of the variable
const std::string & description () const
 returns the description of the variable

Protected Member Functions

 LabelizedVariable ()
 (protected) Default constructor
void copy_ (const LabelizedVariable &aLDRV)
 copies the content of aLDRV
void copy_ (const Variable &aRV)
 protected copy

Private Member Functions

bool _checkSameDomain_ (const Variable &aRV) const final
 check the domain

Private Attributes

Sequence< std::string > _labels_
 the set of labels contained in the variable
std::string _name_
 the name of the variable
std::string _description_
 the description of the variable since description is not a characteristic of a variable, we allow the description to be changed even in a const reference.

Detailed Description

class LabelizedVariable

Base class for labelized discrete random variables

Definition at line 71 of file labelizedVariable.h.

Constructor & Destructor Documentation

◆ LabelizedVariable() [1/4]

gum::LabelizedVariable::LabelizedVariable ( const std::string & aName,
const std::string & aDesc = "",
const Size nbrLabel = 2 )

constructor

Parameters
aNamethe name
aDescthe Description
nbrLabelthe domainSize (2 by default)

Referenced by LabelizedVariable(), LabelizedVariable(), addLabel(), clone(), copy_(), and operator=().

Here is the caller graph for this function:

◆ LabelizedVariable() [2/4]

gum::LabelizedVariable::LabelizedVariable ( const std::string & aName,
const std::string & aDesc,
const std::vector< std::string > & labels )

constructor

Parameters
aNamethe name
aDescthe Description
labelsthe labels

References gum::DiscreteVariable::labels().

Here is the call graph for this function:

◆ LabelizedVariable() [3/4]

gum::LabelizedVariable::LabelizedVariable ( const LabelizedVariable & aLDRV)

Copy constructor.

Parameters
aLDRVthe variable we copy

References LabelizedVariable().

Here is the call graph for this function:

◆ ~LabelizedVariable()

gum::LabelizedVariable::~LabelizedVariable ( )
final

destructor

◆ LabelizedVariable() [4/4]

gum::LabelizedVariable::LabelizedVariable ( )
inlineprotected

(protected) Default constructor

Definition at line 209 of file labelizedVariable.h.

209{ GUM_CONSTRUCTOR(LabelizedVariable) }
LabelizedVariable(const std::string &aName, const std::string &aDesc="", const Size nbrLabel=2)
constructor

References LabelizedVariable().

Here is the call graph for this function:

Member Function Documentation

◆ _checkSameDomain_()

bool gum::LabelizedVariable::_checkSameDomain_ ( const Variable & aRV) const
finalprivatevirtual

check the domain

this function use the assumption that the concrete type of the variable is the same as *this

Implements gum::Variable.

References _checkSameDomain_().

Referenced by _checkSameDomain_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addLabel()

LabelizedVariable & gum::LabelizedVariable::addLabel ( const std::string & aLabel)

add a label with a new index (we assume that we will NEVER remove a label)

Parameters
aLabelthe label to be added to the labelized variable
Exceptions
DuplicateElementis raised if the variable already contains the label
Returns
*this which allows : v.addLabel("1").addLabel("2")...;

References LabelizedVariable(), and addLabel().

Referenced by addLabel(), gum::prm::PRMFactory< GUM_SCALAR >::addLabel(), gum::prm::PRMType::boolean(), and gum::FMDPFactory< GUM_SCALAR >::endVariableDeclaration().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ changeLabel()

void gum::LabelizedVariable::changeLabel ( Idx pos,
const std::string & aLabel ) const

change a label for this index

Parameters
posthe index of the label to be changed
aLabelthe label to be added to the labelized variable
Exceptions
DuplicateElementis raised if the variable already contains
OutOfBounds
Warning
Since this change does not affect the variable domain but only the variable representation, this method is allowed on const LabelizedVariable.

References changeLabel().

Referenced by changeLabel(), and gum::BayesNet< GUM_SCALAR >::changeVariableLabel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clone()

LabelizedVariable * gum::LabelizedVariable::clone ( ) const
finalvirtual

a virtual clone ...

Implements gum::DiscreteVariable.

References LabelizedVariable(), and clone().

Referenced by clone().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ closestIndex()

Idx gum::LabelizedVariable::closestIndex ( double val) const
finalvirtual

returns the closest index of the value

Implements gum::DiscreteVariable.

References closestIndex().

Referenced by closestIndex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ closestLabel()

std::string gum::DiscreteVariable::closestLabel ( double val) const
inherited

for numerical variables, returns the closest label for the value

◆ copy_() [1/2]

void gum::LabelizedVariable::copy_ ( const LabelizedVariable & aLDRV)
protected

copies the content of aLDRV

References LabelizedVariable().

Here is the call graph for this function:

◆ copy_() [2/2]

void gum::Variable::copy_ ( const Variable & aRV)
protectedinherited

protected copy

Parameters
aRVto be copied

References Variable().

Here is the call graph for this function:

◆ description()

const std::string & gum::Variable::description ( ) const
inherited

returns the description of the variable

◆ domain()

std::string gum::LabelizedVariable::domain ( ) const
finalvirtual

Returns the domain.

Implements gum::DiscreteVariable.

Definition at line 49 of file labelizedVariable.cpp.

49 {
50 std::stringstream s;
51 s << "{";
52
53 if (domainSize() > 0) {
54 s << label(0);
55
56 for (Idx i = 1; i < domainSize(); ++i) {
57 s << "|";
58 s << label(i);
59 }
60 }
61
62 s << "}";
63
64 return s.str();
65 }
Size domainSize() const final
returns the size of the random discrete variable domain
std::string label(Idx i) const final
returns the ith label
Size Idx
Type for indexes.
Definition types.h:79

References domainSize(), and label().

Referenced by varType().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ domainSize()

Size gum::LabelizedVariable::domainSize ( ) const
finalvirtual

returns the size of the random discrete variable domain

Implements gum::DiscreteVariable.

References domainSize().

Referenced by domain(), and domainSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ empty()

bool gum::DiscreteVariable::empty ( ) const
inherited
Returns
true if the domainSize() < 2;

◆ eraseLabels()

void gum::LabelizedVariable::eraseLabels ( )

erase all the labels

References eraseLabels().

Referenced by eraseLabels().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ index()

Idx gum::LabelizedVariable::index ( const std::string & label) const
finalvirtual

returns the index of a given label

Parameters
labelsearched label
Returns
the index of this label
Exceptions
NotFound

Implements gum::DiscreteVariable.

References index(), and label().

Referenced by index(), and numerical().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEmpirical()

virtual bool gum::DiscreteVariable::isEmpirical ( ) const
inlinevirtualinherited
Returns
true if the domainSize() < 2;

Reimplemented in gum::IDiscretizedVariable.

Definition at line 124 of file discreteVariable.h.

124{ return false; };

◆ isLabel()

bool gum::LabelizedVariable::isLabel ( const std::string & aLabel) const

indicates whether the variable already has the label passed in argument

Parameters
aLabelThe label
Returns
true if the label already exists

References isLabel().

Referenced by isLabel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ label()

std::string gum::LabelizedVariable::label ( Idx i) const
finalvirtual

returns the ith label

Parameters
i
Returns
the ith label

Implements gum::DiscreteVariable.

References label().

Referenced by domain(), index(), label(), and posLabel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ labels()

std::vector< std::string > gum::DiscreteVariable::labels ( ) const
inherited

vector of labels

Referenced by gum::LabelizedVariable::LabelizedVariable().

Here is the caller graph for this function:

◆ name()

const std::string & gum::Variable::name ( ) const
inherited

returns the name of the variable

Referenced by gum::learning::IBNLearner::Database::Database(), gum::Estimator< GUM_SCALAR >::Estimator(), gum::MultiDimImplementation< double >::MultiDimImplementation(), gum::NumericalDiscreteVariable::NumericalDiscreteVariable(), gum::BNdistance< GUM_SCALAR >::_checkCompatibility_(), gum::BayesNet< double >::_copyTensors_(), gum::prm::PRMFactory< GUM_SCALAR >::_retrieveCommonType_(), gum::prm::PRMFactory< GUM_SCALAR >::_retrieveInputs_(), gum::BayesNetFactory< GUM_SCALAR >::_setCPTAndParents_(), gum::Instantiation::add(), gum::FMDP< double >::addCostForAction(), gum::FMDP< GUM_SCALAR >::addVariable(), gum::MultiDimICIModel< GUM_SCALAR >::causalWeight(), gum::Instantiation::chgVal(), gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), gum::InfluenceDiagram< GUM_SCALAR >::copyStructureAndTables_(), gum::prm::PRMFactory< GUM_SCALAR >::endDiscreteType(), gum::prm::PRMFactory< GUM_SCALAR >::endDiscretizedType(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::FMDPFactory< GUM_SCALAR >::endVariableDeclaration(), gum::Tensor< GUM_SCALAR >::fillWith(), gum::BayesNetFragment< GUM_SCALAR >::nodeId(), gum::Estimator< GUM_SCALAR >::posterior(), gum::Estimator< GUM_SCALAR >::setFromBN(), gum::Instantiation::setValsFrom(), gum::BayesNetFactory< GUM_SCALAR >::setVariable(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::toDot(), gum::RangeVariable::toFast(), gum::Estimator< GUM_SCALAR >::update(), and gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::varNodeListe().

◆ numerical()

double gum::LabelizedVariable::numerical ( Idx index) const
finalvirtual

get a numerical representation of the index-the value.

Implements gum::DiscreteVariable.

References index(), and numerical().

Referenced by numerical().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

LabelizedVariable & gum::LabelizedVariable::operator= ( const LabelizedVariable & aLDRV)

copy operator

Parameters
aLDRVthe labelized discrete random variable we copy

References LabelizedVariable().

Here is the call graph for this function:

◆ operator==()

bool gum::Variable::operator== ( const Variable & aRV) const
inherited

equality operator

References Variable().

Here is the call graph for this function:

◆ operator[]()

Idx gum::DiscreteVariable::operator[] ( const std::string & label) const
inlineinherited

from the label to its index in var.

Warning
This operation may have different complexity in different subclasses.
Exceptions
NotFound

Definition at line 156 of file discreteVariable.h.

156{ return index(label); };
virtual Idx index(const std::string &label) const =0
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.

References index(), and label().

Here is the call graph for this function:

◆ posLabel()

Idx gum::LabelizedVariable::posLabel ( const std::string & label) const

return the pos from label

References label(), and posLabel().

Referenced by gum::BayesNet< GUM_SCALAR >::changeVariableLabel(), and posLabel().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setDescription()

void gum::Variable::setDescription ( const std::string & theValue) const
inherited

sets the description of the variable

Warning
since description is mutable, setDescription() is const
Parameters
theValue

◆ setName()

void gum::Variable::setName ( const std::string & theValue)
inherited

sets the name of the variable

Parameters
theValue

◆ stype()

std::string gum::LabelizedVariable::stype ( ) const
inlinefinalvirtual

string represent the type of the variable

Implements gum::DiscreteVariable.

Definition at line 192 of file labelizedVariable.h.

192{ return "Labelized"; };

References stype().

Referenced by stype().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toFast()

std::string gum::LabelizedVariable::toFast ( ) const
finalvirtual

indicates whether the variable already has the label passed in argument

Parameters
aLabelThe label
Returns
true if the label already exists

Implements gum::DiscreteVariable.

◆ toString()

std::string gum::DiscreteVariable::toString ( ) const
inherited

string version of *this

Referenced by gum::IntegerVariable::IntegerVariable(), and gum::BNdistance< GUM_SCALAR >::_checkCompatibility_().

Here is the caller graph for this function:

◆ toStringWithDescription()

std::string gum::DiscreteVariable::toStringWithDescription ( ) const
inherited

string version of *this using description attribute instead of name.

◆ varType()

VarType gum::LabelizedVariable::varType ( ) const
finalvirtual

returns the type of variable

Implements gum::DiscreteVariable.

References domain(), and varType().

Referenced by varType().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _description_

std::string gum::Variable::_description_
mutableprivateinherited

the description of the variable since description is not a characteristic of a variable, we allow the description to be changed even in a const reference.

Definition at line 165 of file variable.h.

◆ _labels_

Sequence< std::string > gum::LabelizedVariable::_labels_
mutableprivate

the set of labels contained in the variable

Definition at line 217 of file labelizedVariable.h.

◆ _name_

std::string gum::Variable::_name_
privateinherited

the name of the variable

Definition at line 160 of file variable.h.


The documentation for this class was generated from the following files: