aGrUM  0.17.2
a C++ library for (probabilistic) graphical models
gum::Instantiation Class Reference

Class for assigning/browsing values to tuples of discrete variables. More...

#include <agrum/tools/multidim/instantiation.h>

+ Inheritance diagram for gum::Instantiation:
+ Collaboration diagram for gum::Instantiation:

Public Member Functions

Constructors / Destructors
 Instantiation ()
 Default constructor: creates an empty tuple. More...
 
 Instantiation (const Instantiation &aI, const bool notifyMaster=true)
 Copy constructor. More...
 
Instantiationoperator= (const Instantiation &aI)
 Copy operator. More...
 
 Instantiation (MultiDimAdressable &aMD)
 Constructor for a Instantiation of all the variables of a MultiDimAdressable. More...
 
 Instantiation (const MultiDimAdressable &aMD)
 Constructor for a Instantiation of all the variables of a MultiDimAdressable. More...
 
 Instantiation (MultiDimAdressable *aMD)
 Constructor for a Instantiation of all the variables of a MultiDimAdressable. More...
 
 Instantiation (const MultiDimAdressable *aMD)
 Constructor for a Instantiation of all the variables of a MultiDimAdressable. More...
 
 ~Instantiation ()
 Destructor. More...
 
Accessors / Modifiers
Idx nbrDim () const final
 Returns the number of variables in the Instantiation. More...
 
void add (const DiscreteVariable &v) final
 Adds a new variable in the Instantiation. More...
 
void erase (const DiscreteVariable &v) final
 Removes a variable from the Instantiation. More...
 
void erase (const std::string &name)
 Returns the number of variables in the Instantiation. More...
 
void clear ()
 Erase all variables from an Instantiation. More...
 
Size domainSize () const final
 Returns the product of the variable's domain size in the Instantiation. More...
 
Idx pos (const DiscreteVariable &v) const final
 Returns the position of the variable v. More...
 
Idx val (Idx i) const
 Returns the current value of the variable at position i. More...
 
Idx val (const DiscreteVariable &var) const
 Returns the current value of a given variable. More...
 
Idx val (const std::string &name) const
 Returns the number of variables in the Instantiation. More...
 
Idx valFromPtr (const DiscreteVariable *pvar) const
 Returns the current value of a given variable. More...
 
const DiscreteVariablevariable (Idx i) const final
 Returns the variable at position i in the tuple. More...
 
const DiscreteVariablevariable (const std::string &name) const final
 Returns the variable with the name. More...
 
InstantiationchgVal (const DiscreteVariable &v, Idx newval)
 Assign newval to variable v in the Instantiation. More...
 
InstantiationchgVal (const DiscreteVariable *v, Idx newval)
 Assign newval to variable v in the Instantiation. More...
 
InstantiationchgVal (Idx varPos, Idx newval)
 Assign newval to variable at position varPos in the Instantiation. More...
 
InstantiationchgVal (const std::string &var, Idx newval)
 Assign newval to variable at position varPos in the Instantiation. More...
 
InstantiationchgVal (const std::string &var, const std::string &newval)
 Assign newval to variable at position varPos in the Instantiation. More...
 
InstantiationsetVals (const Instantiation &i)
 Assign the values from i in the Instantiation. More...
 
void setValsFrom (const HashTable< const DiscreteVariable *, const DiscreteVariable * > &map, const Instantiation &external)
 Assign the values of external in *this, using map as a bijection between external and this variables. More...
 
bool contains (const DiscreteVariable &v) const final
 Indicates whether a given variable belongs to the Instantiation. More...
 
bool contains (const std::string &name) const
 Returns the number of variables in the Instantiation. More...
 
bool contains (const DiscreteVariable *v) const
 Indicates whether a given variable belongs to the Instantiation. More...
 
const Sequence< const DiscreteVariable *> & variablesSequence () const final
 Returns the sequence of DiscreteVariable of this instantiation. More...
 
virtual bool empty () const final
 Returns true if the instantiation is empty. More...
 
Overflow management methods.
bool inOverflow () const
 Indicates whether the current value of the tuple is correct or not. More...
 
void unsetOverflow ()
 Removes the flag overflow. More...
 
void unsetEnd ()
 Alias for unsetOverflow(). More...
 
bool end () const
 Returns true if the Instantiation reached the end. More...
 
bool rend () const
 Returns true if the Instantiation reached the rend. More...
 
Incrementation and decrementation methods
void inc ()
 Operator increment. More...
 
void dec ()
 Operator decrement. More...
 
void incIn (const Instantiation &i)
 Operator increment for the variables in i. More...
 
void decIn (const Instantiation &i)
 Operator decrement for the variables in i. More...
 
void incOut (const Instantiation &i)
 Operator increment for the variables not in i. More...
 
void decOut (const Instantiation &i)
 Operator decrement for the variables not in i. More...
 
void incNotVar (const DiscreteVariable &v)
 Operator increment for vars which are not v. More...
 
void decNotVar (const DiscreteVariable &v)
 Operator decrement for vars which are not v. More...
 
void incVar (const DiscreteVariable &v)
 Operator increment for variable v only. More...
 
void decVar (const DiscreteVariable &v)
 Operator decrement for variable v only. More...
 
Initialization methods
void setFirst ()
 Assign the first values to the tuple of the Instantiation. More...
 
void setLast ()
 Assign the last values in the Instantiation. More...
 
void setFirstIn (const Instantiation &i)
 Assign the first values in the Instantiation for the variables in i. More...
 
void setLastIn (const Instantiation &i)
 Assign the last values in the Instantiation for the variables in i. More...
 
void setFirstOut (const Instantiation &i)
 Assign the first values in the Instantiation for the variables not in i. More...
 
void setLastOut (const Instantiation &i)
 Assign the last values in the Instantiation for the variables not in i. More...
 
void setFirstNotVar (const DiscreteVariable &v)
 Assign the first values to variables different of v. More...
 
void setLastNotVar (const DiscreteVariable &v)
 Assign the last values to variables different of v. More...
 
void setFirstVar (const DiscreteVariable &v)
 Assign the first value in the Instantiation for var v. More...
 
void setLastVar (const DiscreteVariable &v)
 Assign the last value in the Instantiation for var v. More...
 
Notification methods
bool actAsSlave (MultiDimAdressable &aMD)
 Tries to register the Instantiation to a MultiDimAdressable. More...
 
bool forgetMaster ()
 Deassociate the master MultiDimAdressable, if any. More...
 
bool isSlave () const
 Indicates whether the Instantiation has a master. More...
 
bool isMaster (const MultiDimAdressable *m) const
 Indicates whether m is the master of this instantiation. More...
 
bool isMaster (const MultiDimAdressable &m) const
 Indicates whether m is the master of this instantiation. More...
 
void synchronizeWithMaster (const MultiDimAdressable *m)
 Force the variables sequence to be the same as the master one. More...
 
void addWithMaster (const MultiDimAdressable *m, const DiscreteVariable &v)
 Call Instantiation::__add(const DiscreteVariable&) by master. More...
 
void eraseWithMaster (const MultiDimAdressable *m, const DiscreteVariable &v)
 Call Instantiation::__erase(const DiscreteVariable&) by master. More...
 
Operators
bool operator== (const Instantiation &other) const
 operator== More...
 
Instantiationoperator++ ()
 Alias of Instantiation::inc(). More...
 
Instantiationoperator-- ()
 Alias of Instantiation::dec(). More...
 
Instantiationoperator+= (Size depl)
 Calls depl times Instantiation::inc(). More...
 
Instantiationoperator-= (Size depl)
 Calls depl times Instantiation::dec(). More...
 
Various methods
Idx hamming () const
 Returns the hamming distance of this instantiation. More...
 
std::string toString () const
 Give a string version of instantiation. More...
 
void reorder (const Sequence< const DiscreteVariable * > &v)
 Reorder vars of this instantiation giving the order in v. More...
 
void reorder (const Instantiation &i)
 Calls reorder(const Sequence<const DiscreteVariable*>&) with i.variablesSequence() More...
 
Accessors / Modifiers
void replace (const DiscreteVariable &x, const DiscreteVariable &y)
 Replace variables in this multidim. More...
 

Protected Member Functions

virtual void _replace (const DiscreteVariable *x, const DiscreteVariable *y) final
 Replace x by y. More...
 

Detailed Description

Class for assigning/browsing values to tuples of discrete variables.

Instantiation is designed to assign values to tuples of variables and to efficiently loop over values of subsets of variables. This class can be used in two different flavors:

  • the tuple of variables in the Instantiation is related to a multidimensional array and, when we loop over the possible values of the tuple, we also loop at the same time over the corresponding values in the array.
  • the tuple of variables in the Instantiation is not related to a multidimensional array and we can loop over the possible values of the tuple without looping over values fo any array.

An Instantiation can be associated/deassociated to a given multidimensional array using the MultiDimAdressable::registerSlave(Instantiation& i) and MultiDimAdressable::unregisterSlave functions. Note that, to be registrable, the Instantiation must have precisely the same variables as the array. As a consequence, adding or removing a variable from a Instantiation associated to an array will unregister it. This behavior is compulsory as, if it were still associated, it would not be possible to retrieve a correct value of the array given a value of the Instantiation. For instance, if M[A,B,C] is an array indexed by Boolean variables A,B,C, Which value of M should be returned if B=0 and C=0? We do not know for sure as we do not know the value of A. Note also that, at any time, you can unregister a Instantiation from its master multidimensional array and you can ask to associate it (provided the tuple of variable match).

To print information about a Instantiation use the following function:

See also
operator<<(std::ostream&, const Instantiation&).

Definition at line 83 of file instantiation.h.

Constructor & Destructor Documentation

◆ Instantiation() [1/6]

gum::Instantiation::Instantiation ( )

Default constructor: creates an empty tuple.

Definition at line 40 of file instantiation.cpp.

