aGrUM  0.16.0
gum::RangeVariable Class Reference

Defines a discrete random variable over an integer interval. More...

#include <rangeVariable.h>

+ Inheritance diagram for gum::RangeVariable:
+ Collaboration diagram for gum::RangeVariable:

Public Member Functions

virtual const std::string domain () const
 string represent the domain of the variable More...
 
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
 RangeVariable (const std::string &aName, const std::string &aDesc, long minVal, long maxVal)
 constructors More...
 
 RangeVariable (const std::string &aName, const std::string &aDesc)
 by de default min=0, max=1 More...
 
 RangeVariable (const RangeVariable &aDRV)
 Copy Constructor. More...
 
virtual ~RangeVariable ()
 destructor More...
 
virtual DiscreteVariableclone () const
 Copy Factory. More...
 
Accessors / Modifiers
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 std::string label (Idx indice) const
 Get the indice-th label. More...
 
virtual double numerical (Idx indice) const
 get a numerical representation of he indice-the value. More...
 
long minVal () const
 Returns the lower bound. More...
 
void setMinVal (long minVal)
 Set a new value for the lower bound. More...
 
long maxVal () const
 Returns the upper bound. More...
 
void setMaxVal (long maxVal)
 Set a new value of the upper bound. More...
 
bool belongs (long val) const
 Returns true if the param belongs to the variable's interval. More...
 
virtual Idx index (const std::string &) const
 
Operators
RangeVariableoperator= (const RangeVariable &aRV)
 Copy operator. 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

void _copy (const Variable &aRV)
 protected copy More...
 

Detailed Description

Defines a discrete random variable over an integer interval.

It is technically possible to create RangeVariable with minVal > maxVal (or modify in that way an already created RangeVariable). The result is an empty variable (i.e. empty() returns true). If maxVal - minVal < 0, then domainsize() = 0.

Definition at line 54 of file rangeVariable.h.

Constructor & Destructor Documentation

◆ RangeVariable() [1/3]

gum::RangeVariable::RangeVariable ( const std::string &  aName,
const std::string &  aDesc,
long  minVal,
long  maxVal 
)

constructors

Definition at line 41 of file rangeVariable.cpp.

Referenced by clone().

44  :
45  DiscreteVariable(aName, aDesc),
47  GUM_CONSTRUCTOR(RangeVariable);
48  }
long __maxBound
The upper bound.
long minVal() const
Returns the lower bound.
long maxVal() const
Returns the upper bound.
RangeVariable(const std::string &aName, const std::string &aDesc, long minVal, long maxVal)
constructors
DiscreteVariable()
(protected) Default constructor
long __minBound
The lower bound.
+ Here is the caller graph for this function:

◆ RangeVariable() [2/3]

gum::RangeVariable::RangeVariable ( const std::string &  aName,
const std::string &  aDesc 
)

by de default min=0, max=1

Definition at line 50 of file rangeVariable.cpp.

51  :
52  DiscreteVariable(aName, aDesc),
53  __minBound(0), __maxBound(1) {
54  GUM_CONSTRUCTOR(RangeVariable);
55  }
long __maxBound
The upper bound.
RangeVariable(const std::string &aName, const std::string &aDesc, long minVal, long maxVal)
constructors
DiscreteVariable()
(protected) Default constructor
long __minBound
The lower bound.

◆ RangeVariable() [3/3]

gum::RangeVariable::RangeVariable ( const RangeVariable aDRV)

Copy Constructor.

If aDRV haves any listener, it will not be copied.

Parameters
aDRVthe variable we copy

Definition at line 62 of file rangeVariable.cpp.

62  :
63  DiscreteVariable(aDRV), __minBound(aDRV.__minBound),
64  __maxBound(aDRV.__maxBound) {
65  GUM_CONS_CPY(RangeVariable);
66  }
long __maxBound
The upper bound.
RangeVariable(const std::string &aName, const std::string &aDesc, long minVal, long maxVal)
constructors
DiscreteVariable()
(protected) Default constructor
long __minBound
The lower bound.

◆ ~RangeVariable()

gum::RangeVariable::~RangeVariable ( )
virtual

destructor

Definition at line 71 of file rangeVariable.cpp.

71 { GUM_DESTRUCTOR(RangeVariable); }
RangeVariable(const std::string &aName, const std::string &aDesc, long minVal, long maxVal)
constructors

Member Function Documentation

◆ _copy()

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

protected copy

