aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::DiscretizedVariable< T_TICKS > Class Template Referencefinal

Class for discretized random variable. More...

#include <discretizedVariable.h>

Inheritance diagram for gum::DiscretizedVariable< T_TICKS >:
Collaboration diagram for gum::DiscretizedVariable< T_TICKS >:

Public Member Functions

DiscretizedVariable< T_TICKS > * clone () const override
 a virtual clone
VarType varType () const override
 returns the type of variable
DiscretizedVariable< T_TICKS > & operator= (const DiscretizedVariable< T_TICKS > &aDRV)
 operator =
bool isTick (const T_TICKS &aTick) const
DiscretizedVariableaddTick (const T_TICKS &aTick)
 add a tick.
void eraseTicks ()
 erase all the Ticks
std::string label (Idx i) const override
double numerical (Idx indice) const override
 get a (deterministic) numerical representation of he indice-the value.
double draw (Idx indice) const override
 get a random value in the intervall indice
Idx index (const std::string &label) const override
 from the label to its index in var.
Idx index (const T_TICKS tick) const
 from the T+TICKS to its index in var.
Size domainSize () const override
std::string domain () const override
 string represent the domain of the variable
std::string stype () const override final
 string represent the type of the variable
const T_TICKS & tick (Idx i) const
 from the index to the tick.
const std::vector< T_TICKS > & ticks () const
 Return the list of ticks.
std::vector< doubleticksAsDoubles () const override
 return the list of ticks as a vector of doubles
Idx closestIndex (double val) const override
 returns the closest index of the value
std::string toFast () const override
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
 DiscretizedVariable (const std::string &aName, const std::string &aDesc)
 Constructor.
 DiscretizedVariable (const std::string &aName, const std::string &aDesc, const std::vector< T_TICKS > &ticks, bool is_empirical=false)
 Constructor.
 DiscretizedVariable (const DiscretizedVariable< T_TICKS > &aDRV)
 Copy constructor.
 ~DiscretizedVariable () override final
 Destructor.
Accessors / Modifiers
bool isEmpirical () const final
void setEmpirical (bool state)
Accessors / Modifiers
bool empty () const
std::vector< std::string > labels () const
 vector of labels
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

void copy_ (const DiscretizedVariable< T_TICKS > &aDRV)
 make a copy
Idx pos_ (const T_TICKS &target) const
 search the class of target (internally use dichotomy_)
void copy_ (const Variable &aRV)
 protected copy

Protected Attributes

bool _is_empirical

Private Member Functions

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

Private Attributes

std::vector< T_TICKS > _ticks_
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

template<typename T_TICKS>
class gum::DiscretizedVariable< T_TICKS >

Class for discretized random variable.