40  : __master(nullptr), __overflow(false) {
41  GUM_CONSTRUCTOR(Instantiation);
42  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.

◆ Instantiation() [2/6]

gum::Instantiation::Instantiation ( const Instantiation aI,
const bool  notifyMaster = true 
)

Copy constructor.

Note that the Instantiation is by default associated to the same MultiDimAdressable as aI. This means that looping over values of the tuple will induce looping over the values of the MultiDimAdressable. Similarly, the value of the tuple is that of aI, and, if the Instantiation is slaved, its master is notified of the value of the Instantiation if notifyMaster is true.

Parameters
aIThe Instantiation we copy.
notifyMasterWhether or not notify master if exits.

Definition at line 103 of file instantiation.cpp.

References __master, __overflow, __vals, __vars, and actAsSlave().

103  :
104  MultiDimInterface(), __master(0), __overflow(false) {
105  // for debugging purposes
106  GUM_CONS_CPY(Instantiation);
107  // copy the content of aI
108  __vars = aI.__vars;
109  __vals = aI.__vals;
110  __overflow = aI.__overflow;
111 
112  if (aI.__master && notifyMaster) actAsSlave(*aI.__master);
113  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
bool actAsSlave(MultiDimAdressable &aMD)
Tries to register the Instantiation to a MultiDimAdressable.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ Instantiation() [3/6]

gum::Instantiation::Instantiation ( MultiDimAdressable aMD)

Constructor for a Instantiation of all the variables of a MultiDimAdressable.

The variables of the Instantiation are those of aMD (actually, they are shared in memory). All the variables of aMD belong to the tuple of variables to be instantiated.

Note that the Instantiation is by default associated to aMD, i.e., looping over values of the tuple will induce looping over the values of aMD. The value given to the tuple is the first possible value, that is, (0,...,0). If the Instantiation is slaved, its master is notified of the value of the Instantiation.

Parameters
aMDThe array the variables of which are those of the Instantiation.

Definition at line 68 of file instantiation.cpp.

References __init().

68  :
69  __master(0), __overflow(false) {
70  // for debugging purposes
71  GUM_CONSTRUCTOR(Instantiation);
72  __init(&d);
73  }
void __init(MultiDimAdressable *master)
Initialize this Instantiation.
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

◆ Instantiation() [4/6]

gum::Instantiation::Instantiation ( const MultiDimAdressable aMD)

Constructor for a Instantiation of all the variables of a MultiDimAdressable.

The variables of the Instantiation are those of aMD (actually, they are shared in memory). All the variables of aMD belong to the tuple of variables to be instantiated.

Note that the Instantiation is by default associated to aMD, i.e., looping over values of the tuple will induce looping over the values of aMD. The value given to the tuple is the first possible value, that is, (0,...,0). If the Instantiation is slaved, its master is notified of the value of the Instantiation.

Parameters
aMDThe array the variables of which are those of the Instantiation.

Definition at line 75 of file instantiation.cpp.

References __init().

75  :
76  __master(0), __overflow(false) {
77  // for debugging purposes
78  GUM_CONSTRUCTOR(Instantiation);
79  __init(const_cast< MultiDimAdressable* >(&d));
80  }
void __init(MultiDimAdressable *master)
Initialize this Instantiation.
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

◆ Instantiation() [5/6]

gum::Instantiation::Instantiation ( MultiDimAdressable aMD)

Constructor for a Instantiation of all the variables of a MultiDimAdressable.

The variables of the Instantiation are those of aMD (actually, they are shared in memory). All the variables of aMD belong to the tuple of variables to be instantiated.

Note that the Instantiation is by default associated to aMD, i.e., looping over values of the tuple will induce looping over the values of aMD. The value given to the tuple is the first possible value, that is, (0,...,0). If the Instantiation is slaved, its master is notified of the value of the Instantiation.

Parameters
aMDThe array the variables of which are those of the Instantiation.

Definition at line 83 of file instantiation.cpp.

References __init().

83  :
84  __master(0), __overflow(false) {
85  // for debugging purposes
86  GUM_CONSTRUCTOR(Instantiation);
87 
88  if (d) __init(d);
89  }
void __init(MultiDimAdressable *master)
Initialize this Instantiation.
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

◆ Instantiation() [6/6]

gum::Instantiation::Instantiation ( const MultiDimAdressable aMD)

Constructor for a Instantiation of all the variables of a MultiDimAdressable.

The variables of the Instantiation are those of aMD (actually, they are shared in memory). All the variables of aMD belong to the tuple of variables to be instantiated.

Note that the Instantiation is by default associated to aMD, i.e., looping over values of the tuple will induce looping over the values of aMD. The value given to the tuple is the first possible value, that is, (0,...,0). If the Instantiation is slaved, its master is notified of the value of the Instantiation.

Parameters
aMDThe array the variables of which are those of the Instantiation.

Definition at line 94 of file instantiation.cpp.

References __init().

94  :
95  __master(0), __overflow(false) {
96  // for debugging purposes
97  GUM_CONSTRUCTOR(Instantiation);
98 
99  if (const_d) __init(const_cast< MultiDimAdressable* >(const_d));
100  }
void __init(MultiDimAdressable *master)
Initialize this Instantiation.
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

◆ ~Instantiation()

gum::Instantiation::~Instantiation ( )

Destructor.

Definition at line 45 of file instantiation.cpp.

References __master, and gum::MultiDimAdressable::unregisterSlave().

45  {
46  GUM_DESTRUCTOR(Instantiation);
47  // unregister the Instantiation from its __master
48 
49  if (__master) __master->unregisterSlave(*this);
50  }
virtual bool unregisterSlave(Instantiation &i)=0
Unregister i as a slave of this MultiDimAdressable.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
Instantiation()
Default constructor: creates an empty tuple.
+ Here is the call graph for this function:

Member Function Documentation

◆ __add()

INLINE void gum::Instantiation::__add ( const DiscreteVariable v)
private

Adds a new var to the sequence of vars.

If variable v already belongs to the Instantiation tuple of variables, then nothing is done. In particular, no exception is thrown in this case.

Warning
note that this function does not deassociate the Instantiation from its master MultiDimAdressable, if any. To do so, use function add instead.
this function does not notify the master MultiDimAdressable, if any. Use in addition function chgVal or __chgVal if need be.
variable v is known to the Instantiation only by a pointer to it. As a result, this is not a copy of v that is used by Instantiation but rather v itself. As such, v should never be deleted from memory until the Instantiation is removed.
Parameters
vThe new var.
Exceptions
DuplicateElementRaised if v is already in this Instantiation.

Definition at line 799 of file instantiation_inl.h.

References __overflow, __vals, and __vars.

Referenced by __init(), add(), and addWithMaster().

799  {
800  __vars.insert(&v);
801  __vals.push_back(0);
802  __overflow = false;
803  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the caller graph for this function:

◆ __chgVal()

INLINE void gum::Instantiation::__chgVal ( Idx  varPos,
Idx  newVal 
)
private

Modifies internally the value of a given variable of the sequence.

In addition to modifying the value of the variable, the Instantiation informs its master MultiDimAdressable of the modification.

Parameters
varPosThe variable to change.
newValThe variable new value.

Definition at line 49 of file instantiation_inl.h.

References __masterChangeNotification(), and __vals.

Referenced by chgVal(), decIn(), decNotVar(), decOut(), decVar(), incIn(), incNotVar(), incOut(), incVar(), setFirstIn(), setFirstNotVar(), setFirstOut(), setFirstVar(), setLastIn(), setLastNotVar(), setLastOut(), setLastVar(), and setVals().

49  {
50  Idx oldVal = __vals[varPos];
51  __vals[varPos] = newVal;
52 
53  __masterChangeNotification(varPos, newVal, oldVal);
54  }
void __masterChangeNotification(Idx varPos, Idx newVal, Idx oldVal) const
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __erase()

INLINE void gum::Instantiation::__erase ( const DiscreteVariable v)
private

Removes a variable from the sequence of vars.

If variable v does not belong to the Instantiation tuple of variables, then nothing is done. In particular, no exception is thrown in this case.

Warning
this function does not notify the master MultiDimAdressable, if any.
note that this function does not deassociate the Instantiation from its master MultiDimAdressable, if any. To do so, use function removeDim instead.
Parameters
vThe variable to be erased from the tuple.

Definition at line 806 of file instantiation_inl.h.

References __vals, __vars, and pos().

Referenced by erase(), and eraseWithMaster().

806  {
807  // get the position of the variable
808  Idx pos = __vars.pos(&v);
809  __vars.erase(&v);
810  __vals.erase(__vals.begin() + pos);
811  }
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __init()

void gum::Instantiation::__init ( MultiDimAdressable master)
private

Initialize this Instantiation.

Parameters
masterThis Instantiation's master.

Definition at line 52 of file instantiation.cpp.

References __add(), __vals, __vars, actAsSlave(), gum::MultiDimAdressable::getMasterRef(), gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::size(), and gum::MultiDimInterface::variablesSequence().

Referenced by Instantiation().

52  {
53  // for speed issues
54  GUM_ASSERT(master != nullptr);
55 
56  const Sequence< const DiscreteVariable* >& v = master->variablesSequence();
57  __vars.resize(v.size());
58  __vals.reserve(v.size());
59  // fill the instantiation
60 
61  for (const auto var: v)
62  __add(*var);
63 
64  actAsSlave(master->getMasterRef());
65  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
bool actAsSlave(MultiDimAdressable &aMD)
Tries to register the Instantiation to a MultiDimAdressable.
void __add(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __masterChangeNotification()

void gum::Instantiation::__masterChangeNotification ( Idx  varPos,
Idx  newVal,
Idx  oldVal 
) const
private

Definition at line 198 of file instantiation.cpp.

References __master, __vars, and gum::MultiDimAdressable::changeNotification().

Referenced by __chgVal().

200  {
201  if (__master)
202  __master->changeNotification(*this, __vars[varPos], oldVal, newVal);
203  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval)=0
Listen to changes in a given Instantiation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __masterDecNotification()

void gum::Instantiation::__masterDecNotification ( ) const
private

Definition at line 215 of file instantiation.cpp.

References __master, and gum::MultiDimAdressable::setDecNotification().

Referenced by dec().

215  {
216  if (__master) __master->setDecNotification(*this);
217  }
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
virtual void setDecNotification(const Instantiation &i)=0
Listen to increment in each recorded Instantiation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __masterFirstNotification()

void gum::Instantiation::__masterFirstNotification ( ) const
private

Definition at line 205 of file instantiation.cpp.

References __master, and gum::MultiDimAdressable::setFirstNotification().

Referenced by inc(), and setFirst().

205  {
207  }
virtual void setFirstNotification(const Instantiation &i)=0
Listen to setFirst in a given Instantiation.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __masterIncNotification()

void gum::Instantiation::__masterIncNotification ( ) const
private

Definition at line 209 of file instantiation.cpp.

References __master, and gum::MultiDimAdressable::setIncNotification().

Referenced by inc().

209  {
210  if (__master) __master->setIncNotification(*this);
211  }
virtual void setIncNotification(const Instantiation &i)=0
Listen to increment in a given Instantiation.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __masterLastNotification()

void gum::Instantiation::__masterLastNotification ( ) const
private

Definition at line 212 of file instantiation.cpp.

References __master, and gum::MultiDimAdressable::setLastNotification().

Referenced by dec(), and setLast().

212  {
214  }
virtual void setLastNotification(const Instantiation &i)=0
Listen to setLast in a given Instantiation.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __notifiedDimChanged()

void gum::Instantiation::__notifiedDimChanged ( const Sequence< const DiscreteVariable * > &  v)
private

This function is called by the master (if any) when changes arise in its vars list.

Warning
No implementation of this method?
Parameters
vthe new vars list

◆ __reorder()

INLINE void gum::Instantiation::__reorder ( const Sequence< const DiscreteVariable * > &  v)
private

Reorder vars of this instantiation giving the order in v.

In the new order variables common to v and *this are placed first, then variables only in *this.

The variables only in v are ignored.

Parameters
vThe new order of variables in this Instantiation.

Definition at line 769 of file instantiation_inl.h.

References __swap(), gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::atPos(), contains(), pos(), and gum::SequenceImplementation< Key, Alloc, std::is_scalar< Key >::value >::size().

Referenced by reorder(), and synchronizeWithMaster().

770  {
771  Idx max = original.size();
772  Idx position = 0;
773  for (Idx i = 0; i < max; ++i) {
774  const DiscreteVariable* pv = original.atPos(i);
775 
776  if (contains(pv)) {
777  auto p = pos(*pv);
778  GUM_ASSERT(p >= position); // this var should not be
779  // already placed.
780  __swap(position, p);
781  position++;
782  }
783  }
784  }
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
void __swap(Idx i, Idx j)
Swap two variables in the Instantiation.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __swap()

INLINE void gum::Instantiation::__swap ( Idx  i,
Idx  j 
)
private

Swap two variables in the Instantiation.

Parameters
iThe first variable.
jThe second variable.

Definition at line 745 of file instantiation_inl.h.

References __vals, and __vars.

Referenced by __reorder().

745  {
746  if (i == j) return;
747 
748  __vars.swap(i, j);
749 
750  Idx v;
751  v = __vals[i];
752  __vals[i] = __vals[j];
753  __vals[j] = v;
754  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the caller graph for this function:

◆ _replace()

INLINE void gum::Instantiation::_replace ( const DiscreteVariable x,
const DiscreteVariable y 
)
finalprotectedvirtual

Replace x by y.

Parameters
xThe variable to replace.
yThe variable replacing x.

Implements gum::MultiDimInterface.

Definition at line 817 of file instantiation_inl.h.

References __vars.

818  {
819  __vars.setAtPos(__vars.pos(x), y);
820  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.

◆ actAsSlave()

bool gum::Instantiation::actAsSlave ( MultiDimAdressable aMD)

Tries to register the Instantiation to a MultiDimAdressable.

The function will actually register the Instantiation if and only if it has precisely the same variables as the MultiDimAdressable (by precisely, we mean a physical equality, that is, the variables are at the same places in memory).

Parameters
aMDThe multidimensional array which will be the master of *this
Returns
Returns true if and only if the Instantiation has been associated successfully to aMD.
Exceptions
OperationNotAllowedRaised if this instantiation has already a master.

Definition at line 248 of file instantiation.cpp.

References __master, GUM_ERROR, and gum::MultiDimAdressable::registerSlave().

Referenced by __init(), Instantiation(), and operator=().

248  {
249  // if __master : not allowed
250  if (__master != nullptr) {
251  GUM_ERROR(OperationNotAllowed, "in slave Instantiation");
252  }
253 
254  __master = &aMD;
255 
256  // perform the registration
257  if (aMD.registerSlave(*this)) {
258  return true;
259  } else {
260  __master = nullptr;
261  return false;
262  }
263  }
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ add()

INLINE void gum::Instantiation::add ( const DiscreteVariable v)
finalvirtual

Adds a new variable in the Instantiation.

If variable v already belongs to the Instantiation tuple of variables, then DuplicateElement is thrown in this case. The value of the new variable is set to that of index 0, that is, the first possible value for the variable. Since an instantiation must share the same set of variables with his master an OperationNotAllowed is raised if you try to add a variable of a slaved instantiation.

Warning
Variable v is known to the Instantiation only by a pointer to it. As a result, this is not a copy of v that is used by the Instantiation, but rather v itself. As such, v should never be deleted from memory until the Instantiation is removed.
Parameters
vThe new variable added to this Instantiation.
Exceptions
DuplicateElementRaised if v is already in this Instantiation.
InvalidArgumentRaised if the name of v is already used in this Instantiation.
OperationNotAllowedRaised if this is a slave Instantiation.

Implements gum::MultiDimInterface.

Definition at line 129 of file instantiation_inl.h.

References __add(), __master, __vars, GUM_ERROR, and gum::Variable::name().

Referenced by gum::MultiDimBucket< GUM_SCALAR >::__addVariable(), gum::SamplingInference< GUM_SCALAR >::_addVarSample(), gum::WeightedSampling< GUM_SCALAR >::_draw(), gum::ImportanceSampling< GUM_SCALAR >::_draw(), gum::AbstractSimulator::_randomState(), gum::SamplingInference< GUM_SCALAR >::contextualize(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::Potential< GUM_SCALAR >::fillWith(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::GibbsOperator< GUM_SCALAR >::monteCarloSample(), gum::FMDPSimulator::perform(), and gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns().

129  {
130  // if __master : not allowed
131  if (__master) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation"); }
132 
133  // check if the variable already belongs to the tuple of variables
134  // of the Instantiation
135  if (__vars.exists(&v)) {
136  GUM_ERROR(DuplicateElement,
137  "Var <" << v.name() << "> already exists in this instantiation");
138  }
139 
140  for (const auto& vv: __vars) {
141  if (vv->name() == v.name()) {
142  GUM_ERROR(InvalidArgument,
143  "Var with name <" << v.name()
144  << "> already exists in this instantiation");
145  }
146  }
147 
148  // actually add the new dimension
149  __add(v);
150  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
void __add(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addWithMaster()

INLINE void gum::Instantiation::addWithMaster ( const MultiDimAdressable m,
const DiscreteVariable v 
)

Call Instantiation::__add(const DiscreteVariable&) by master.

Parameters
mThe master of this instantiation.
vThe varaible to add.
Exceptions
OperationNotAllowedRaised if m is not hte master of this instantiation.

Definition at line 788 of file instantiation_inl.h.

References __add(), __master, and GUM_ERROR.

789  {
790  if (m != __master) {
791  GUM_ERROR(OperationNotAllowed, "only master can do this");
792  }
793 
794  __add(v);
795  }
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
void __add(const DiscreteVariable &v)
Adds a new var to the sequence of vars.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ chgVal() [1/5]

INLINE Instantiation & gum::Instantiation::chgVal ( const DiscreteVariable v,
Idx  newval 
)

Assign newval to variable v in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
vThe variable whose value is assigned.
newvalThe index of the value assigned.
Returns
Returns a reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if variable v does not belong to the instantiation.
OutOfBoundRaised if newval is not a possible value for v.

Definition at line 57 of file instantiation_inl.h.

References __chgVal(), __overflow, __vars, gum::DiscreteVariable::domainSize(), GUM_ERROR, and gum::Variable::name().

Referenced by gum::BayesNetInference< GUM_SCALAR >::__createHardEvidence(), gum::GibbsOperator< GUM_SCALAR >::__drawVarMonteCarlo(), gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::GibbsOperator< GUM_SCALAR >::__GibbsSample(), gum::TaxiSimulator::__performFillUp(), gum::TaxiSimulator::__performGoEast(), gum::TaxiSimulator::__performGoNorth(), gum::TaxiSimulator::__performGoSouth(), gum::TaxiSimulator::__performGoWest(), gum::TaxiSimulator::__performPickUp(), gum::TaxiSimulator::__performPutDown(), gum::SamplingInference< GUM_SCALAR >::_addVarSample(), gum::MultiDimWithOffset< GUM_SCALAR >::_computeInstantiationValue(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::WeightedSampling< GUM_SCALAR >::_draw(), gum::ImportanceSampling< GUM_SCALAR >::_draw(), gum::AbstractSimulator::_randomState(), chgVal(), gum::SamplingInference< GUM_SCALAR >::contextualize(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::Potential< GUM_SCALAR >::fillWith(), gum::GibbsOperator< GUM_SCALAR >::monteCarloSample(), gum::FMDPSimulator::perform(), gum::TaxiSimulator::perform(), gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule(), gum::BayesNetFactory< GUM_SCALAR >::setParentModality(), and setValsFrom().

58  {
59  try {
60  // check that the variable does belong to the instantiation and that the
61  // new
62  // value is possible.
63  Idx varPos = __vars.pos(&v); // throws NotFound if v doesn't belong to this
64 
65  if (newVal >= v.domainSize()) { GUM_ERROR(OutOfBounds, ""); }
66 
67  // if we were in overflow, indicate that we are not anymore
68  __overflow = false;
69 
70  __chgVal(varPos, newVal);
71 
72  return *this;
73  } catch (NotFound&) {
74  std::string name = "instantiation does not contain this DiscreteVariable: ";
75  GUM_ERROR(NotFound, name + v.name());
76  }
77  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ chgVal() [2/5]

INLINE Instantiation & gum::Instantiation::chgVal ( const DiscreteVariable v,
Idx  newval 
)

Assign newval to variable v in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
vThe variable whose value is assigned.
newvalThe index of the value assigned.
Returns
Returns a reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if variable v does not belong to the instantiation.
OutOfBoundRaised if newval is not a possible value for v.

Definition at line 79 of file instantiation_inl.h.

References __chgVal(), __overflow, __vars, gum::DiscreteVariable::domainSize(), GUM_ERROR, and gum::Variable::name().

80  {
81  try {
82  // check that the variable does belong to the instantiation and that the
83  // new
84  // value is possible.
85  Idx varPos = __vars.pos(v); // throws NotFound if v doesn't belong to this
86 
87  if (newVal >= v->domainSize()) { GUM_ERROR(OutOfBounds, ""); }
88 
89  // if we were in overflow, indicate that we are not anymore
90  __overflow = false;
91 
92  __chgVal(varPos, newVal);
93 
94  return *this;
95  } catch (NotFound&) {
96  std::string name = "instantiation does not contain this DiscreteVariable: ";
97  GUM_ERROR(NotFound, name + v->name());
98  }
99  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ chgVal() [3/5]

INLINE Instantiation & gum::Instantiation::chgVal ( Idx  varPos,
Idx  newval 
)

Assign newval to variable at position varPos in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
varPosThe index of the variable whose value is assigned in the tuple of variables of the Instantiation.
newvalThe index of the value assigned.
Returns
A reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if the variable does not belong to this
OutOfBoundRaised if newval is not a possible value for the variable

Definition at line 102 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, domainSize(), and GUM_ERROR.

102  {
103  // check that the variable does belong to the instantiation and that the new
104  // value is possible.
105  if (__vals.size() <= varPos) { GUM_ERROR(NotFound, ""); }
106 
107  if (newVal >= __vars[varPos]->domainSize()) { GUM_ERROR(OutOfBounds, ""); }
108 
109  // if we were in overflow, indicate that we are not anymore
110  __overflow = false;
111 
112  __chgVal(varPos, newVal);
113 
114  return *this;
115  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ chgVal() [4/5]

INLINE Instantiation & gum::Instantiation::chgVal ( const std::string &  var,
Idx  newval 
)

Assign newval to variable at position varPos in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
varthe name of the variable whose value is assigned in the tuple of variables of the Instantiation.
newvalThe index of the value assigned.
Returns
A reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if the variable does not belong to this
NotFoundRaised if newval is not a possible value for the variable

Definition at line 117 of file instantiation_inl.h.

References chgVal(), and variable().

117  {
118  return chgVal(variable(var), newVal);
119  }
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ chgVal() [5/5]

INLINE Instantiation & gum::Instantiation::chgVal ( const std::string &  var,
const std::string &  newval 
)

Assign newval to variable at position varPos in the Instantiation.

Consider the values of v as an array indexed from 0 to n of values (which might be anything from real numbers to strings, etc). Parameter newval indicates the index in this array of the new value taken by v.

In addition to modifying the value of the variable, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

Parameters
varthe name of the variable whose value is assigned in the tuple of variables of the Instantiation.
newvalThe label of the value assigned.
Returns
A reference to *this in order to chain the chgVal.
Exceptions
NotFoundRaised if the variable does not belong to this
OutOfBoundRaised if newval is not a possible value for the variable

Definition at line 121 of file instantiation_inl.h.

References chgVal(), pos(), and variable().

122  {
123  const auto& vv = variable(var);
124  Idx pos = vv.index(newVal);
125  return chgVal(vv, pos);
126  }
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ clear()

INLINE void gum::Instantiation::clear ( )

Erase all variables from an Instantiation.

Exceptions
OperationNotAllowedRaised if the instantiation is a slave.

Definition at line 171 of file instantiation_inl.h.

References __master, __vals, __vars, and GUM_ERROR.

Referenced by gum::WeightedSampling< GUM_SCALAR >::_draw(), gum::MonteCarloSampling< GUM_SCALAR >::_draw(), and gum::ImportanceSampling< GUM_SCALAR >::_draw().

171  {
172  if (__master) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation"); }
173 
174  __vars.clear();
175  __vals.clear();
176  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the caller graph for this function:

◆ contains() [1/3]

INLINE bool gum::Instantiation::contains ( const DiscreteVariable v) const
finalvirtual

Indicates whether a given variable belongs to the Instantiation.

Parameters
vThe variable for which the test is made.
Returns
Returns true if v is in the Instantiation.

Implements gum::MultiDimInterface.

Definition at line 35 of file instantiation_inl.h.

References __vars.

Referenced by __reorder(), gum::MultiDimWithOffset< GUM_SCALAR >::_getOffs(), contains(), decIn(), decOut(), gum::MultiDimContainer< GUM_SCALAR >::extractFrom(), incIn(), incOut(), operator=(), operator==(), gum::MultiDimImplementation< std::string >::registerSlave(), setFirstIn(), setFirstOut(), setLastIn(), setLastOut(), setVals(), and gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked().

35  {
36  return __vars.exists(&v);
37  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
+ Here is the caller graph for this function:

◆ contains() [2/3]

INLINE bool gum::Instantiation::contains ( const std::string &  name) const

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Definition at line 39 of file instantiation_inl.h.

References contains(), and variable().

39  {
40  return contains(variable(name));
41  }
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ contains() [3/3]

INLINE bool gum::Instantiation::contains ( const DiscreteVariable v) const

Indicates whether a given variable belongs to the Instantiation.

Parameters
vA pointer on the variable for which the test is made.
Returns
Returns true if *v is in the Instantiation.

Definition at line 44 of file instantiation_inl.h.

References __vars.

44  {
45  return __vars.exists(v);
46  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.

◆ dec()

INLINE void gum::Instantiation::dec ( )

Operator decrement.

Note that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). If the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. If we already reached the end() or the rend() of the possible values, function inc() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Usage example:

for(Instantiation i.setLast();! i.rend(); i.dec()) {
// code
}

Definition at line 285 of file instantiation_inl.h.

References __masterDecNotification(), __masterLastNotification(), __overflow, __vals, __vars, and nbrDim().

Referenced by operator--(), and operator-=().

285  {
286  Size p = nbrDim();
287  if (p == 0) { __overflow = true; }
288 
289  if (__overflow) return;
290  p -= 1;
291  Idx cpt = 0;
292  // if we are in overflow, do nothing
293 
294  // perform the increment
295  while (true) {
296  Idx v = __vals[cpt];
297 
298  if (v == 0) {
299  __vals[cpt] = __vars[cpt]->domainSize() - 1;
300 
301  if (cpt == p) {
302  __overflow = true;
303 
305 
306  return;
307  } else
308  ++cpt;
309  } else {
310  --__vals[cpt];
311  break;
312  }
313  }
314 
316  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
void __masterDecNotification() const
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __masterLastNotification() const
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decIn()

INLINE void gum::Instantiation::decIn ( const Instantiation i)

Operator decrement for the variables in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated.

Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). Finally, let us mention that the value of instantiation i is not taken into account, that is, only the variables belonging to i are taken into account. The next value of *this is thus computed w.r.t. to the current value of *this. If we already reached the end() or the rend() of the possible values, function incIn() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
iThe set of variables to decrement in this Instantiation.

Definition at line 416 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, contains(), domainSize(), nbrDim(), pos(), and variable().

416  {
417  Size p = i.nbrDim() - 1;
418  Idx i_cpt = 0;
419  // if we are in overflow, do nothing
420 
421  if (__overflow) return;
422 
423  while (true) {
424  // verify that __vars[cpt] belongs to i before incrementing its value
425  const DiscreteVariable& v = i.variable(i_cpt);
426 
427  if (!contains(v)) {
428  if (i_cpt == p) {
429  __overflow = true;
430  return;
431  } else
432  ++i_cpt;
433  } else {
434  Idx cpt = pos(v);
435  Idx iv = __vals[cpt];
436 
437  if (iv == 0) {
438  __chgVal(cpt, __vars[cpt]->domainSize() - 1);
439 
440  if (i_cpt == p) {
441  __overflow = true;
442  return;
443  } else
444  ++i_cpt;
445  } else {
446  __chgVal(cpt, iv - 1);
447  return;
448  }
449  }
450  }
451  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ decNotVar()

INLINE void gum::Instantiation::decNotVar ( const DiscreteVariable v)

Operator decrement for vars which are not v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated.

Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). If we already reached the end() or the rend() of the possible values, function incNotVar() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
vThe varaible not to decrement in this Instantiation.

Definition at line 609 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, domainSize(), and nbrDim().

609  {
610  Size p = nbrDim() - 1;
611  Idx cpt = 0;
612  // if we are in overflow, do nothing
613 
614  if (__overflow) return;
615 
616  while (true) {
617  if (__vars[cpt] == &v) {
618  if (cpt == p) {
619  __overflow = true;
620  return;
621  } else
622  ++cpt;
623  } else {
624  Idx iv = __vals[cpt];
625 
626  if (iv == 0) {
627  __chgVal(cpt, __vars[cpt]->domainSize() - 1);
628 
629  if (cpt == p) {
630  __overflow = true;
631  return;
632  } else
633  ++cpt;
634  } else {
635  __chgVal(cpt, iv - 1);
636  return;
637  }
638  }
639  }
640  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ decOut()

INLINE void gum::Instantiation::decOut ( const Instantiation i)

Operator decrement for the variables not in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). Finally, let us mention that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. The next value of *this is thus computed w.r.t. to the current value of *this. If we already reached the end() or the rend() of the possible values, function incerr() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
iThe set of variables to not decrement in this Instantiation.

Definition at line 522 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, contains(), domainSize(), and nbrDim().

522  {
523  Size p = nbrDim() - 1;
524  Idx cpt = 0;
525  // if we are in overflow, do nothing
526 
527  if (__overflow) return;
528 
529  while (true) {
530  if (i.contains(__vars[cpt])) {
531  if (cpt == p) {
532  __overflow = true;
533  return;
534  } else
535  ++cpt;
536  } else {
537  Idx v = __vals[cpt];
538 
539  if (v == 0) {
540  __chgVal(cpt, __vars[cpt]->domainSize() - 1);
541 
542  if (cpt == p) {
543  __overflow = true;
544  return;
545  } else
546  ++cpt;
547  } else {
548  __chgVal(cpt, v - 1);
549  return;
550  }
551  }
552  }
553  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ decVar()

INLINE void gum::Instantiation::decVar ( const DiscreteVariable v)

Operator decrement for variable v only.

This function decrement only variable v. Trying to decrement the last possible value results in an overflow (no exception is thrown in this case). If we already reached the end() or the rend() of the possible values, function incVar() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
vThe variable to decrement in this Instantiation.
Exceptions
NotFoundRaised if variable v does not belong to the Instantiation.

Definition at line 695 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, and gum::DiscreteVariable::domainSize().

695  {
696  // get the position of the variable
697  Idx cpt = __vars.pos(&v);
698  // if we are in overflow, do nothing
699 
700  if (__overflow) return;
701 
702  Idx p = __vals[cpt];
703 
704  if (p == 0) {
705  __chgVal(cpt, v.domainSize() - 1);
706  __overflow = true;
707  } else {
708  __chgVal(cpt, p - 1);
709  }
710  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ domainSize()

INLINE Size gum::Instantiation::domainSize ( ) const
finalvirtual

Returns the product of the variable's domain size in the Instantiation.

Returns
Returns the product of the variable's domain size in the Instantiation.

Implements gum::MultiDimInterface.

Definition at line 180 of file instantiation_inl.h.

References __vars.

Referenced by chgVal(), decIn(), decNotVar(), decOut(), inc(), incIn(), incNotVar(), incOut(), setLast(), setLastIn(), setLastOut(), and gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked().

180  {
181  // @todo enhance the cplxity with a member domainSize ?
182  Size s = 1;
183 
184  for (const auto var: __vars)
185  s *= var->domainSize();
186 
187  return s;
188  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the caller graph for this function:

◆ empty()

INLINE bool gum::Instantiation::empty ( ) const
finalvirtual

Returns true if the instantiation is empty.

Returns
Returns true if the instantiation is empty.

Implements gum::MultiDimInterface.

Definition at line 814 of file instantiation_inl.h.

References __vals.

Referenced by gum::MultiDimBucket< GUM_SCALAR >::_commitMultipleChanges(), and gum::AbstractSimulator::hasReachEnd().

814 { return __vals.empty(); }
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the caller graph for this function:

◆ end()

INLINE bool gum::Instantiation::end ( ) const

Returns true if the Instantiation reached the end.

Function end() should be used as in:

for(Instantiation i.setFirst();! i.end(); ++i) {
// code
}
Returns
Returns true if the Instantiation reached the end.

Definition at line 240 of file instantiation_inl.h.

References inOverflow().

Referenced by gum::MultiDimBucket< GUM_SCALAR >::__computeValue(), gum::prm::PRMFormAttribute< GUM_SCALAR >::__fillCpf(), gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::prm::PRMSystem< double >::__groundPotential(), gum::prm::StructuredBayesBall< GUM_SCALAR >::__isHardEvidence(), gum::BayesNetInference< GUM_SCALAR >::__isHardEvidence(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__threadUpdate(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::prm::PRMFormAttribute< GUM_SCALAR >::_type(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::_type(), gum::prm::PRMInference< double >::addEvidence(), gum::MultiDimContainer< GUM_SCALAR >::apply(), gum::prm::PRMFormAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::o3prmr::O3prmrInterpreter::checkObserve(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::MultiDimBucket< GUM_SCALAR >::compute(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copy(), gum::MultiDimContainer< GUM_SCALAR >::copyFrom(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::Potential< GUM_SCALAR >::draw(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::MultiDimContainer< GUM_SCALAR >::extractFrom(), gum::Potential< GUM_SCALAR >::fillWith(), gum::Potential< GUM_SCALAR >::findAll(), gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT(), gum::JointTargetedInference< GUM_SCALAR >::I(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::Potential< GUM_SCALAR >::KL(), gum::Potential< GUM_SCALAR >::normalizeAsCPT(), gum::prm::PRMInference< double >::operator=(), gum::learning::DAG2BNLearner< ALLOC >::operator=(), gum::IBayesNet< double >::operator==(), gum::MultiDimContainer< GUM_SCALAR >::operator==(), gum::FMDPSimulator::perform(), gum::MultiDimContainer< GUM_SCALAR >::populate(), gum::prm::PRMInference< double >::PRMInference(), gum::prm::o3prmr::O3prmrInterpreter::query(), gum::MultiDimContainer< GUM_SCALAR >::reduce(), gum::Estimator< GUM_SCALAR >::setFromLBP(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::prm::PRMFormAttribute< GUM_SCALAR >::swap(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::swap(), and gum::MultiDimContainer< GUM_SCALAR >::toString().

240 { return inOverflow(); }
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
+ Here is the call graph for this function:

◆ erase() [1/2]

INLINE void gum::Instantiation::erase ( const DiscreteVariable v)
finalvirtual

Removes a variable from the Instantiation.

If variable v does not belong to the Instantiation tuple of variables, then NotFound is thrown. Since an instantiation must share the same set of variables with his master an OperationNotAllowed is raised if you try to remove a variable from a slaved instantiation.

Parameters
vThe variable to remove from this Instantiation.
Exceptions
NotFoundRaised if v does not belong to this Instantiation.
OperationNotAllowedRaised if the instantiation is a slave.

Implements gum::MultiDimInterface.

Definition at line 153 of file instantiation_inl.h.

References __erase(), __master, __vars, and GUM_ERROR.

Referenced by gum::GibbsOperator< GUM_SCALAR >::__drawVarMonteCarlo(), gum::MultiDimBucket< GUM_SCALAR >::__eraseVariable(), gum::GibbsOperator< GUM_SCALAR >::__GibbsSample(), gum::MultiDimBucket< GUM_SCALAR >::_commitMultipleChanges(), erase(), and gum::credal::CredalNet< GUM_SCALAR >::toString().

153  {
154  // if __master : not allowed
155  if (__master) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation"); }
156 
157  // check that the variable does actually belong to the Instantiation
158  if (!__vars.exists(&v)) {
159  GUM_ERROR(NotFound, "Var does not exist in this instantiation");
160  }
161 
162  // actually delete the dimension
163  __erase(v);
164  }
void __erase(const DiscreteVariable &v)
Removes a variable from the sequence of vars.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ erase() [2/2]

INLINE void gum::Instantiation::erase ( const std::string &  name)

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Definition at line 166 of file instantiation_inl.h.

References erase(), and variable().

166  {
167  erase(variable(name));
168  }
void erase(const DiscreteVariable &v) final
Removes a variable from the Instantiation.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ eraseWithMaster()

void gum::Instantiation::eraseWithMaster ( const MultiDimAdressable m,
const DiscreteVariable v 
)

Call Instantiation::__erase(const DiscreteVariable&) by master.

Parameters
mThe master of this instantiation.
vThe variable to remove.
Exceptions
OperationNotAllowedRaised if m is not the master of this instantiation.

Definition at line 236 of file instantiation.cpp.

References __erase(), __master, GUM_ERROR, and gum::MultiDimAdressable::setChangeNotification().

237  {
238  if (m != __master) {
239  GUM_ERROR(OperationNotAllowed, "only master can do this");
240  }
241 
242  __erase(v);
243 
245  }
void __erase(const DiscreteVariable &v)
Removes a variable from the sequence of vars.
virtual void setChangeNotification(const Instantiation &i)=0
Listen to an assignment of a value in a Instantiation.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ forgetMaster()

bool gum::Instantiation::forgetMaster ( )

Deassociate the master MultiDimAdressable, if any.

Returns
Returns true if and only if the Instantiation has been unregistered.

Definition at line 220 of file instantiation.cpp.

References __master, and gum::MultiDimAdressable::unregisterSlave().

Referenced by gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), gum::credal::CredalNet< GUM_SCALAR >::setCPT(), and gum::credal::CredalNet< GUM_SCALAR >::toString().

220  {
221  if (__master) {
222  __master->unregisterSlave(*this);
223  __master = nullptr;
224  }
225  return true;
226  }
virtual bool unregisterSlave(Instantiation &i)=0
Unregister i as a slave of this MultiDimAdressable.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hamming()

Idx gum::Instantiation::hamming ( ) const

Returns the hamming distance of this instantiation.

Returns
Returns the hamming distance of this instantiation.

Definition at line 167 of file instantiation.cpp.

References __vars, and val().

167  {
168  Idx res = 0;
169 
170  for (const auto var: __vars)
171  res += val(*var);
172 
173  return res;
174  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
Idx val(Idx i) const
Returns the current value of the variable at position i.
+ Here is the call graph for this function:

◆ inc()

INLINE void gum::Instantiation::inc ( )

Operator increment.

Note that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). If the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. If we already reached the end() or the rend() of the possible values, function inc() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Usage example:

for(Instantiation i.setFirst();! i.end(); i.inc()) {
// code
}

Definition at line 253 of file instantiation_inl.h.

References __masterFirstNotification(), __masterIncNotification(), __overflow, __vals, __vars, domainSize(), and nbrDim().

Referenced by gum::prm::PRMFormAttribute< GUM_SCALAR >::__fillCpf(), gum::prm::PRMSystem< double >::__groundPotential(), gum::prm::StructuredBayesBall< GUM_SCALAR >::__isHardEvidence(), gum::BayesNetInference< GUM_SCALAR >::__isHardEvidence(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::prm::GroundedInference< GUM_SCALAR >::_evidenceAdded(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::prm::PRMFormAttribute< GUM_SCALAR >::_type(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::_type(), gum::prm::PRMInference< double >::addEvidence(), gum::prm::PRMFormAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::o3prmr::O3prmrInterpreter::checkObserve(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::MultiDimBucket< GUM_SCALAR >::compute(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copy(), gum::Potential< GUM_SCALAR >::draw(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::Potential< GUM_SCALAR >::KL(), gum::prm::PRMInference< double >::marginal(), operator++(), operator+=(), gum::prm::PRMInference< double >::operator=(), gum::IBayesNet< double >::operator==(), gum::prm::PRMInference< double >::PRMInference(), gum::prm::o3prmr::O3prmrInterpreter::query(), gum::prm::PRMFormAttribute< GUM_SCALAR >::swap(), and gum::prm::PRMScalarAttribute< GUM_SCALAR >::swap().

253  {
254  Size p = nbrDim();
255  if (p == 0) { __overflow = true; }
256 
257  if (__overflow) return;
258  p -= 1;
259  Idx cpt = 0;
260  // if we are in overflow, do nothing
261 
262  // perform the increment
263  while (true) {
264  Idx v = __vals[cpt];
265 
266  if (v + 1 == __vars[cpt]->domainSize()) {
267  __vals[cpt] = 0;
268 
269  if (cpt == p) {
270  __overflow = true;
272  return;
273  } else
274  ++cpt;
275  } else {
276  ++__vals[cpt];
277  break;
278  }
279  }
280 
282  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __masterIncNotification() const
void __masterFirstNotification() const
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ incIn()

INLINE void gum::Instantiation::incIn ( const Instantiation i)

Operator increment for the variables in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated.

Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). Finally, let us mention that the value of instantiation i is not taken into account, that is, only the variables belonging to i are taken into account. The next value of *this is thus computed w.r.t. to the current value of *this. If we already reached the end() or the rend() of the possible values, function incIn() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
iThe set of variables to increment in this Instantiation.

Definition at line 371 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, contains(), domainSize(), nbrDim(), pos(), and variable().

Referenced by gum::MultiDimContainer< GUM_SCALAR >::copyFrom(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), and gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked().

371  {
372  // if i is empty, overflow and do nothing
373  if (i.nbrDim() == 0) {
374  __overflow = true;
375  return;
376  }
377 
378  // if we are in overflow, do nothing
379  if (__overflow) return;
380 
381  Size p = i.nbrDim() - 1;
382 
383  Idx i_cpt = 0;
384 
385  while (true) {
386  // verify that __vars[cpt] belongs to i before incrementing its value
387  const DiscreteVariable& v = i.variable(i_cpt);
388 
389  if (!contains(v)) {
390  if (i_cpt == p) {
391  __overflow = true;
392  return;
393  } else
394  ++i_cpt;
395  } else {
396  Idx cpt = pos(v);
397  Idx iv = __vals[cpt];
398 
399  if (iv + 1 == __vars[cpt]->domainSize()) {
400  __chgVal(cpt, 0);
401 
402  if (i_cpt == p) {
403  __overflow = true;
404  return;
405  } else
406  ++i_cpt;
407  } else {
408  __chgVal(cpt, iv + 1);
409  return;
410  }
411  }
412  }
413  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ incNotVar()

INLINE void gum::Instantiation::incNotVar ( const DiscreteVariable v)

Operator increment for vars which are not v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). If we already reached the end() or the rend() of the possible values, function incNotVar() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
vThe variable not to increment in this Instantiation.

Definition at line 575 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, domainSize(), and nbrDim().

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT(), and gum::Potential< GUM_SCALAR >::normalizeAsCPT().

575  {
576  Size p = nbrDim() - 1;
577  Idx cpt = 0;
578  // if we are in overflow, do nothing
579 
580  if (__overflow) return;
581 
582  while (true) {
583  if (__vars[cpt] == &v) {
584  if (cpt == p) {
585  __overflow = true;
586  return;
587  } else
588  ++cpt;
589  } else {
590  Idx iv = __vals[cpt];
591 
592  if (iv + 1 == __vars[cpt]->domainSize()) {
593  __chgVal(cpt, 0);
594 
595  if (cpt == p) {
596  __overflow = true;
597  return;
598  } else
599  ++cpt;
600  } else {
601  __chgVal(cpt, iv + 1);
602  return;
603  }
604  }
605  }
606  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ incOut()

INLINE void gum::Instantiation::incOut ( const Instantiation i)

Operator increment for the variables not in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated.

Note also that this operator never throws an exception when it reaches the end of the possible values of the tuple of variables of the Instantiation. To know if we reached the end, use function end(). Finally, let us mention that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. The next value of *this is thus computed w.r.t. to the current value of *this. If we already reached the end() or the rend() of the possible values, function incerr() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
iThe set of variable to not increment in this Instantiation.

Definition at line 488 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, contains(), domainSize(), and nbrDim().

Referenced by gum::MultiDimBucket< GUM_SCALAR >::__computeValue(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::MultiDimContainer< GUM_SCALAR >::extractFrom(), gum::FMDPSimulator::perform(), and gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked().

488  {
489  Size p = nbrDim() - 1;
490  Idx cpt = 0;
491  // if we are in overflow, do nothing
492 
493  if (__overflow) return;
494 
495  while (true) {
496  if (i.contains(__vars[cpt])) {
497  if (cpt == p) {
498  __overflow = true;
499  return;
500  } else
501  ++cpt;
502  } else {
503  Idx v = __vals[cpt];
504 
505  if (v + 1 == __vars[cpt]->domainSize()) {
506  __chgVal(cpt, 0);
507 
508  if (cpt == p) {
509  __overflow = true;
510  return;
511  } else
512  ++cpt;
513  } else {
514  __chgVal(cpt, v + 1);
515  return;
516  }
517  }
518  }
519  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ incVar()

INLINE void gum::Instantiation::incVar ( const DiscreteVariable v)

Operator increment for variable v only.

This function increment only variable v. Trying to increment the last possible value results in an overflow (no exception is thrown in this case). If we already reached the end() or the rend() of the possible values, function incVar() will perform nothing (this prevents looping inadvertently several times within the same loop). To unset the end flag, use functions unsetOverflow(), unsetEnd() or one of the setFirst() or setLast().

Parameters
vThe variable to increment in this Instantiation.
Exceptions
NotFoundRaised if variable v does not belong to the Instantiation.

Definition at line 677 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, and gum::DiscreteVariable::domainSize().

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT(), and gum::Potential< GUM_SCALAR >::normalizeAsCPT().

677  {
678  // get the position of the variable
679  Idx cpt = __vars.pos(&v);
680  // if we are in overflow, do nothing
681 
682  if (__overflow) return;
683 
684  Idx p = __vals[cpt];
685 
686  if (p + 1 == v.domainSize()) {
687  __chgVal(cpt, 0);
688  __overflow = true;
689  } else {
690  __chgVal(cpt, p + 1);
691  }
692  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ inOverflow()

INLINE bool gum::Instantiation::inOverflow ( ) const

Indicates whether the current value of the tuple is correct or not.

The function inOverflow() is used to flag overflowed operation (for instance, ++ on the last value or – on the first value will produce an incorrect value of the tuple. Hence inOverflow() is used as an end()/rend() function for loops on Instantiation.

for(Instantiation i.setFirst(); !i.inOverflow(); ++i) {
// code...
}

Definition at line 237 of file instantiation_inl.h.

References __overflow.

Referenced by end(), operator==(), and rend().

237 { return __overflow; }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the caller graph for this function:

◆ isMaster() [1/2]

INLINE bool gum::Instantiation::isMaster ( const MultiDimAdressable m) const

Indicates whether m is the master of this instantiation.

Returns
Returns true if m is the master of this instantiation.

Definition at line 728 of file instantiation_inl.h.

References __master.

Referenced by gum::MultiDimArray< GUM_SCALAR >::_get(), gum::MultiDimSparse< GUM_SCALAR >::get(), gum::MultiDimBijArray< GUM_SCALAR >::get(), gum::MultiDimBucket< GUM_SCALAR >::get(), isMaster(), operator=(), gum::MultiDimSparse< GUM_SCALAR >::set(), and gum::MultiDimWithOffset< GUM_SCALAR >::toString().

728  {
729  return (__master == m);
730  }
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
+ Here is the caller graph for this function:

◆ isMaster() [2/2]

INLINE bool gum::Instantiation::isMaster ( const MultiDimAdressable m) const

Indicates whether m is the master of this instantiation.

Returns
Returns true if m is the master of this instantiation.

Definition at line 733 of file instantiation_inl.h.

References isMaster().

733  {
734  return isMaster(&m);
735  }
bool isMaster(const MultiDimAdressable *m) const
Indicates whether m is the master of this instantiation.
+ Here is the call graph for this function:

◆ isSlave()

INLINE bool gum::Instantiation::isSlave ( ) const

Indicates whether the Instantiation has a master.

Returns
Returns true if the Instantiation has a master.

Definition at line 725 of file instantiation_inl.h.

References __master.

725 { return (__master != nullptr); }
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.

◆ nbrDim()

INLINE Idx gum::Instantiation::nbrDim ( ) const
finalvirtual

◆ operator++()

INLINE Instantiation & gum::Instantiation::operator++ ( )

Alias of Instantiation::inc().

Returns
Returns this Instantiation.

Definition at line 319 of file instantiation_inl.h.

References inc().

319  {
320  inc();
321  return *this;
322  }
void inc()
Operator increment.
+ Here is the call graph for this function:

◆ operator+=()

INLINE Instantiation & gum::Instantiation::operator+= ( Size  depl)

Calls depl times Instantiation::inc().

Returns
Returns this Instantiation.

Definition at line 331 of file instantiation_inl.h.

References inc().

331  {
332  //@todo : this code should be improved !!!
333  for (Idx i = 0; i < depl; i++)
334  inc();
335 
336  return *this;
337  }
void inc()
Operator increment.
+ Here is the call graph for this function:

◆ operator--()

INLINE Instantiation & gum::Instantiation::operator-- ( )

Alias of Instantiation::dec().

Returns
Returns this Instantiation.

Definition at line 325 of file instantiation_inl.h.

References dec().

325  {
326  dec();
327  return *this;
328  }
void dec()
Operator decrement.
+ Here is the call graph for this function:

◆ operator-=()

INLINE Instantiation & gum::Instantiation::operator-= ( Size  depl)

Calls depl times Instantiation::dec().

Returns
Returns this Instantiation.

Definition at line 340 of file instantiation_inl.h.

References dec().

340  {
341  //@todo : this code should be improved !!!
342  for (Idx i = 0; i < depl; i++)
343  dec();
344 
345  return *this;
346  }
void dec()
Operator decrement.
+ Here is the call graph for this function:

◆ operator=()

Instantiation & gum::Instantiation::operator= ( const Instantiation aI)

Copy operator.

If this is a slave but not with the same as aI's master: if aI and this does not share the same variables then an OperationNotAllowed will we be raised. Otherwise calls this->setVals( aI ).

If this is not a slave, copies aI.

Parameters
aIThe Instantiation to copy.
Exceptions
OperationNotAllowedRaised if copy is not allowed.

Definition at line 116 of file instantiation.cpp.

References __master, __overflow, __vals, __vars, actAsSlave(), contains(), GUM_ERROR, isMaster(), nbrDim(), setVals(), and variable().

116  {
117  if (__master) {
118  if (!aI.isMaster(__master)) { // aI as the same master.
119  if (nbrDim() != aI.nbrDim()) {
120  GUM_ERROR(OperationNotAllowed, "in slave Instantiation");
121  }
122 
123  for (Idx i = 0; i < nbrDim(); i++) {
124  if ((!contains(aI.variable(i))) || (!aI.contains(variable(i)))) {
125  GUM_ERROR(OperationNotAllowed, "in slave Instantiation");
126  }
127  }
128  }
129 
130  setVals(aI);
131  } else {
132  // copy the content of aI
133  __vars = aI.__vars;
134  __vals = aI.__vals;
135  __overflow = aI.__overflow;
136 
137  if (aI.__master) actAsSlave(*aI.__master);
138  }
139 
140  return *this;
141  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
bool actAsSlave(MultiDimAdressable &aMD)
Tries to register the Instantiation to a MultiDimAdressable.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ operator==()

INLINE bool gum::Instantiation::operator== ( const Instantiation other) const

operator==

Definition at line 840 of file instantiation_inl.h.

References contains(), inOverflow(), nbrDim(), val(), and variablesSequence().

840  {
841  if (inOverflow() && other.inOverflow()) return true;
842  if (other.nbrDim() != nbrDim()) return false;
843  for (const auto& k: variablesSequence()) {
844  if (!other.contains(k)) return false;
845  if (val(*k) != other.val(*k)) return false;
846  }
847  return true;
848  }
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns the sequence of DiscreteVariable of this instantiation.
Idx val(Idx i) const
Returns the current value of the variable at position i.
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
+ Here is the call graph for this function:

◆ pos()

INLINE Idx gum::Instantiation::pos ( const DiscreteVariable v) const
finalvirtual

Returns the position of the variable v.

Returns
Returns the position of the variable v.
Parameters
vThe variable for which its position is return.
Exceptions
NotFoundRaised if v does not belong to the instantiation.

Implements gum::MultiDimInterface.

Definition at line 191 of file instantiation_inl.h.

References __vars.

Referenced by __erase(), __reorder(), gum::prm::PRMFormAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::becomeCastDescendant(), chgVal(), decIn(), incIn(), and setVals().

191  {
192  return __vars.pos(&k);
193  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
+ Here is the caller graph for this function:

◆ rend()

INLINE bool gum::Instantiation::rend ( ) const

Returns true if the Instantiation reached the rend.

Function end() should be used as in:

for(Instantiation i.setLast();! i.rend(); --i) {
// code
}
Returns
Returns true if the Instantiation reached the rend.

Definition at line 243 of file instantiation_inl.h.

References inOverflow().

243 { return inOverflow(); }
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.
+ Here is the call graph for this function:

◆ reorder() [1/2]

INLINE void gum::Instantiation::reorder ( const Sequence< const DiscreteVariable * > &  v)

Reorder vars of this instantiation giving the order in v.

In the new order variables common to v and *this are placed first, then variables only in *this.

The variables only in v are ignored.

Parameters
vThe new order of variables for this Instantiation.
Exceptions
OperationNotAllowedif slave instantiation

Definition at line 759 of file instantiation_inl.h.

References __master, __reorder(), and GUM_ERROR.

Referenced by gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), reorder(), and gum::credal::CredalNet< GUM_SCALAR >::setCPT().

759  {
760  if (__master != nullptr) {
761  GUM_ERROR(OperationNotAllowed,
762  "Reordering impossible in slave instantiation");
763  }
764 
765  __reorder(original);
766  }
void __reorder(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reorder() [2/2]

INLINE void gum::Instantiation::reorder ( const Instantiation i)

Calls reorder(const Sequence<const DiscreteVariable*>&) with i.variablesSequence()

Parameters
iThe sequence of variables with which to reorder this Instantiation.

Definition at line 454 of file instantiation_inl.h.

References reorder(), and variablesSequence().

454  {
455  reorder(i.variablesSequence());
456  }
void reorder(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.
+ Here is the call graph for this function:

◆ replace()

INLINE void gum::MultiDimInterface::replace ( const DiscreteVariable x,
const DiscreteVariable y 
)
inherited

Replace variables in this multidim.

If x is in this MultiDim and y has the same domain size, then x will be replace by y in this MultiDim.

Parameters
xThe variable in this which will be replaced.
yThe variable replacing y.
Exceptions
NotFoundRaised if x does not belong to this MultiDim.
OperationNotAllowedIf y and x are not interchangeable.
DuplicateElementIf y is already in this MultiDim.

Definition at line 36 of file multiDimInterface_inl.h.

References gum::MultiDimInterface::_replace(), gum::MultiDimInterface::contains(), gum::DiscreteVariable::domainSize(), and GUM_ERROR.

Referenced by gum::MultiDimImplementation< std::string >::_replace(), gum::MultiDimBucket< GUM_SCALAR >::_replace(), and gum::MultiDimInterface::~MultiDimInterface().

37  {
38  if (!contains(x)) { GUM_ERROR(NotFound, "could not find the variable"); }
39 
40  if (contains(y)) {
41  GUM_ERROR(DuplicateElement, "variable " << y << " already in MultiDim");
42  }
43 
44  if (x.domainSize() != y.domainSize()) {
45  GUM_ERROR(OperationNotAllowed, "incompatible variables");
46  }
47 
48  _replace(&x, &y);
49  }
virtual bool contains(const DiscreteVariable &v) const =0
Returns true if var is in *this.
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y)=0
This is called by MultiDimContainer::replace() to proceed with the replacing between x and y...
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFirst()

INLINE void gum::Instantiation::setFirst ( )

Assign the first values to the tuple of the Instantiation.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Definition at line 349 of file instantiation_inl.h.

References __masterFirstNotification(), __overflow, __vals, and nbrDim().

Referenced by gum::prm::PRMFormAttribute< GUM_SCALAR >::__fillCpf(), gum::prm::PRMSystem< double >::__groundPotential(), gum::credal::CredalNet< GUM_SCALAR >::__intervalToCredal(), gum::prm::StructuredBayesBall< GUM_SCALAR >::__isHardEvidence(), gum::BayesNetInference< GUM_SCALAR >::__isHardEvidence(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__threadUpdate(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::prm::GroundedInference< GUM_SCALAR >::_evidenceAdded(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::prm::PRMFormAttribute< GUM_SCALAR >::_type(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::_type(), gum::prm::PRMInference< double >::addEvidence(), gum::MultiDimContainer< GUM_SCALAR >::apply(), gum::prm::PRMFormAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::credal::CredalNet< GUM_SCALAR >::bnToCredal(), gum::prm::o3prmr::O3prmrInterpreter::checkObserve(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::MultiDimBucket< GUM_SCALAR >::compute(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copy(), gum::MultiDimContainer< GUM_SCALAR >::copyFrom(), gum::Potential< GUM_SCALAR >::draw(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), gum::Potential< GUM_SCALAR >::fillWith(), gum::Potential< GUM_SCALAR >::findAll(), gum::JointTargetedInference< GUM_SCALAR >::I(), gum::credal::CredalNet< GUM_SCALAR >::idmLearning(), gum::credal::CredalNet< GUM_SCALAR >::intervalToCredal(), gum::credal::CredalNet< GUM_SCALAR >::intervalToCredalWithFiles(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::Potential< GUM_SCALAR >::KL(), gum::credal::CredalNet< GUM_SCALAR >::lagrangeNormalization(), gum::prm::PRMInference< double >::marginal(), gum::Potential< GUM_SCALAR >::normalizeAsCPT(), gum::prm::PRMInference< double >::operator=(), gum::learning::DAG2BNLearner< ALLOC >::operator=(), gum::IBayesNet< double >::operator==(), gum::MultiDimContainer< GUM_SCALAR >::operator==(), gum::MultiDimContainer< GUM_SCALAR >::populate(), gum::prm::PRMInference< double >::PRMInference(), gum::prm::o3prmr::O3prmrInterpreter::query(), gum::MultiDimContainer< GUM_SCALAR >::reduce(), setFirstNotVar(), gum::Estimator< GUM_SCALAR >::setFromLBP(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::prm::PRMFormAttribute< GUM_SCALAR >::swap(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::swap(), gum::MultiDimContainer< GUM_SCALAR >::toString(), and gum::credal::CredalNet< GUM_SCALAR >::toString().

349  {
350  __overflow = false;
351  Size s = nbrDim();
352 
353  for (Idx p = 0; p < s; ++p)
354  __vals[p] = 0;
355 
357  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void __masterFirstNotification() const
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ setFirstIn()

INLINE void gum::Instantiation::setFirstIn ( const Instantiation i)

Assign the first values in the Instantiation for the variables in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. This function naturally unsets the overFlow flag.

Parameters
iThe variables to which their first value is assigned in this Instantiation.

Definition at line 459 of file instantiation_inl.h.

References __chgVal(), __overflow, __vars, contains(), and nbrDim().

Referenced by gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), and gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked().

459  {
460  __overflow = false;
461  Idx s = nbrDim();
462 
463  for (Size p = 0; p < s; ++p)
464  if (i.contains(__vars[p])) __chgVal(p, 0);
465  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFirstNotVar()

INLINE void gum::Instantiation::setFirstNotVar ( const DiscreteVariable v)

Assign the first values to variables different of v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Parameters
vTha variable that will not be set to its first value in this Instantiation.

Definition at line 643 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, nbrDim(), and setFirst().

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), and gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT().

643  {
644  __overflow = false;
645  Idx s = nbrDim();
646 
647  for (Size p = 0; p < s; ++p) {
648  if (__vars[p] == &v) {
649  Idx oldval = __vals[p];
650  setFirst();
651  __chgVal(p, oldval);
652  return;
653  }
654  }
655 
656  setFirst();
657  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
void setFirst()
Assign the first values to the tuple of the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFirstOut()

INLINE void gum::Instantiation::setFirstOut ( const Instantiation i)

Assign the first values in the Instantiation for the variables not in i.

Note that, if the Instantiation is related to a qum::MultiDimAdressable, then the corresponding value in the latter is updated. Note also that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. This function naturally unsets the overFlow flag.

Parameters
iThe variable that will not be set to their first value in this Instantiation.

Definition at line 557 of file instantiation_inl.h.

References __chgVal(), __overflow, __vars, contains(), and nbrDim().

Referenced by gum::MultiDimBucket< GUM_SCALAR >::__computeValue(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::MultiDimContainer< GUM_SCALAR >::extractFrom(), gum::FMDPSimulator::perform(), and gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked().

557  {
558  __overflow = false;
559  Idx s = nbrDim();
560 
561  for (Size p = 0; p < s; ++p)
562  if (!i.contains(__vars[p])) __chgVal(p, 0);
563  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFirstVar()

INLINE void gum::Instantiation::setFirstVar ( const DiscreteVariable v)

Assign the first value in the Instantiation for var v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Parameters
vThe variable that will be set to its first value in this Instantiation.

Definition at line 713 of file instantiation_inl.h.

References __chgVal(), __overflow, and __vars.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT(), and gum::Potential< GUM_SCALAR >::normalizeAsCPT().

713  {
714  __overflow = false;
715  __chgVal(__vars.pos(&v), 0);
716  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLast()

INLINE void gum::Instantiation::setLast ( )

Assign the last values in the Instantiation.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Definition at line 360 of file instantiation_inl.h.

References __masterLastNotification(), __overflow, __vals, __vars, domainSize(), and nbrDim().

Referenced by setLastNotVar().

360  {
361  __overflow = false;
362  Size s = nbrDim();
363 
364  for (Idx p = 0; p < s; ++p)
365  __vals[p] = __vars[p]->domainSize() - 1;
366 
368  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __masterLastNotification() const
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setLastIn()

INLINE void gum::Instantiation::setLastIn ( const Instantiation i)

Assign the last values in the Instantiation for the variables in i.

Where Di is the domain size of variable i in the Instantiation) for the i vars.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that the value of instantiation i is not taken into account, that is, only the variables belonging to i are taken into account. This function naturally unsets the overFlow flag.

Parameters
iThe variables to which their last value is assigned in this Instantiation.

Definition at line 479 of file instantiation_inl.h.

References __chgVal(), __overflow, __vars, contains(), domainSize(), and nbrDim().

479  {
480  __overflow = false;
481  Idx s = nbrDim();
482 
483  for (Size p = 0; p < s; ++p)
484  if (i.contains(__vars[p])) __chgVal(p, __vars[p]->domainSize() - 1);
485  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:

◆ setLastNotVar()

INLINE void gum::Instantiation::setLastNotVar ( const DiscreteVariable v)

Assign the last values to variables different of v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Parameters
vThe variable that will not be set to its last value in this Instantiation.

Definition at line 660 of file instantiation_inl.h.

References __chgVal(), __overflow, __vals, __vars, nbrDim(), and setLast().

660  {
661  __overflow = false;
662  Idx s = nbrDim();
663 
664  for (Size p = 0; p < s; ++p) {
665  if (__vars[p] == &v) {
666  Idx oldval = __vals[p];
667  setLast();
668  __chgVal(p, oldval);
669  return;
670  }
671  }
672 
673  setLast();
674  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
void setLast()
Assign the last values in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the call graph for this function:

◆ setLastOut()

INLINE void gum::Instantiation::setLastOut ( const Instantiation i)

Assign the last values in the Instantiation for the variables not in i.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. Note also that the value of instantiation i is not taken into account, that is, only the variables not belonging to i are taken into account. This function naturally unsets the overFlow flag.

Parameters
iThe variables that will not be set to their last value in this Instantiation.

Definition at line 566 of file instantiation_inl.h.

References __chgVal(), __overflow, __vars, contains(), domainSize(), and nbrDim().

566  {
567  __overflow = false;
568  Idx s = nbrDim();
569 
570  for (Size p = 0; p < s; ++p)
571  if (!i.contains(__vars[p])) __chgVal(p, __vars[p]->domainSize() - 1);
572  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Size domainSize() const final
Returns the product of the variable&#39;s domain size in the Instantiation.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:

◆ setLastVar()

INLINE void gum::Instantiation::setLastVar ( const DiscreteVariable v)

Assign the last value in the Instantiation for var v.

Note that, if the Instantiation is related to a MultiDimAdressable, then the corresponding value in the latter is updated. This function naturally unsets the overFlow flag.

Parameters
vThe variable that will be set to its last value in this Instantiation.

Definition at line 719 of file instantiation_inl.h.

References __chgVal(), __overflow, __vars, and gum::DiscreteVariable::domainSize().

719  {
720  __overflow = false;
721  __chgVal(__vars.pos(&v), v.domainSize() - 1);
722  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
+ Here is the call graph for this function:

◆ setVals()

INLINE Instantiation & gum::Instantiation::setVals ( const Instantiation i)

Assign the values from i in the Instantiation.

For any variable in i and in *this, value of the variable in i is assigned to the variable in *this.

In addition of modifying the value of the variables in *this, the Instantiation informs its master of the modification. This function also unsets the overflow flag.

If no variables in i matches, then no value is changed.

Warning
Variables has to be "the same". Therefore chgValIn is usefull in a same domain variables (for instance a BN). However two identical variables will not be recognized as same (for instance between 2 BNs).
See also
Instantiation::setValsFrom for this kind of utilisation.
Parameters
iA Instantiation in which the new values are searched.
Returns
Returns a reference to *this in order to chain the chgVal.

Definition at line 468 of file instantiation_inl.h.

References __chgVal(), __overflow, contains(), nbrDim(), pos(), val(), and variable().

Referenced by gum::MultiDimBucket< GUM_SCALAR >::__computeValue(), gum::SimpleCPTDisturber< GUM_SCALAR >::disturbReducCPT(), gum::MultiDimContainer< GUM_SCALAR >::extractFrom(), gum::learning::DAG2BNLearner< ALLOC >::operator=(), operator=(), gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule(), and gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked().

468  {
469  __overflow = false;
470  Idx s = i.nbrDim();
471 
472  for (Size p = 0; p < s; ++p)
473  if (contains(i.variable(p))) __chgVal(pos(i.variable(p)), i.val(p));
474 
475  return *this;
476  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
void __chgVal(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setValsFrom()

void gum::Instantiation::setValsFrom ( const HashTable< const DiscreteVariable *, const DiscreteVariable * > &  map,
const Instantiation external 
)

Assign the values of external in *this, using map as a bijection between external and this variables.

Parameters
mapKeys are variables in external.
externalAn instantiation used to change the values in j.
Exceptions
NotFoundRaised if a variable in external does not point to a variable in *this or in external.

Definition at line 176 of file instantiation.cpp.

References chgVal(), GUM_ERROR, gum::Variable::name(), and val().

178  {
179  for (const auto& elt: map) {
180  const DiscreteVariable& var = *elt.second;
181 
182  try {
183  Idx val = external.val(*elt.first);
184 
185  try {
186  chgVal(var, val);
187  } catch (NotFound&) {
188  GUM_ERROR(NotFound,
189  var.name() << " : missing variable in instantiation");
190  }
191  } catch (NotFound&) {
192  GUM_ERROR(NotFound,
193  var.name() << " : missing variable in external instantiation");
194  }
195  }
196  }
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
Idx val(Idx i) const
Returns the current value of the variable at position i.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:

◆ synchronizeWithMaster()

void gum::Instantiation::synchronizeWithMaster ( const MultiDimAdressable m)

Force the variables sequence to be the same as the master one.

The master should be a friend to notify dimensions changes friend class MultiDimAdressable.

Parameters
mThe master of this instantiation.
Exceptions
OperationNotAllowedRaised if m is not the master of instantiation.

Definition at line 228 of file instantiation.cpp.

References __master, __reorder(), GUM_ERROR, and gum::MultiDimInterface::variablesSequence().

Referenced by gum::MultiDimImplementation< std::string >::registerSlave().

228  {
229  if (m != __master) {
230  GUM_ERROR(OperationNotAllowed, "only master can do this");
231  }
232 
234  }
void __reorder(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.
MultiDimAdressable * __master
The master, if any, contains precisely the set of variables to be instantiated.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const =0
Returns a const ref to the sequence of DiscreteVariable*.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString()

std::string gum::Instantiation::toString ( ) const

Give a string version of instantiation.

Returns
Returns a string version of instantiation.

Definition at line 144 of file instantiation.cpp.

References __overflow, __vars, and val().

Referenced by gum::operator<<(), gum::MultiDimICIModel< GUM_SCALAR >::toString(), and gum::aggregator::MultiDimAggregator< GUM_SCALAR >::toString().

144  {
145  std::stringstream sstr;
146  // check if the value of the instantiation is correct
147 
148  if (__overflow) { sstr << "<invalid>"; }
149 
150  sstr << "<";
151 
152  bool first = true;
153 
154  for (const auto var: __vars) {
155  if (!first) sstr << "|";
156 
157  first = false;
158  sstr << var->name() << ":" << var->label(val(*var));
159  }
160 
161  sstr << ">";
162 
163  return sstr.str();
164  }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
Idx val(Idx i) const
Returns the current value of the variable at position i.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unsetEnd()

INLINE void gum::Instantiation::unsetEnd ( )

Alias for unsetOverflow().

See also
unsetOverflow().

Definition at line 250 of file instantiation_inl.h.

References __overflow.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), and gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT().

250 { __overflow = false; }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...
+ Here is the caller graph for this function:

◆ unsetOverflow()

INLINE void gum::Instantiation::unsetOverflow ( )

Removes the flag overflow.

See full documentation for details. (Recommended).

When we use multiple inner loops w.r.t. a given Instantiation, it may happen that one inner loop reaches the end() of the Instantiation while the outer loops do not have reached it. This means that the inner loop has toggled the overflow flag. To enable the other loops to go on, we must unset this flag using function unsetOverflow(). For instance, assume that Prob represents probability P(b|a,c), then normalizing this proba can be performed using the following code:

// assume the probability has been defined somewhere:
MultiDimArray<double> Prob;
// create 2 instantiations for the 2 necessary loops
Instantiation i(Prob), j;
j << a << c;
double delta;
// outer loop: loop over the values of b
for(i.setFirstIn(j); !i.end(); i.incIn(j))
{
delta = 0.0;
// inner loop: loop over the values of a and c
for(i.setFirstOut(j); !i.end(); i.incerr(j))
delta += dd[i];
for(i.setFirstOut(j); !i.end(); i.incerr(j))
dd[i] /= delta;
// indicate that the end() reached after looping over a and c does not
// correspond to an end() for the loop w.r.t. b
i.unsetOverflow();
}

Definition at line 247 of file instantiation_inl.h.

References __overflow.

247 { __overflow = false; }
bool __overflow
Indicates whether the current value of the tuple is valid when we loop sufficiently over values of th...

◆ val() [1/3]

INLINE Idx gum::Instantiation::val ( Idx  i) const

Returns the current value of the variable at position i.

Warning
For speed issues, the function does not actually check whether the overflow flag is set before returning the current value of the variable as, usually, it is not necessary. If need be, use function inOverflow() to check.
Parameters
iThe index of the variable.
Returns
Returns the current value of the variable at position i.
Exceptions
NotFoundRaised if the element cannot be found.

Definition at line 199 of file instantiation_inl.h.

References __vals, and GUM_ERROR.

Referenced by gum::BayesNetInference< GUM_SCALAR >::__isHardEvidence(), gum::aggregator::Amplitude< GUM_SCALAR >::_buildValue(), gum::aggregator::Median< GUM_SCALAR >::_buildValue(), gum::aggregator::MultiDimAggregator< GUM_SCALAR >::_buildValue(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), gum::MonteCarloSampling< GUM_SCALAR >::_draw(), gum::HashFunc< Instantiation >::castToSize(), gum::prm::o3prmr::O3prmrInterpreter::checkObserve(), gum::Potential< GUM_SCALAR >::draw(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::SDYNA::feedback(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), gum::MultiDimLogit< GUM_SCALAR >::get(), gum::MultiDimNoisyORNet< GUM_SCALAR >::get(), gum::MultiDimNoisyORCompound< GUM_SCALAR >::get(), gum::aggregator::MultiDimAggregator< GUM_SCALAR >::get(), gum::MultiDimNoisyAND< GUM_SCALAR >::get(), gum::MultiDimFunctionGraph< bool, ExactTerminalNodePolicy >::get(), hamming(), gum::AbstractSimulator::hasReachEnd(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::IBayesNet< double >::operator==(), operator==(), gum::FMDPSimulator::perform(), gum::prm::o3prmr::O3prmrInterpreter::query(), gum::credal::CredalNet< GUM_SCALAR >::setCPT(), setVals(), setValsFrom(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), toString(), gum::Estimator< GUM_SCALAR >::update(), and val().

199  {
200  if (i >= __vals.size()) {
201  GUM_ERROR(NotFound, i << " is out of bound index for the instantiation.");
202  }
203 
204  return __vals[i];
205  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
std::vector< Idx > __vals
The current instantiation: the value of the tuple.

◆ val() [2/3]

INLINE Idx gum::Instantiation::val ( const DiscreteVariable var) const

Returns the current value of a given variable.

Warning
For speed issues, the function does not actually check whether the overflow flag is set before returning the current value of the variable as, usually, it is not necessary. If need be, use function inOverflow() to check.
Parameters
varThe variable the value of which we wish to know.
Returns
Returns the current value of a given variable.
Exceptions
NotFoundRaised it var does not belong to the instantiation.

Definition at line 208 of file instantiation_inl.h.

References __vals, and __vars.

208  {
209  return __vals[__vars.pos(&var)];
210  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.

◆ val() [3/3]

INLINE Idx gum::Instantiation::val ( const std::string &  name) const

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Definition at line 212 of file instantiation_inl.h.

References val(), and variable().

212  {
213  return val(variable(name));
214  }
Idx val(Idx i) const
Returns the current value of the variable at position i.
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
+ Here is the call graph for this function:

◆ valFromPtr()

INLINE Idx gum::Instantiation::valFromPtr ( const DiscreteVariable pvar) const

Returns the current value of a given variable.

Warning
For speed issues, the function does not actually check whether the overflow flag is set before returning the current value of the variable as, usually, it is not necessary. If need be, use function inOverflow() to check.
Parameters
pvarThe variable for which the value is returned.
Returns
Returns the current value of a given variable.
Exceptions
NotFoundRaised if var does not belong to the instantiation.

Definition at line 218 of file instantiation_inl.h.

References __vals, and __vars.

Referenced by gum::TaxiSimulator::__evalReward(), gum::StatesCounter::__incState(), gum::StatesChecker::__insertState(), gum::TaxiSimulator::__performFillUp(), gum::TaxiSimulator::__performGoEast(), gum::TaxiSimulator::__performGoNorth(), gum::TaxiSimulator::__performGoSouth(), gum::TaxiSimulator::__performGoWest(), gum::TaxiSimulator::__performPickUp(), gum::TaxiSimulator::__performPutDown(), gum::MultiDimWithOffset< GUM_SCALAR >::_getOffs(), gum::StatesChecker::addState(), gum::StatesCounter::incState(), and gum::TaxiSimulator::perform().

218  {
219  return __vals[__vars.pos(pvar)];
220  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
std::vector< Idx > __vals
The current instantiation: the value of the tuple.
+ Here is the caller graph for this function:

◆ variable() [1/2]

INLINE const DiscreteVariable & gum::Instantiation::variable ( Idx  i) const
finalvirtual

Returns the variable at position i in the tuple.

Parameters
iThe index of the variable
Returns
Returns the variable at position i in the tuple.
Exceptions
NotFoundRaised if the element cannot be found.

Implements gum::MultiDimInterface.

Definition at line 223 of file instantiation_inl.h.

References __vars.

Referenced by gum::aggregator::Median< GUM_SCALAR >::_buildValue(), gum::GibbsBNdistance< GUM_SCALAR >::_computeKL(), gum::InfluenceDiagram< GUM_SCALAR >::_copyTables(), chgVal(), contains(), decIn(), erase(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), incIn(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), operator=(), gum::IBayesNet< double >::operator==(), gum::credal::CredalNet< GUM_SCALAR >::setCPT(), setVals(), gum::Estimator< GUM_SCALAR >::update(), and val().

223  {
224  return *(__vars.atPos(i));
225  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
+ Here is the caller graph for this function:

◆ variable() [2/2]

INLINE const DiscreteVariable & gum::Instantiation::variable ( const std::string &  name) const
finalvirtual

Returns the variable with the name.

Parameters
nameThe index of the variable
Returns
Returns the variable qith the name in the tuple. This function is not O(1)
Exceptions
NotFoundRaised if the element cannot be found.

Implements gum::MultiDimInterface.

Definition at line 228 of file instantiation_inl.h.

References __vars, and GUM_ERROR.

228  {
229  for (const auto& v: __vars) {
230  if (v->name() == name) return *v;
231  }
232 
233  GUM_ERROR(NotFound, "'" << name << "' can not be found in the instantiation.")
234  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55

◆ variablesSequence()

INLINE const Sequence< const DiscreteVariable *> & gum::Instantiation::variablesSequence ( ) const
finalvirtual

Returns the sequence of DiscreteVariable of this instantiation.

Returns
Returns the sequence of DiscreteVariable of this instantiation.

Implements gum::MultiDimInterface.

Definition at line 739 of file instantiation_inl.h.

References __vars.

Referenced by gum::StatesCounter::__incState(), gum::StatesChecker::__insertState(), gum::MultiDimBucket< GUM_SCALAR >::_commitMultipleChanges(), gum::HashFunc< Instantiation >::castToSize(), gum::SDYNA::feedback(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), gum::AbstractSimulator::hasReachEnd(), operator==(), reorder(), gum::StatesCounter::reset(), gum::StatesChecker::reset(), and gum::credal::CredalNet< GUM_SCALAR >::setCPT().

739  {
740  return __vars;
741  }
Sequence< const DiscreteVariable *> __vars
The tuple of variables to be instantiated.
+ Here is the caller graph for this function:

Member Data Documentation

◆ __master

◆ __overflow

bool gum::Instantiation::__overflow
private

Indicates whether the current value of the tuple is valid when we loop sufficiently over values of the tuple, we may have browsed all the possible values and we have to know in a way or another that the tuple contains no more value. This is precisely the meaning of Boolean overflow.

Definition at line 1143 of file instantiation.h.

Referenced by __add(), chgVal(), dec(), decIn(), decNotVar(), decOut(), decVar(), inc(), incIn(), incNotVar(), incOut(), incVar(), inOverflow(), Instantiation(), operator=(), setFirst(), setFirstIn(), setFirstNotVar(), setFirstOut(), setFirstVar(), setLast(), setLastIn(), setLastNotVar(), setLastOut(), setLastVar(), setVals(), toString(), unsetEnd(), and unsetOverflow().

◆ __vals

std::vector< Idx > gum::Instantiation::__vals
private

◆ __vars


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