Parameters
aRVto be copied

◆ belongs()

INLINE bool gum::RangeVariable::belongs ( long  val) const

Returns true if the param belongs to the variable's interval.

Definition at line 95 of file rangeVariable_inl.h.

References __maxBound, and __minBound.

Referenced by index(), and label().

95  {
96  return ((__minBound <= val) && (val <= __maxBound));
97  }
long __maxBound
The upper bound.
long __minBound
The lower bound.
+ Here is the caller graph for this function:

◆ clone()

INLINE DiscreteVariable * gum::RangeVariable::clone ( ) const
virtual

Copy Factory.

Returns
Returns a pointer on a new copy of this.

Implements gum::DiscreteVariable.

Definition at line 38 of file rangeVariable_inl.h.

References RangeVariable().

38  {
39  return new RangeVariable(*this);
40  }
RangeVariable(const std::string &aName, const std::string &aDesc, long minVal, long maxVal)
constructors
+ Here is the call graph for this function:

◆ description()

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

returns the description of the variable

◆ domain()

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

string represent the domain of the variable

Implements gum::DiscreteVariable.

Definition at line 73 of file rangeVariable.cpp.

References maxVal(), and minVal().

73  {
74  std::stringstream s;
75  s << "[" << minVal() << "-" << maxVal() << "]";
76  return s.str();
77  }
long minVal() const
Returns the lower bound.
long maxVal() const
Returns the upper bound.
+ Here is the call graph for this function:

◆ domainSize()

INLINE Size gum::RangeVariable::domainSize ( ) const
virtual

returns the size of the random discrete variable domain

Warning
: It is technically possible to create RangeVariable with minVal

maxVal

(or modify in that way an already created RangeVariable). The result is an empty variable (i.e. empty() returns true). If maxVal - minVal < 0, then domainsize() = 0.

Implements gum::DiscreteVariable.

Definition at line 43 of file rangeVariable_inl.h.

References __maxBound, and __minBound.

43  {
44  return (__maxBound < __minBound) ? Size(0) : Size(__maxBound + 1 - __minBound);
45  }
long __maxBound
The upper bound.
long __minBound
The lower bound.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48

◆ empty()

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

◆ index()

INLINE Idx gum::RangeVariable::index ( const std::string &  label) const
virtual
Returns
the modality index from the label
Exceptions
NotFound

Implements gum::DiscreteVariable.

Definition at line 67 of file rangeVariable_inl.h.

References __minBound, belongs(), and GUM_ERROR.

67  {
68  std::istringstream i(label);
69  long target;
70 
71  if (!(i >> target)) {
72  GUM_ERROR(NotFound, "Bad label : " << label << " for " << *this);
73  }
74 
75  if (!belongs(target)) {
76  GUM_ERROR(NotFound, "Bad label : " << label << " for " << *this);
77  }
78 
79  return static_cast< Idx >(target - __minBound);
80  }
bool belongs(long val) const
Returns true if the param belongs to the variable&#39;s interval.
virtual std::string label(Idx indice) const
Get the indice-th label.
long __minBound
The lower bound.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ label()

INLINE std::string gum::RangeVariable::label ( Idx  indice) const
virtual

Get the indice-th label.

Parameters
indicethe index of the label we wish to return
Exceptions
OutOfBound

Implements gum::DiscreteVariable.

Definition at line 50 of file rangeVariable_inl.h.

References __minBound, belongs(), and GUM_ERROR.

50  {
51  long target = static_cast< long >(indice) + __minBound;
52  if (belongs(target)) {
53  std::stringstream strBuff;
54  strBuff << target;
55  return strBuff.str();
56  } else {
57  GUM_ERROR(OutOfBounds, "Indice out of bounds.");
58  }
59  }
bool belongs(long val) const
Returns true if the param belongs to the variable&#39;s interval.
long __minBound
The lower bound.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ labels()

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

vector of labels

◆ maxVal()

INLINE long gum::RangeVariable::maxVal ( ) const

Returns the upper bound.

Definition at line 89 of file rangeVariable_inl.h.

References __maxBound.

Referenced by domain(), and setMaxVal().

89 { return __maxBound; }
long __maxBound
The upper bound.
+ Here is the caller graph for this function:

◆ minVal()

INLINE long gum::RangeVariable::minVal ( ) const

Returns the lower bound.

Definition at line 83 of file rangeVariable_inl.h.

References __minBound.