a DiscretizedVariable contains a vector of T_TICKS, assuming that the modalities of the variable arc [T1,T2[,[T2,T3[,...,[Tn-1,Tn]. T can be plus_infinity or minus_infinity.

operator [] has a T_TICKS argument.

Warning
DiscretizedVariable is a template, but it is assumed that there is a complete order on T_TICKS.
Note that, if T_TICKS allows it, you may use -std::numeric_limits<T_TICKS>::infinity() and std::numeric_limits<T_TICKS>::infinity() as tick value.
If a variable contains less than 3 ticks, it is considered as empty(). A variable with 3 ticks is binary and contains 2 ranges : [T1,T2[ (modality 0) and [T2,T3] (modality 1).
For convenience, if the variable _is_empirical, a value smaller than the first tick or bigger than the last tick is not considered as an error but is treated as a correct value.
Author
Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_AMU)

Definition at line 76 of file discretizedVariable.h.

Constructor & Destructor Documentation

◆ DiscretizedVariable() [1/3]

template<typename T_TICKS>
gum::DiscretizedVariable< T_TICKS >::DiscretizedVariable ( const std::string & aName,
const std::string & aDesc )

Constructor.

Parameters
aNamethe name
aDescthe description

Referenced by DiscretizedVariable(), addTick(), clone(), copy_(), and operator=().

Here is the caller graph for this function:

◆ DiscretizedVariable() [2/3]

template<typename T_TICKS>
gum::DiscretizedVariable< T_TICKS >::DiscretizedVariable ( const std::string & aName,
const std::string & aDesc,
const std::vector< T_TICKS > & ticks,
bool is_empirical = false )

Constructor.

Parameters
aNamethe name
aDescthe description
tickslist of ticks (limits of the intervals of the discretization)
is_empiricaldetermine the behavior of the variable for value below or above the limits. If false, it is treated as an error.

References ticks().

Here is the call graph for this function:

◆ DiscretizedVariable() [3/3]

template<typename T_TICKS>
gum::DiscretizedVariable< T_TICKS >::DiscretizedVariable ( const DiscretizedVariable< T_TICKS > & aDRV)

Copy constructor.

Parameters
aDRV

References DiscretizedVariable().

Here is the call graph for this function:

◆ ~DiscretizedVariable()

template<typename T_TICKS>
gum::DiscretizedVariable< T_TICKS >::~DiscretizedVariable ( )
finaloverride

Destructor.

Member Function Documentation

◆ _checkSameDomain_()

template<typename T_TICKS>
bool gum::DiscretizedVariable< T_TICKS >::_checkSameDomain_ ( const Variable & aRV) const
overrideprivatevirtual

check the domain

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

Implements gum::Variable.

◆ addTick()

template<typename T_TICKS>
DiscretizedVariable & gum::DiscretizedVariable< T_TICKS >::addTick ( const T_TICKS & aTick)

add a tick.

Parameters
aTick
Exceptions
DefaultInLabel

References DiscretizedVariable(), and addTick().

Referenced by addTick(), and gum::prm::PRMFactory< GUM_SCALAR >::addTick().

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

◆ clone()

template<typename T_TICKS>
DiscretizedVariable< T_TICKS > * gum::DiscretizedVariable< T_TICKS >::clone ( ) const
overridevirtual

a virtual clone

Implements gum::IDiscretizedVariable.

References DiscretizedVariable(), and clone().

Referenced by clone().

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

◆ closestIndex()

template<typename T_TICKS>
Idx gum::DiscretizedVariable< T_TICKS >::closestIndex ( double val) const
overridevirtual

returns the closest index of the value

Implements gum::DiscreteVariable.

◆ closestLabel()

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

for numerical variables, returns the closest label for the value

◆ copy_() [1/2]

template<typename T_TICKS>
void gum::DiscretizedVariable< T_TICKS >::copy_ ( const DiscretizedVariable< T_TICKS > & aDRV)
protected

make a copy

Parameters
aDRVthe copied object

References DiscretizedVariable().

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()

template<typename T_TICKS>
std::string gum::DiscretizedVariable< T_TICKS >::domain ( ) const
overridevirtual

string represent the domain of the variable

Implements gum::DiscreteVariable.

References domain().

Referenced by domain().

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

◆ domainSize()

template<typename T_TICKS>
Size gum::DiscretizedVariable< T_TICKS >::domainSize ( ) const
overridevirtual
Returns
the size of the random discrete variable domain

Implements gum::DiscreteVariable.

References domainSize().

Referenced by domainSize().

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

◆ draw()

template<typename T_TICKS>
double gum::DiscretizedVariable< T_TICKS >::draw ( Idx indice) const
overridevirtual

get a random value in the intervall indice

Implements gum::IDiscretizedVariable.

References draw().

Referenced by draw().

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;

◆ eraseTicks()

template<typename T_TICKS>
void gum::DiscretizedVariable< T_TICKS >::eraseTicks ( )

erase all the Ticks

References eraseTicks().

Referenced by eraseTicks().

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

◆ index() [1/2]

template<typename T_TICKS>
Idx gum::DiscretizedVariable< T_TICKS >::index ( const std::string & label) const
overridevirtual

from the label to its index in var.

Exceptions
NotFound

Implements gum::DiscreteVariable.

References index(), and label().

Referenced by index(), and index().

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

◆ index() [2/2]

template<typename T_TICKS>
Idx gum::DiscretizedVariable< T_TICKS >::index ( const T_TICKS tick) const

from the T+TICKS to its index in var.

Exceptions
NotFound

References index(), and tick().

Here is the call graph for this function:

◆ isEmpirical()

bool gum::IDiscretizedVariable::isEmpirical ( ) const
finalvirtualinherited
Returns
true if the tick is considered as empirical (relaxeds bounds)

Reimplemented from gum::DiscreteVariable.

◆ isTick()

template<typename T_TICKS>
bool gum::DiscretizedVariable< T_TICKS >::isTick ( const T_TICKS & aTick) const
Parameters
aTick
Returns
true if the tick already exists

References isTick().

Referenced by isTick().

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

◆ label()

template<typename T_TICKS>
std::string gum::DiscretizedVariable< T_TICKS >::label ( Idx i) const
overridevirtual
Parameters
i
Returns
the ith label
Exceptions
OutOfBound

Implements gum::DiscreteVariable.

References label().

Referenced by index(), and label().

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()

template<typename T_TICKS>
double gum::DiscretizedVariable< T_TICKS >::numerical ( Idx indice) const
overridevirtual

get a (deterministic) numerical representation of he indice-the value.

Implements gum::DiscreteVariable.

References numerical().

Referenced by numerical().

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

◆ operator=()

template<typename T_TICKS>
DiscretizedVariable< T_TICKS > & gum::DiscretizedVariable< T_TICKS >::operator= ( const DiscretizedVariable< T_TICKS > & aDRV)

operator =

Parameters
aDRVa labelized discrete random variable
Returns
a reference to *this

References DiscretizedVariable().

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:

◆ pos_()

template<typename T_TICKS>
Idx gum::DiscretizedVariable< T_TICKS >::pos_ ( const T_TICKS & target) const
protected

search the class of target (internally use dichotomy_)

Parameters
target
Returns
the class of target

◆ 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

◆ setEmpirical()

void gum::IDiscretizedVariable::setEmpirical ( bool state)
inherited
Parameters
state: change the variabl to empirical or not

References setEmpirical().

Referenced by setEmpirical().

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

◆ setName()

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

sets the name of the variable

Parameters
theValue

◆ stype()

template<typename T_TICKS>
std::string gum::DiscretizedVariable< T_TICKS >::stype ( ) const
inlinefinaloverridevirtual

string represent the type of the variable

Implements gum::DiscreteVariable.

Definition at line 193 of file discretizedVariable.h.

193{ return "Discretized"; };

References stype().

Referenced by stype().

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

◆ tick()

template<typename T_TICKS>
const T_TICKS & gum::DiscretizedVariable< T_TICKS >::tick ( Idx i) const

from the index to the tick.

Exceptions
NotFound

Referenced by index().

Here is the caller graph for this function:

◆ ticks()

template<typename T_TICKS>
const std::vector< T_TICKS > & gum::DiscretizedVariable< T_TICKS >::ticks ( ) const

Return the list of ticks.

Referenced by DiscretizedVariable().

Here is the caller graph for this function:

◆ ticksAsDoubles()

template<typename T_TICKS>
std::vector< double > gum::DiscretizedVariable< T_TICKS >::ticksAsDoubles ( ) const
overridevirtual

return the list of ticks as a vector of doubles

Implements gum::IDiscretizedVariable.

◆ toFast()

template<typename T_TICKS>
std::string gum::DiscretizedVariable< T_TICKS >::toFast ( ) const
overridevirtual
Returns
true if the domainSize() < 2;

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()

template<typename T_TICKS>
VarType gum::DiscretizedVariable< T_TICKS >::varType ( ) const
overridevirtual

returns the type of variable

Implements gum::DiscreteVariable.

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

◆ _is_empirical

bool gum::IDiscretizedVariable::_is_empirical
protectedinherited

Definition at line 112 of file IDiscretizedVariable.h.

◆ _name_

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

the name of the variable

Definition at line 160 of file variable.h.

◆ _ticks_

template<typename T_TICKS>
std::vector< T_TICKS > gum::DiscretizedVariable< T_TICKS >::_ticks_
private

Definition at line 78 of file discretizedVariable.h.


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