aGrUM  0.13.2
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...
 
const std::string toString () const
 string version of *this More...
 
const 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 int 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 49 of file labelizedVariable.h.

Constructor & Destructor Documentation

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

constructor

Parameters
aNamethe name
aDescthe Description
nbrLabelthe domainSize (2 by default)
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
gum::LabelizedVariable::LabelizedVariable ( const LabelizedVariable aLDRV)

Copy constructor.

Parameters
aLDRVthe variable we copy
virtual gum::LabelizedVariable::~LabelizedVariable ( )
virtual

destructor

gum::LabelizedVariable::LabelizedVariable ( )
inlineprotected

(protected) Default constructor

Definition at line 170 of file labelizedVariable.h.

References _copy().

170 { GUM_CONSTRUCTOR(LabelizedVariable); };
LabelizedVariable()
(protected) Default constructor

+ Here is the call graph for this function:

Member Function Documentation

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

protected copy

Parameters
aRVto be copied
void gum::LabelizedVariable::_copy ( const LabelizedVariable aLDRV)
protected

copies the content of aLDRV

Referenced by LabelizedVariable().

+ Here is the caller graph for this function:

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

Referenced by gum::prm::PRM< GUM_SCALAR >::__addBuiltInTypes(), gum::prm::PRMType< double >::boolean(), gum::FMDPFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), and gum::TaxiSimulator::TaxiSimulator().

+ Here is the caller graph for this function:

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.

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

+ Here is the caller graph for this function:

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

a virtual clone ...

Implements gum::DiscreteVariable.

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

returns the description of the variable

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

Returns the domain.

Implements gum::DiscreteVariable.

Definition at line 27 of file labelizedVariable.cpp.

References domainSize(), and label().

27  {
28  std::stringstream s;
29  s << "<";
30 
31  if (domainSize() > 0) {
32  s << label(0);
33 
34  for (Idx i = 1; i < domainSize(); ++i) {
35  s << ",";
36  s << label(i);
37  }
38  }
39 
40  s << ">";
41 
42  return s.str();
43  }
virtual std::string label(Idx i) const
returns the ith label
virtual Size domainSize() const
returns the size of the random discrete variable domain
unsigned long Idx
Type for indexes.
Definition: types.h:43

+ Here is the call graph for this function:

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

returns the size of the random discrete variable domain

Implements gum::DiscreteVariable.

Referenced by domain().

+ Here is the caller graph for this function:

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

erase all the labels

Referenced by gum::TaxiSimulator::TaxiSimulator().

+ Here is the caller graph for this function:

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.

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
virtual std::string gum::LabelizedVariable::label ( Idx  i) const
virtual

returns the ith label

Parameters
i
Returns
the ith label

Implements gum::DiscreteVariable.

Referenced by domain().

+ Here is the caller graph for this function:

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

vector of labels

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

returns the name of the variable

Referenced by gum::KL< GUM_SCALAR >::__checkCompatibility(), gum::BayesNetFactory< GUM_SCALAR >::__setCPTAndParents(), gum::GibbsKL< GUM_SCALAR >::_computeKL(), gum::MultiDimImplementation< GUM_SCALAR >::add(), gum::Instantiation::add(), gum::FMDP< GUM_SCALAR >::addTransitionForAction(), gum::FMDP< GUM_SCALAR >::addVariable(), gum::MultiDimICIModel< GUM_SCALAR >::causalWeight(), gum::Instantiation::chgVal(), gum::learning::genericBNLearner::Database::Database(), gum::FMDPFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::MarkovBlanket::hasSameStructure(), gum::BayesNetFragment< GUM_SCALAR >::nodeId(), gum::StructuredPlaner< GUM_SCALAR >::optimalPolicy2String(), gum::Estimator< GUM_SCALAR >::posterior(), gum::Instantiation::setValsFrom(), gum::BayesNetFactory< GUM_SCALAR >::setVariable(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValues(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::MarkovBlanket::toDot(), gum::EssentialGraph::toDot(), gum::InfluenceDiagram< GUM_SCALAR >::toDot(), gum::prm::InstanceBayesNet< GUM_SCALAR >::toDot(), gum::prm::ClassBayesNet< GUM_SCALAR >::toDot(), gum::IBayesNet< GUM_SCALAR >::toDot(), gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::toDot(), gum::Estimator< GUM_SCALAR >::update(), and gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >::varNodeListe().

+ Here is the caller graph for this function:

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

get a numerical representation of he indice-the value.

Implements gum::DiscreteVariable.

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

inequality operator

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

inequality operator

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

copy operator

Parameters
aLDRVthe labelized discrete random variable we copy
virtual bool gum::Variable::operator== ( const Variable aRV) const
virtualinherited

equality operator

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

equality 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 137 of file discreteVariable.h.

References gum::DiscreteVariable::domain(), gum::DiscreteVariable::index(), gum::DiscreteVariable::label(), gum::DiscreteVariable::toString(), and gum::DiscreteVariable::toStringWithDescription().

137 { 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

+ Here is the call graph for this function:

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

return the pos from label

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

+ Here is the caller graph for this function:

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
void gum::Variable::setName ( const std::string &  theValue)
inherited

sets the name of the variable

Parameters
theValue

Referenced by gum::prm::PRMSystem< GUM_SCALAR >::__groundAttr(), gum::FMDP< GUM_SCALAR >::addVariable(), and gum::TaxiSimulator::TaxiSimulator().

+ Here is the caller graph for this function:

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

string version of *this

Referenced by gum::DiscreteVariable::operator[]().

+ Here is the caller graph for this function:

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

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

Referenced by gum::DiscreteVariable::operator[](), and gum::IBayesNet< GUM_SCALAR >::toDot().

+ Here is the caller graph for this function:

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

returns the type of variable

Implements gum::DiscreteVariable.

Member Data Documentation

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

the set of labels contained in the variable

Definition at line 178 of file labelizedVariable.h.


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