Referenced by domain(), and setMinVal().

83 { return __minBound; }
long __minBound
The lower bound.
+ 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::BNdistance< GUM_SCALAR >::__checkCompatibility(), gum::prm::PRMFactory< GUM_SCALAR >::__retrieveCommonType(), gum::prm::PRMFactory< GUM_SCALAR >::__retrieveInputs(), gum::BayesNetFactory< GUM_SCALAR >::__setCPTAndParents(), gum::GibbsBNdistance< GUM_SCALAR >::_computeKL(), gum::MultiDimImplementation< std::string >::add(), gum::Instantiation::add(), gum::FMDP< double >::addTransitionForAction(), gum::FMDP< double >::addVariable(), gum::MultiDimICIModel< GUM_SCALAR >::causalWeight(), gum::Instantiation::chgVal(), gum::learning::genericBNLearner::Database::Database(), gum::prm::PRMFactory< GUM_SCALAR >::endDiscreteType(), gum::prm::PRMFactory< GUM_SCALAR >::endDiscretizedType(), gum::FMDPFactory< GUM_SCALAR >::endVariableDeclaration(), gum::BayesNetFactory< GUM_SCALAR >::endVariableDeclaration(), gum::MarkovBlanket::hasSameStructure(), gum::BayesNetFragment< GUM_SCALAR >::nodeId(), gum::StructuredPlaner< double >::optimalPolicy2String(), gum::Estimator< GUM_SCALAR >::posterior(), gum::prm::PRMFormAttribute< GUM_SCALAR >::PRMFormAttribute(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::PRMScalarAttribute(), 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::MultiDimFunctionGraph< bool, ExactTerminalNodePolicy >::toDot(), gum::Estimator< GUM_SCALAR >::update(), and gum::MultiDimFunctionGraph< bool, ExactTerminalNodePolicy >::varNodeListe().

◆ numerical()

INLINE double gum::RangeVariable::numerical ( Idx  indice) const
virtual

get a numerical representation of he indice-the value.

Implements gum::DiscreteVariable.

Definition at line 62 of file rangeVariable_inl.h.

References __minBound.

62  {
63  return double(__minBound + static_cast< long >(indice));
64  }
long __minBound
The lower bound.

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

INLINE RangeVariable & gum::RangeVariable::operator= ( const RangeVariable aRV)

Copy operator.

Parameters
aRVto be copied
Returns
a ref to *this

Definition at line 102 of file rangeVariable_inl.h.

References __maxBound, and __minBound.

102  {
103  __minBound = aRV.__minBound;
104  __maxBound = aRV.__maxBound;
105  return *this;
106  }
long __maxBound
The upper bound.
long __minBound
The lower bound.

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

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

140 { 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:

◆ 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

◆ setMaxVal()

INLINE void gum::RangeVariable::setMaxVal ( long  maxVal)

Set a new value of the upper bound.

Definition at line 92 of file rangeVariable_inl.h.

References __maxBound, and maxVal().

92 { __maxBound = maxVal; }
long __maxBound
The upper bound.
long maxVal() const
Returns the upper bound.
+ Here is the call graph for this function:

◆ setMinVal()

INLINE void gum::RangeVariable::setMinVal ( long  minVal)

Set a new value for the lower bound.

Definition at line 86 of file rangeVariable_inl.h.

References __minBound, and minVal().

86 { __minBound = minVal; }
long minVal() const
Returns the lower bound.
long __minBound
The lower bound.
+ Here is the call graph for this function:

◆ setName()

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

sets the name of the variable

Parameters
theValue

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

+ Here is the caller graph for this function:

◆ toString()

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:

◆ toStringWithDescription()

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

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

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

+ Here is the caller graph for this function:

◆ varType()

INLINE VarType gum::RangeVariable::varType ( ) const
virtual

returns the type of variable

Implements gum::DiscreteVariable.

Definition at line 108 of file rangeVariable_inl.h.

References gum::Range.

Member Data Documentation

◆ __maxBound

long gum::RangeVariable::__maxBound
private

The upper bound.

Definition at line 164 of file rangeVariable.h.

Referenced by belongs(), domainSize(), maxVal(), operator=(), and setMaxVal().

◆ __minBound

long gum::RangeVariable::__minBound
private

The lower bound.

Definition at line 161 of file rangeVariable.h.

Referenced by belongs(), domainSize(), index(), label(), minVal(), numerical(), operator=(), and setMinVal().


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