aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::LabelizedVariable Class Reference

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

Protected Member Functions

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

Detailed Description

class LabelizedVariable

Base class for labelized discrete random variables

Definition at line 51 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)

◆ 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

◆ LabelizedVariable() [3/4]

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

Copy constructor.

Parameters
aLDRVthe variable we copy

◆ ~LabelizedVariable()

virtual gum::LabelizedVariable::~LabelizedVariable ( )
virtual

destructor

◆ LabelizedVariable() [4/4]

gum::LabelizedVariable::LabelizedVariable ( )
inlineprotected

(protected) Default constructor

Definition at line 172 of file labelizedVariable.h.

172  {
173  GUM_CONSTRUCTOR(LabelizedVariable);
174  ;
175  }
LabelizedVariable()
(protected) Default constructor

Member Function Documentation

◆ 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")...;

◆ 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.

◆ clone()

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

a virtual clone ...

Implements gum::DiscreteVariable.

◆ copy_() [1/2]

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

protected copy

Parameters
aRVto be copied

◆ copy_() [2/2]

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

copies the content of aLDRV

◆ description()

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

returns the description of the variable

◆ domain()

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

Returns the domain.

Implements gum::DiscreteVariable.

Definition at line 29 of file labelizedVariable.cpp.

References gum::Set< Key, Alloc >::emplace().

29  {
30  std::stringstream s;
31  s << "<";
32 
33  if (domainSize() > 0) {
34  s << label(0);
35 
36  for (Idx i = 1; i < domainSize(); ++i) {
37  s << ",";
38  s << label(i);
39  }
40  }
41 
42  s << ">";
43 
44  return s.str();
45  }
virtual std::string label(Idx i) const
returns the ith label
virtual Size domainSize() const
returns the size of the random discrete variable domain
+ Here is the call graph for this function:

◆ domainSize()

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

returns the size of the random discrete variable domain

Implements gum::DiscreteVariable.

◆ empty()

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

◆ eraseLabels()

void gum::LabelizedVariable::eraseLabels ( )

erase all the labels

◆ index()

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

returns the index of a given label

Parameters
labelsearched label
Returns
the index of this label
Exceptions
NotFound

Implements gum::DiscreteVariable.

◆ 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

◆ label()

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

returns the ith label

Parameters
i
Returns
the ith label

Implements gum::DiscreteVariable.

◆ labels()

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

vector of labels

◆ name()

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

returns the name of the variable

◆ numerical()

virtual double gum::LabelizedVariable::numerical ( Idx  indice) const
virtual

get a numerical representation of he indice-the value.

Implements gum::DiscreteVariable.

◆ operator!=() [1/2]

virtual bool gum::Variable::operator!= ( const Variable aRV) const
virtualinherited

inequality operator

◆ operator!=() [2/2]

virtual bool gum::DiscreteVariable::operator!= ( const DiscreteVariable aRV) const
virtualinherited

inequality operator

◆ operator=()

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

copy operator

Parameters
aLDRVthe labelized discrete random variable we copy

◆ operator==() [1/2]

virtual bool gum::Variable::operator== ( const Variable aRV) const
virtualinherited

equality operator

◆ operator==() [2/2]

virtual bool gum::DiscreteVariable::operator== ( const DiscreteVariable aRV) const
virtualinherited

equality operator

◆ 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 139 of file discreteVariable.h.

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

◆ posLabel()

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

return the pos from label

◆ 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

◆ toString()

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

string version of *this

◆ toStringWithDescription()

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

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

◆ varType()

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

returns the type of variable

Implements gum::DiscreteVariable.

Member Data Documentation

◆ _labels_

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

the set of labels contained in the variable

Definition at line 183 of file labelizedVariable.h.


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