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

class IntegerVariable More...

#include <integerVariable.h>

Inheritance diagram for gum::IntegerVariable:
Collaboration diagram for gum::IntegerVariable:

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
 IntegerVariable (const std::string &aName, const std::string &aDesc="")
 constructor
 IntegerVariable (const std::string &aName, const std::string &aDesc, const std::vector< int > &domain)
 constructor assigning a domain to the variable
 IntegerVariable (const std::string &aName, const std::string &aDesc, int first, int last, Size nb)
 constructor assigning a domain to the variable
 IntegerVariable (const IntegerVariable &from)
 Copy constructor.
 IntegerVariable (IntegerVariable &&from) noexcept
 move constructor
IntegerVariableclone () const final
 virtual copy constructor
 ~IntegerVariable () final
 destructor
Operators
IntegerVariableoperator= (const IntegerVariable &from)
 copy operator
IntegerVariableoperator= (IntegerVariable &&from)
 move operator
Accessors / Modifiers
Size domainSize () const final
 returns the domain size of the discrete random variable
VarType varType () const final
 returns the type of variable
std::string toFast () const final
 returns the domain size of the discrete random variable
Idx index (const std::string &label) const final
 returns the index of a given label
Idx closestIndex (double val) const final
 returns the closest index of the value
std::string label (Idx index) const final
 returns a string corresponding to the ith value of the domain
double numerical (Idx index) const final
 get a integer representation of the value at a given index
std::string domain () const final
 Returns the domain as a string.
std::string stype () const final
 string represent the type of the variable
const std::vector< int > & integerDomain () const
 returns the domain as a sequence of values
void addValue (int value)
 add a new value to the domain size
bool isValue (int value) const
 does this value exist in the domain ?
void changeValue (int old_value, int new_value)
 substitute a value by another one
void eraseValue (int value)
 erase a value from the domain of the variable
void eraseValues ()
 clear the domain of the variable
std::string closestLabel (double val) const
 gives the value closets to val
Accessors / Modifiers
bool empty () const
std::vector< std::string > labels () const
 vector of labels
virtual bool isEmpirical () const
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 Variable &aRV)
 protected copy

Private Member Functions

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

Private Attributes

std::vector< int > _domain_
 the domain of 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 IntegerVariable

The class representing discrete integer random variables

Definition at line 62 of file integerVariable.h.

Constructor & Destructor Documentation

◆ IntegerVariable() [1/5]

gum::IntegerVariable::IntegerVariable ( const std::string & aName,
const std::string & aDesc = "" )

constructor

Parameters
aNamethe name of the variable
aDescthe Description of the variable, if any

References domain().

Referenced by IntegerVariable(), IntegerVariable(), IntegerVariable(), IntegerVariable(), ~IntegerVariable(), clone(), operator=(), and operator=().

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

◆ IntegerVariable() [2/5]

gum::IntegerVariable::IntegerVariable ( const std::string & aName,
const std::string & aDesc,
const std::vector< int > & domain )

constructor assigning a domain to the variable

Parameters
aNamethe name of the variable
aDescthe Description of the variable, if any
domainthe domain (set of values) of the variable

Definition at line 53 of file integerVariable.cpp.

55 :
56 DiscreteVariable(aName, aDesc) {
57 // get the values in increasing order
58 for (const auto value: domain) {
59 if (!gum::isfinite< double >(value)) {
60 GUM_ERROR(DefaultInLabel,
61 "Value '" << value << "' is not allowed for variable " << toString())
62 }
63 if (!isValue(value)) { _domain_.push_back(value); }
64 }
65 std::sort(_domain_.begin(), _domain_.end());
66
67 // for debugging purposes
68 GUM_CONSTRUCTOR(IntegerVariable)
69 }
DiscreteVariable()
(protected) Default constructor
std::string toString() const
string version of *this
std::string domain() const final
Returns the domain as a string.
std::vector< int > _domain_
the domain of the variable
IntegerVariable(const std::string &aName, const std::string &aDesc="")
constructor
bool isValue(int value) const
does this value exist in the domain ?
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
bool isfinite(T arg)
Definition math_utils.h:75

References gum::DiscreteVariable::DiscreteVariable(), IntegerVariable(), _domain_, domain(), GUM_ERROR, gum::isfinite(), isValue(), and gum::DiscreteVariable::toString().

Here is the call graph for this function:

◆ IntegerVariable() [3/5]

gum::IntegerVariable::IntegerVariable ( const std::string & aName,
const std::string & aDesc,
int first,
int last,
Size nb )

constructor assigning a domain to the variable

Parameters
aNamethe name of the variable
aDescthe Description of the variable, if any
firstthe first value
lastthe last value
nbthe number of values

Definition at line 72 of file integerVariable.cpp.

76 : DiscreteVariable(aName, aDesc) {
77 // store the sorted values into a sequence
78 if (nb < 2) GUM_ERROR(ArgumentError, "The size of the domain must be >2 (here :" << nb << ").")
79 if (first >= last)
80 GUM_ERROR(ArgumentError, "first (here :" << first << " must be <last (here :" << last << ").")
81
82 double step = (last - first) / double(nb - 1);
83 if (step <= 1)
84 GUM_ERROR(ArgumentError,
85 "With nb=" << nb << ", increment is less (or equal) than 1 ! (" << step << ")")
86
87 _domain_.resize(nb);
88 _domain_.clear();
89
90 _domain_.push_back(first);
91 double current = first;
92 for (Idx i = 1; i < nb - 1; i++) {
93 current += step;
94 _domain_.push_back(int(current));
95 }
96 _domain_.push_back(last);
97
98 std::sort(_domain_.begin(), _domain_.end());
99
100 // for debugging purposes
101 GUM_CONSTRUCTOR(IntegerVariable)
102 }
Size Idx
Type for indexes.
Definition types.h:79

References gum::DiscreteVariable::DiscreteVariable(), IntegerVariable(), _domain_, and GUM_ERROR.

Here is the call graph for this function:

◆ IntegerVariable() [4/5]

gum::IntegerVariable::IntegerVariable ( const IntegerVariable & from)

Copy constructor.

Parameters
fromthe variable we copy

References IntegerVariable().

Here is the call graph for this function:

◆ IntegerVariable() [5/5]

gum::IntegerVariable::IntegerVariable ( IntegerVariable && from)
noexcept

move constructor

References IntegerVariable().

Here is the call graph for this function:

◆ ~IntegerVariable()

gum::IntegerVariable::~IntegerVariable ( )
final

destructor

References IntegerVariable().

Here is the call graph for this function:

Member Function Documentation

◆ _checkSameDomain_()

bool gum::IntegerVariable::_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.

◆ addValue()

void gum::IntegerVariable::addValue ( int value)

add a new value to the domain size

Exceptions
DuplicateElementis raised if the variable already contains the value

◆ changeValue()

void gum::IntegerVariable::changeValue ( int old_value,
int new_value )

substitute a value by another one

◆ clone()

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

virtual copy constructor

Implements gum::DiscreteVariable.

References IntegerVariable().

Here is the call graph for this function:

◆ closestIndex()

Idx gum::IntegerVariable::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::IntegerVariable::closestLabel ( double val) const

gives the value closets to val

Parameters
valthe desired value
Returns
the value

◆ copy_()

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::IntegerVariable::domain ( ) const
finalvirtual

Returns the domain as a string.

Implements gum::DiscreteVariable.

Definition at line 105 of file integerVariable.cpp.

105 {
106 std::stringstream s;
107 const Size size = domainSize();
108
109 s << "{";
110 if (size > 0) {
111 s << _domain_[0];
112 for (Idx i = 1; i < size; ++i)
113 s << '|' << _domain_[i];
114 }
115 s << "}";
116 return s.str();
117 }
Size domainSize() const final
returns the domain size of the discrete random variable
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

References _domain_, and domainSize().

Referenced by IntegerVariable(), IntegerVariable(), and numerical().

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

◆ domainSize()

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

returns the domain size of the discrete random variable

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;

◆ eraseValue()

void gum::IntegerVariable::eraseValue ( int value)

erase a value from the domain of the variable

◆ eraseValues()

void gum::IntegerVariable::eraseValues ( )

clear the domain of the variable

◆ index()

Idx gum::IntegerVariable::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(), label(), and numerical().

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

◆ integerDomain()

const std::vector< int > & gum::IntegerVariable::integerDomain ( ) const

returns the domain as a sequence of values

◆ 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; };

◆ isValue()

bool gum::IntegerVariable::isValue ( int value) const

does this value exist in the domain ?

Referenced by IntegerVariable().

Here is the caller graph for this function:

◆ label()

std::string gum::IntegerVariable::label ( Idx index) const
finalvirtual

returns a string corresponding to the ith value of the domain

Implements gum::DiscreteVariable.

References index(), and 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()

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

get a integer representation of the value at a given index

Implements gum::DiscreteVariable.

References domain(), index(), and numerical().

Referenced by numerical().

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

◆ operator=() [1/2]

IntegerVariable & gum::IntegerVariable::operator= ( const IntegerVariable & from)

copy operator

Parameters
fromthe integer discrete random variable we copy

References IntegerVariable().

Here is the call graph for this function:

◆ operator=() [2/2]

IntegerVariable & gum::IntegerVariable::operator= ( IntegerVariable && from)

move operator

Parameters
fromthe integer discrete random variable we copy

References IntegerVariable().

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:

◆ 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::IntegerVariable::stype ( ) const
inlinefinalvirtual

string represent the type of the variable

Implements gum::DiscreteVariable.

Definition at line 165 of file integerVariable.h.

165{ return "Integer"; };

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::IntegerVariable::toFast ( ) const
finalvirtual

returns the domain size of the discrete random variable

Implements gum::DiscreteVariable.

References toFast().

Referenced by toFast().

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

◆ 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::IntegerVariable::varType ( ) const
finalvirtual

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.

◆ _domain_

std::vector< int > gum::IntegerVariable::_domain_
private

the domain of the variable

Definition at line 205 of file integerVariable.h.

Referenced by IntegerVariable(), IntegerVariable(), and domain().

◆ _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: