aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::Instantiation Class Referencefinal

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

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

Protected Member Functions

void replace_ (const DiscreteVariable *x, const DiscreteVariable *y) final
 Replace x by y.

Private Member Functions

void _swap_ (Idx i, Idx j)
 Swap two variables in the Instantiation.
void _chgVal_ (Idx varPos, Idx newVal)
 Modifies internally the value of a given variable of the sequence.
void _add_ (const DiscreteVariable &v)
 Adds a new var to the sequence of vars.
void _erase_ (const DiscreteVariable &v)
 Removes a variable from the sequence of vars.
void _notifiedDimChanged_ (const Sequence< const DiscreteVariable * > &v)
 This function is called by the master (if any) when changes arise in its vars list.
void _init_ (MultiDimAdressable *master)
 Initialize this Instantiation.
void _reorder_ (const Sequence< const DiscreteVariable * > &v)
 Reorder vars of this instantiation giving the order in v.
void _masterChangeNotification_ (Idx varPos, Idx newVal, Idx oldVal) const
void _masterFirstNotification_ () const
void _masterIncNotification_ () const
void _masterLastNotification_ () const
void _masterDecNotification_ () const

Private Attributes

MultiDimAdressable_master_
 The master, if any, contains precisely the set of variables to be instantiated.
Sequence< const DiscreteVariable * > _vars_
 The tuple of variables to be instantiated.
std::vector< Idx_vals_
 The current instantiation: the value of the tuple.
bool _overflow_
 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.

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 for 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 102 of file instantiation.h.

Constructor & Destructor Documentation

◆ Instantiation() [1/6]

gum::Instantiation::Instantiation ( )

Default constructor: creates an empty tuple.

Definition at line 59 of file instantiation.cpp.

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

References Instantiation(), _master_, and _overflow_.

Referenced by Instantiation(), Instantiation(), Instantiation(), Instantiation(), Instantiation(), Instantiation(), ~Instantiation(), chgVal(), chgVal(), chgVal(), chgVal(), decIn(), decOut(), incIn(), incOut(), operator++(), operator+=(), operator--(), operator-=(), operator=(), operator==(), reorder(), setFirstIn(), setFirstOut(), setLastIn(), setLastOut(), setVals(), and setValsFrom().

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

◆ 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 118 of file instantiation.cpp.

118 :
119 MultiDimInterface(), _master_(0), _overflow_(false) {
120 // for debugging purposes
121 GUM_CONS_CPY(Instantiation);
122 // copy the content of aI
123 _vars_ = aI._vars_;
124 _vals_ = aI._vals_;
125 _overflow_ = aI._overflow_;
126
127 if (aI._master_ && notifyMaster) actAsSlave(*aI._master_);
128 }
Sequence< const DiscreteVariable * > _vars_
The tuple of variables to be instantiated.
bool actAsSlave(MultiDimAdressable &aMD)
Tries to register the Instantiation to a MultiDimAdressable.
std::vector< Idx > _vals_
The current instantiation: the value of the tuple.

References Instantiation(), _master_, _overflow_, _vals_, _vars_, and actAsSlave().

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 87 of file instantiation.cpp.

87 : _master_(0), _overflow_(false) {
88 // for debugging purposes
89 GUM_CONSTRUCTOR(Instantiation);
90 _init_(&d);
91 }
void _init_(MultiDimAdressable *master)
Initialize this Instantiation.

References Instantiation(), _init_(), _master_, and _overflow_.

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 93 of file instantiation.cpp.

93 : _master_(0), _overflow_(false) {
94 // for debugging purposes
95 GUM_CONSTRUCTOR(Instantiation);
96 _init_(const_cast< MultiDimAdressable* >(&d));
97 }

References Instantiation(), _init_(), _master_, and _overflow_.

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 100 of file instantiation.cpp.

100 : _master_(0), _overflow_(false) {
101 // for debugging purposes
102 GUM_CONSTRUCTOR(Instantiation);
103
104 if (d) _init_(d);
105 }

References Instantiation(), _init_(), _master_, and _overflow_.

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 110 of file instantiation.cpp.

110 : _master_(0), _overflow_(false) {
111 // for debugging purposes
112 GUM_CONSTRUCTOR(Instantiation);
113
114 if (const_d) _init_(const_cast< MultiDimAdressable* >(const_d));
115 }

References Instantiation(), _init_(), _master_, and _overflow_.

Here is the call graph for this function:

◆ ~Instantiation()

gum::Instantiation::~Instantiation ( )
override

Destructor.

Definition at line 64 of file instantiation.cpp.

64 {
65 GUM_DESTRUCTOR(Instantiation);
66 // unregister the Instantiation from its _master_
67
68 if (_master_) _master_->unregisterSlave(*this);
69 }

References Instantiation(), and _master_.

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 478 of file instantiation_inl.h.

478 {
479 _vars_.insert(&v);
480 _vals_.push_back(0);
481 _overflow_ = false;
482 }

References _overflow_, _vals_, and _vars_.

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

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 69 of file instantiation_inl.h.

69 {
70 Idx oldVal = _vals_[varPos];
71 _vals_[varPos] = newVal;
72
73 _masterChangeNotification_(varPos, newVal, oldVal);
74 }
void _masterChangeNotification_(Idx varPos, Idx newVal, Idx oldVal) const
Size Idx
Type for indexes.
Definition types.h:79

References _masterChangeNotification_(), and _vals_.

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

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 485 of file instantiation_inl.h.

485 {
486 // get the position of the variable
487 Idx pos = _vars_.pos(&v);
488 _vars_.erase(&v);
489 _vals_.erase(_vals_.begin() + pos);
490 }
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.

References _vals_, _vars_, and pos().

Referenced by erase(), and eraseWithMaster().

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 71 of file instantiation.cpp.

71 {
72 // for speed issues
73 GUM_ASSERT(master != nullptr);
74
75 const Sequence< const DiscreteVariable* >& v = master->variablesSequence();
76 _vars_.resize(v.size());
77 _vals_.reserve(v.size());
78 // fill the instantiation
79
80 for (const auto var: v)
81 _add_(*var);
82
83 actAsSlave(master->getMasterRef());
84 }
void _add_(const DiscreteVariable &v)
Adds a new var to the sequence of vars.

References _add_(), _vals_, _vars_, actAsSlave(), gum::MultiDimAdressable::getMasterRef(), gum::SequenceImplementation< Key, Gen >::size(), and gum::MultiDimInterface::variablesSequence().

Referenced by Instantiation(), Instantiation(), Instantiation(), and Instantiation().

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 211 of file instantiation.cpp.

211 {
212 if (_master_) _master_->changeNotification(*this, _vars_[varPos], oldVal, newVal);
213 }

References _master_, and _vars_.

Referenced by _chgVal_().

Here is the caller graph for this function:

◆ _masterDecNotification_()

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

Definition at line 227 of file instantiation.cpp.

227 {
228 if (_master_) _master_->setDecNotification(*this);
229 }

References _master_.

Referenced by dec().

Here is the caller graph for this function:

◆ _masterFirstNotification_()

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

Definition at line 215 of file instantiation.cpp.

215 {
216 if (_master_) _master_->setFirstNotification(*this);
217 }

References _master_.

Referenced by inc(), and setFirst().

Here is the caller graph for this function:

◆ _masterIncNotification_()

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

Definition at line 219 of file instantiation.cpp.

219 {
220 if (_master_) _master_->setIncNotification(*this);
221 }

References _master_.

Referenced by inc().

Here is the caller graph for this function:

◆ _masterLastNotification_()

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

Definition at line 223 of file instantiation.cpp.

223 {
224 if (_master_) _master_->setLastNotification(*this);
225 }

References _master_.

Referenced by dec(), and setLast().

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 454 of file instantiation_inl.h.

454 {
455 Idx max = original.size();
456 Idx position = 0;
457 for (Idx i = 0; i < max; ++i) {
458 const DiscreteVariable* pv = original.atPos(i);
459
460 if (contains(pv)) {
461 auto p = pos(*pv);
462 GUM_ASSERT(p >= position); // this var should not be
463 // already placed.
464 _swap_(position, p);
465 position++;
466 }
467 }
468 }
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.

References _swap_(), gum::SequenceImplementation< Key, Gen >::atPos(), contains(), pos(), and gum::SequenceImplementation< Key, Gen >::size().

Referenced by reorder(), and synchronizeWithMaster().

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 430 of file instantiation_inl.h.

430 {
431 if (i == j) return;
432
433 _vars_.swap(i, j);
434
435 Idx v;
436 v = _vals_[i];
437 _vals_[i] = _vals_[j];
438 _vals_[j] = v;
439 }

References _vals_, and _vars_.

Referenced by _reorder_().

Here is the caller graph for this function:

◆ 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 257 of file instantiation.cpp.

257 {
258 // if _master_ : not allowed
259 if (_master_ != nullptr) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
260
261 _master_ = &aMD;
262
263 // perform the registration
264 if (aMD.registerSlave(*this)) {
265 return true;
266 } else {
267 _master_ = nullptr;
268 return false;
269 }
270 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

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

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

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

◆ add()

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 278 of file instantiation.cpp.

278 {
279 // if _master_ : not allowed
280 if (_master_) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
281
282 // check if the variable already belongs to the tuple of variables
283 // of the Instantiation
284 if (_vars_.exists(&v)) {
285 GUM_ERROR(DuplicateElement, "Var <" << v.name() << "> already exists in this instantiation")
286 }
287
288 for (const auto& vv: _vars_) {
289 if (vv->name() == v.name()) {
290 GUM_ERROR(InvalidArgument,
291 "Var with name <" << v.name() << "> already exists in this instantiation");
292 }
293 }
294
295 // actually add the new dimension
296 _add_(v);
297 }

References _add_(), _master_, _vars_, GUM_ERROR, and gum::Variable::name().

Referenced by gum::SamplingInference< GUM_SCALAR >::addVarSample_(), gum::SamplingInference< GUM_SCALAR >::contextualize(), gum::ImportanceSampling< GUM_SCALAR >::draw_(), gum::WeightedSampling< GUM_SCALAR >::draw_(), gum::MCBNDistance< GUM_SCALAR >::drawSample_(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::JointTargetedMRFInference< GUM_SCALAR >::evidenceJointImpact(), gum::Tensor< GUM_SCALAR >::fillWith(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), gum::makeInstantiationFromValues(), gum::GibbsOperator< GUM_SCALAR >::monteCarloSample(), gum::FMDPSimulator::perform(), gum::AbstractSimulator::randomState_(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), and gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns().

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 471 of file instantiation_inl.h.

471 {
472 if (m != _master_) { GUM_ERROR(OperationNotAllowed, "only master can do this") }
473
474 _add_(v);
475 }

References _add_(), _master_, and GUM_ERROR.

Here is the call graph for this function:

◆ chgVal() [1/4]

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.
OutOfBoundsRaised if newval is not a possible value for v.

Definition at line 77 of file instantiation_inl.h.

77 {
78 // check that the variable does belong to the instantiation and that the
79 // new value is possible.
80 auto pPos = _vars_.tryPos(&v);
81 if (!pPos) {
82 std::string name = "instantiation does not contain this DiscreteVariable: ";
83 GUM_ERROR(NotFound, name + v.name())
84 }
85
86 Idx varPos = *pPos;
87
88 if (newVal >= v.domainSize()) { GUM_ERROR(OutOfBounds, "") }
89
90 // if we were in overflow, indicate that we are not anymore
91 _overflow_ = false;
92
93 _chgVal_(varPos, newVal);
94
95 return *this;
96 }
void _chgVal_(Idx varPos, Idx newVal)
Modifies internally the value of a given variable of the sequence.

References Instantiation(), _chgVal_(), _overflow_, _vars_, gum::DiscreteVariable::domainSize(), GUM_ERROR, and gum::Variable::name().

Referenced by gum::GibbsOperator< GUM_SCALAR >::_drawVarMonteCarlo_(), gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_(), gum::GibbsOperator< GUM_SCALAR >::_GibbsSample_(), gum::SamplingInference< GUM_SCALAR >::addVarSample_(), chgVal(), chgVal(), gum::MultiDimWithOffset< GUM_ELEMENT >::computeInstantiationValue_(), gum::SamplingInference< GUM_SCALAR >::contextualize(), gum::Tensor< GUM_SCALAR >::deterministicTensor(), gum::ImportanceSampling< GUM_SCALAR >::draw_(), gum::WeightedSampling< GUM_SCALAR >::draw_(), gum::MCBNDistance< GUM_SCALAR >::drawSample_(), gum::Tensor< GUM_SCALAR >::evEq(), gum::Tensor< GUM_SCALAR >::evGt(), gum::Tensor< GUM_SCALAR >::evIn(), gum::Tensor< GUM_SCALAR >::evLt(), gum::makeInstantiationFromValues(), gum::GibbsOperator< GUM_SCALAR >::monteCarloSample(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::InfluenceDiagram< GUM_SCALAR >::operator==(), gum::FMDPSimulator::perform(), gum::AbstractSimulator::randomState_(), gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule(), gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule(), and setValsFrom().

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

◆ chgVal() [2/4]

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
OutOfBoundsRaised if newval is not a possible value for the variable

Definition at line 99 of file instantiation_inl.h.

99 {
100 // check that the variable does belong to the instantiation and that the new
101 // value is possible.
102 if (_vals_.size() <= varPos) { GUM_ERROR(NotFound, "") }
103
104 if (newVal >= _vars_[varPos]->domainSize()) { GUM_ERROR(OutOfBounds, "") }
105
106 // if we were in overflow, indicate that we are not anymore
107 _overflow_ = false;
108
109 _chgVal_(varPos, newVal);
110
111 return *this;
112 }
Size domainSize() const final
Returns the product of the variable's domain size in the Instantiation.

References Instantiation(), _chgVal_(), _overflow_, _vals_, _vars_, domainSize(), and GUM_ERROR.

Here is the call graph for this function:

◆ chgVal() [3/4]

INLINE Instantiation & gum::Instantiation::chgVal ( std::string_view 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 114 of file instantiation_inl.h.

114 {
115 return chgVal(variable(var), newVal);
116 }
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.

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

Here is the call graph for this function:

◆ chgVal() [4/4]

INLINE Instantiation & gum::Instantiation::chgVal ( std::string_view var,
std::string_view 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
OutOfBoundsRaised if newval is not a possible value for the variable

Definition at line 118 of file instantiation_inl.h.

118 {
119 const auto& vv = variable(var);
120 Idx pos = vv.index(newVal);
121 return chgVal(vv, pos);
122 }

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

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 141 of file instantiation_inl.h.

141 {
142 if (_master_) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
143
144 _vars_.clear();
145 _vals_.clear();
146 }

References _master_, _vals_, _vars_, and GUM_ERROR.

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

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 56 of file instantiation_inl.h.

56{ return _vars_.exists(&v); }

References _vars_.

Referenced by _reorder_(), gum::BayesNet< double >::_unsafeChangeTensor_(), gum::MultiDimContainer< double >::copyFrom(), decIn(), decOut(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::MultiDimWithOffset< GUM_ELEMENT >::getOffs_(), incIn(), incOut(), operator=(), operator==(), setFirstIn(), setFirstOut(), setLastIn(), setLastOut(), and setValsFrom().

Here is the caller graph for this function:

◆ contains() [2/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 66 of file instantiation_inl.h.

66{ return _vars_.exists(v); }

References _vars_.

◆ contains() [3/3]

INLINE bool gum::Instantiation::contains ( std::string_view name) const

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Definition at line 58 of file instantiation_inl.h.

58 {
59 for (const auto& v: _vars_) {
60 if (v->name() == name) return true;
61 }
62 return false;
63 }

References _vars_.

◆ dec()

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 329 of file instantiation.cpp.

329 {
330 Size p = nbrDim();
331 if (p == 0) { _overflow_ = true; }
332
333 if (_overflow_) return;
334 p -= 1;
335 Idx cpt = 0;
336 // if we are in overflow, do nothing
337
338 // perform the increment
339 while (true) {
340 Idx v = _vals_[cpt];
341
342 if (v == 0) {
343 _vals_[cpt] = _vars_[cpt]->domainSize() - 1;
344
345 if (cpt == p) {
346 _overflow_ = true;
347
349
350 return;
351 } else ++cpt;
352 } else {
353 --_vals_[cpt];
354 break;
355 }
356 }
357
359 }
void _masterLastNotification_() const
void _masterDecNotification_() const
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

References _masterDecNotification_(), _masterLastNotification_(), _overflow_, _vals_, _vars_, and nbrDim().

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

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

◆ decIn()

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 403 of file instantiation.cpp.

403 {
404 if (i.nbrDim() == 0) {
405 _overflow_ = true;
406 return;
407 }
408 Size p = i.nbrDim() - 1;
409 Idx i_cpt = 0;
410 // if we are in overflow, do nothing
411
412 if (_overflow_) return;
413
414 while (true) {
415 // verify that _vars_[cpt] belongs to i before incrementing its value
416 const DiscreteVariable& v = i.variable(i_cpt);
417
418 if (!contains(v)) {
419 if (i_cpt == p) {
420 _overflow_ = true;
421 return;
422 } else ++i_cpt;
423 } else {
424 Idx cpt = pos(v);
425 Idx iv = _vals_[cpt];
426
427 if (iv == 0) {
428 _chgVal_(cpt, _vars_[cpt]->domainSize() - 1);
429
430 if (i_cpt == p) {
431 _overflow_ = true;
432 return;
433 } else ++i_cpt;
434 } else {
435 _chgVal_(cpt, iv - 1);
436 return;
437 }
438 }
439 }
440 }

References Instantiation(), _chgVal_(), _overflow_, _vals_, _vars_, contains(), domainSize(), nbrDim(), pos(), and variable().

Here is the call graph for this function:

◆ decNotVar()

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 547 of file instantiation.cpp.

547 {
548 if (nbrDim() == 0) {
549 _overflow_ = true;
550 return;
551 }
552 Size p = nbrDim() - 1;
553 Idx cpt = 0;
554 // if we are in overflow, do nothing
555
556 if (_overflow_) return;
557
558 while (true) {
559 if (_vars_[cpt] == &v) {
560 if (cpt == p) {
561 _overflow_ = true;
562 return;
563 } else ++cpt;
564 } else {
565 Idx iv = _vals_[cpt];
566
567 if (iv == 0) {
568 _chgVal_(cpt, _vars_[cpt]->domainSize() - 1);
569
570 if (cpt == p) {
571 _overflow_ = true;
572 return;
573 } else ++cpt;
574 } else {
575 _chgVal_(cpt, iv - 1);
576 return;
577 }
578 }
579 }
580 }

References _chgVal_(), _overflow_, _vals_, _vars_, domainSize(), and nbrDim().

Referenced by gum::Tensor< GUM_SCALAR >::toString().

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

◆ decOut()

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 477 of file instantiation.cpp.

477 {
478 if (nbrDim() == 0) {
479 _overflow_ = true;
480 return;
481 }
482 Size p = nbrDim() - 1;
483 Idx cpt = 0;
484 // if we are in overflow, do nothing
485
486 if (_overflow_) return;
487
488 while (true) {
489 if (i.contains(_vars_[cpt])) {
490 if (cpt == p) {
491 _overflow_ = true;
492 return;
493 } else ++cpt;
494 } else {
495 Idx v = _vals_[cpt];
496
497 if (v == 0) {
498 _chgVal_(cpt, _vars_[cpt]->domainSize() - 1);
499
500 if (cpt == p) {
501 _overflow_ = true;
502 return;
503 } else ++cpt;
504 } else {
505 _chgVal_(cpt, v - 1);
506 return;
507 }
508 }
509 }
510 }

References Instantiation(), _chgVal_(), _overflow_, _vals_, _vars_, contains(), domainSize(), and nbrDim().

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 386 of file instantiation_inl.h.

386 {
387 // get the position of the variable
388 Idx cpt = _vars_.pos(&v);
389 // if we are in overflow, do nothing
390
391 if (_overflow_) return;
392
393 Idx p = _vals_[cpt];
394
395 if (p == 0) {
396 _chgVal_(cpt, v.domainSize() - 1);
397 _overflow_ = true;
398 } else {
399 _chgVal_(cpt, p - 1);
400 }
401 }

References _chgVal_(), _overflow_, _vals_, _vars_, and gum::DiscreteVariable::domainSize().

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 150 of file instantiation_inl.h.

150 {
151 Size s = 1;
152
153 for (const auto var: _vars_)
154 s *= var->domainSize();
155
156 return s;
157 }

References _vars_.

Referenced by chgVal(), decIn(), decNotVar(), decOut(), inc(), incIn(), incNotVar(), incOut(), setLast(), setLastIn(), and setLastOut().

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 493 of file instantiation_inl.h.

493{ return _vals_.empty(); }

References _vals_.

Referenced by gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples().

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 203 of file instantiation_inl.h.

203{ return inOverflow(); }
bool inOverflow() const
Indicates whether the current value of the tuple is correct or not.

References inOverflow().

Referenced by gum::prm::PRMInference< GUM_SCALAR >::PRMInference(), gum::prm::PRMFormAttribute< GUM_SCALAR >::_fillCpf_(), gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_(), gum::GraphicalModelInference< GUM_SCALAR >::_isHardEvidence_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_isHardEvidence_(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_threadUpdate_(), gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence(), gum::prm::PRMInference< GUM_SCALAR >::addEvidence(), gum::MultiDimContainer< GUM_ELEMENT >::apply(), gum::prm::PRMFormAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::o3prmr::O3prmrInterpreter::checkObserve(), gum::GraphicalModelInference< GUM_SCALAR >::chgEvidence(), gum::MultiDimBucket< GUM_ELEMENT >::compute(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copy(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copyCpf(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::copyCpf(), gum::MultiDimContainer< GUM_ELEMENT >::copyFrom(), gum::MultiDimContainer< GUM_ELEMENT >::copyFrom(), gum::learning::DAG2BNLearner::createBNwithEM(), gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::disturbReducCPT(), gum::SimpleCPTDisturber< GUM_SCALAR >::disturbReducCPT(), gum::DecisionTensor< GUM_SCALAR >::divideEvenZero(), gum::Tensor< GUM_SCALAR >::draw(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::JointTargetedMRFInference< GUM_SCALAR >::evidenceJointImpact(), gum::Tensor< GUM_SCALAR >::fillWith(), gum::Tensor< GUM_SCALAR >::findAll(), gum::MultiDimContainer< double >::get(), gum::prm::PRMAggregate< GUM_SCALAR >::getCastDescendant(), gum::prm::PRMFormAttribute< GUM_SCALAR >::getCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::getCastDescendant(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), gum::Tensor< GUM_SCALAR >::operator&(), gum::prm::PRMInference< double >::operator=(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::InfluenceDiagram< GUM_SCALAR >::operator==(), gum::Tensor< GUM_SCALAR >::operator|(), gum::Tensor< GUM_SCALAR >::operator~(), gum::FMDPSimulator::perform(), gum::MultiDimContainer< double >::populate(), gum::prm::StructuredInference< GUM_SCALAR >::posterior_(), gum::prm::o3prmr::O3prmrInterpreter::query(), gum::Tensor< GUM_SCALAR >::randomCPT(), gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule(), gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule(), gum::Estimator< GUM_SCALAR >::setFromLBP(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::prm::PRMFormAttribute< GUM_SCALAR >::swap(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::swap(), gum::Tensor< GUM_SCALAR >::toString(), gum::prm::PRMFormAttribute< GUM_SCALAR >::type_(), and gum::prm::PRMScalarAttribute< GUM_SCALAR >::type_().

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 127 of file instantiation_inl.h.

127 {
128 // if _master_ : not allowed
129 if (_master_) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
130
131 // check that the variable does actually belong to the Instantiation
132 if (!_vars_.exists(&v)) { GUM_ERROR(NotFound, "Var does not exist in this instantiation") }
133
134 // actually delete the dimension
135 _erase_(v);
136 }
void _erase_(const DiscreteVariable &v)
Removes a variable from the sequence of vars.

References _erase_(), _master_, _vars_, and GUM_ERROR.

Referenced by gum::GibbsOperator< GUM_SCALAR >::_drawVarMonteCarlo_(), gum::GibbsOperator< GUM_SCALAR >::_GibbsSample_(), gum::MCBNDistance< GUM_SCALAR >::drawSample_(), erase(), and gum::credal::CredalNet< GUM_SCALAR >::toString().

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

◆ erase() [2/2]

INLINE void gum::Instantiation::erase ( std::string_view name)

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Definition at line 138 of file instantiation_inl.h.

138{ erase(variable(name)); }
void erase(const DiscreteVariable &v) final
Removes a variable from the Instantiation.

References erase(), and variable().

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 248 of file instantiation.cpp.

248 {
249 if (m != _master_) { GUM_ERROR(OperationNotAllowed, "only master can do this") }
250
251 _erase_(v);
252
253 if (_master_) _master_->setChangeNotification(*this);
254 }

References _erase_(), _master_, and GUM_ERROR.

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 232 of file instantiation.cpp.

232 {
233 if (_master_) {
234 _master_->unregisterSlave(*this);
235 _master_ = nullptr;
236 }
237 return true;
238 }

References _master_.

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

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 182 of file instantiation.cpp.

182 {
183 Idx res = 0;
184
185 for (const auto var: _vars_)
186 res += val(*var);
187
188 return res;
189 }
Idx val(Idx i) const
Returns the current value of the variable at position i.

References _vars_, and val().

Here is the call graph for this function:

◆ inc()

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 299 of file instantiation.cpp.

299 {
300 Size p = nbrDim();
301 if (p == 0) { _overflow_ = true; }
302
303 if (_overflow_) return;
304 p -= 1;
305 Idx cpt = 0;
306 // if we are in overflow, do nothing
307
308 // perform the increment
309 while (true) {
310 Idx v = _vals_[cpt];
311
312 if (v + 1 == _vars_[cpt]->domainSize()) {
313 _vals_[cpt] = 0;
314
315 if (cpt == p) {
316 _overflow_ = true;
318 return;
319 } else ++cpt;
320 } else {
321 ++_vals_[cpt];
322 break;
323 }
324 }
325
327 }
void _masterIncNotification_() const
void _masterFirstNotification_() const

References _masterFirstNotification_(), _masterIncNotification_(), _overflow_, _vals_, _vars_, domainSize(), and nbrDim().

Referenced by gum::prm::PRMInference< GUM_SCALAR >::PRMInference(), gum::prm::PRMFormAttribute< GUM_SCALAR >::_fillCpf_(), gum::GraphicalModelInference< GUM_SCALAR >::_isHardEvidence_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_isHardEvidence_(), gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence(), gum::prm::PRMInference< GUM_SCALAR >::addEvidence(), gum::prm::PRMFormAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::o3prmr::O3prmrInterpreter::checkObserve(), gum::GraphicalModelInference< GUM_SCALAR >::chgEvidence(), gum::MultiDimBucket< GUM_ELEMENT >::compute(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copy(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copyCpf(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::copyCpf(), gum::DecisionTensor< GUM_SCALAR >::divideEvenZero(), gum::Tensor< GUM_SCALAR >::draw(), gum::prm::GroundedInference< GUM_SCALAR >::evidenceAdded_(), gum::prm::PRMAggregate< GUM_SCALAR >::getCastDescendant(), gum::prm::PRMFormAttribute< GUM_SCALAR >::getCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::getCastDescendant(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), operator++(), operator+=(), gum::prm::PRMInference< double >::operator=(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::InfluenceDiagram< GUM_SCALAR >::operator==(), gum::prm::PRMInference< GUM_SCALAR >::posterior(), gum::prm::StructuredInference< GUM_SCALAR >::posterior_(), gum::prm::o3prmr::O3prmrInterpreter::query(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), gum::prm::PRMFormAttribute< GUM_SCALAR >::swap(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::swap(), gum::prm::PRMFormAttribute< GUM_SCALAR >::type_(), and gum::prm::PRMScalarAttribute< GUM_SCALAR >::type_().

Here is the call graph for this function:

◆ incIn()

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 361 of file instantiation.cpp.

361 {
362 // if i is empty, overflow and do nothing
363 if (i.nbrDim() == 0) {
364 _overflow_ = true;
365 return;
366 }
367
368 // if we are in overflow, do nothing
369 if (_overflow_) return;
370
371 Size p = i.nbrDim() - 1;
372
373 Idx i_cpt = 0;
374
375 while (true) {
376 // verify that _vars_[cpt] belongs to i before incrementing its value
377 const DiscreteVariable& v = i.variable(i_cpt);
378
379 if (!contains(v)) {
380 if (i_cpt == p) {
381 _overflow_ = true;
382 return;
383 } else ++i_cpt;
384 } else {
385 Idx cpt = pos(v);
386 Idx iv = _vals_[cpt];
387
388 if (iv + 1 == _vars_[cpt]->domainSize()) {
389 _chgVal_(cpt, 0);
390
391 if (i_cpt == p) {
392 _overflow_ = true;
393 return;
394 } else ++i_cpt;
395 } else {
396 _chgVal_(cpt, iv + 1);
397 return;
398 }
399 }
400 }
401 }

References Instantiation(), _chgVal_(), _overflow_, _vals_, _vars_, contains(), domainSize(), nbrDim(), pos(), and variable().

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

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

◆ incNotVar()

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 512 of file instantiation.cpp.

512 {
513 if (nbrDim() == 0) {
514 _overflow_ = true;
515 return;
516 }
517 Size p = nbrDim() - 1;
518 Idx cpt = 0;
519 // if we are in overflow, do nothing
520
521 if (_overflow_) return;
522
523 while (true) {
524 if (_vars_[cpt] == &v) {
525 if (cpt == p) {
526 _overflow_ = true;
527 return;
528 } else ++cpt;
529 } else {
530 Idx iv = _vals_[cpt];
531
532 if (iv + 1 == _vars_[cpt]->domainSize()) {
533 _chgVal_(cpt, 0);
534
535 if (cpt == p) {
536 _overflow_ = true;
537 return;
538 } else ++cpt;
539 } else {
540 _chgVal_(cpt, iv + 1);
541 return;
542 }
543 }
544 }
545 }

References _chgVal_(), _overflow_, _vals_, _vars_, domainSize(), and nbrDim().

Referenced by gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::Tensor< GUM_SCALAR >::randomCPT(), and gum::Tensor< GUM_SCALAR >::toString().

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

◆ incOut()

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 442 of file instantiation.cpp.

442 {
443 if (nbrDim() == 0) {
444 _overflow_ = true;
445 return;
446 }
447 Size p = nbrDim() - 1;
448 Idx cpt = 0;
449 // if we are in overflow, do nothing
450
451 if (_overflow_) return;
452
453 while (true) {
454 if (i.contains(_vars_[cpt])) {
455 if (cpt == p) {
456 _overflow_ = true;
457 return;
458 } else ++cpt;
459 } else {
460 Idx v = _vals_[cpt];
461
462 if (v + 1 == _vars_[cpt]->domainSize()) {
463 _chgVal_(cpt, 0);
464
465 if (cpt == p) {
466 _overflow_ = true;
467 return;
468 } else ++cpt;
469 } else {
470 _chgVal_(cpt, v + 1);
471 return;
472 }
473 }
474 }
475 }

References Instantiation(), _chgVal_(), _overflow_, _vals_, _vars_, contains(), domainSize(), and nbrDim().

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

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 368 of file instantiation_inl.h.

368 {
369 // get the position of the variable
370 Idx cpt = _vars_.pos(&v);
371 // if we are in overflow, do nothing
372
373 if (_overflow_) return;
374
375 Idx p = _vals_[cpt];
376
377 if (p + 1 == v.domainSize()) {
378 _chgVal_(cpt, 0);
379 _overflow_ = true;
380 } else {
381 _chgVal_(cpt, p + 1);
382 }
383 }

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::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::Tensor< GUM_SCALAR >::randomCPT(), and gum::Tensor< GUM_SCALAR >::toString().

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 200 of file instantiation_inl.h.

200{ return _overflow_; }

References _overflow_.

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

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 422 of file instantiation_inl.h.

422{ return isMaster(&m); }
bool isMaster(const MultiDimAdressable *m) const
Indicates whether m is the master of this instantiation.

References isMaster().

Here is the call 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 419 of file instantiation_inl.h.

419{ return (_master_ == m); }

References _master_.

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

Here is the caller 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 416 of file instantiation_inl.h.

416{ return (_master_ != nullptr); }

References _master_.

◆ nbrDim()

◆ operator++()

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

Alias of Instantiation::inc().

Returns
Returns this Instantiation.

Definition at line 220 of file instantiation_inl.h.

220 {
221 inc();
222 return *this;
223 }
void inc()
Operator increment.

References Instantiation(), and inc().

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 232 of file instantiation_inl.h.

232 {
233 for (Idx i = 0; i < depl; i++)
234 inc();
235
236 return *this;
237 }

References Instantiation(), and inc().

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 226 of file instantiation_inl.h.

226 {
227 dec();
228 return *this;
229 }
void dec()
Operator decrement.

References Instantiation(), and dec().

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 240 of file instantiation_inl.h.

240 {
241 for (Idx i = 0; i < depl; i++)
242 dec();
243
244 return *this;
245 }

References Instantiation(), and dec().

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 131 of file instantiation.cpp.

131 {
132 if (_master_) {
133 if (!aI.isMaster(_master_)) { // aI as the same master.
134 if (nbrDim() != aI.nbrDim()) { GUM_ERROR(OperationNotAllowed, "in slave Instantiation") }
135
136 for (Idx i = 0; i < nbrDim(); i++) {
137 if ((!contains(aI.variable(i))) || (!aI.contains(variable(i)))) {
138 GUM_ERROR(OperationNotAllowed, "in slave Instantiation")
139 }
140 }
141 }
142
143 setVals(aI);
144 } else {
145 // copy the content of aI
146 _vars_ = aI._vars_;
147 _vals_ = aI._vals_;
148 _overflow_ = aI._overflow_;
149
150 if (aI._master_) actAsSlave(*aI._master_);
151 }
152
153 return *this;
154 }
Instantiation & setVals(const Instantiation &i)
Assign the values from i in the Instantiation.

References Instantiation(), _master_, _overflow_, _vals_, _vars_, actAsSlave(), contains(), GUM_ERROR, isMaster(), nbrDim(), setVals(), and variable().

Here is the call graph for this function:

◆ operator==()

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

operator==

Definition at line 517 of file instantiation_inl.h.

517 {
518 if (inOverflow() && other.inOverflow()) return true;
519 if (inOverflow() != other.inOverflow()) return false;
520 if (other.nbrDim() != nbrDim()) return false;
521 for (const auto& k: variablesSequence()) {
522 if (!other.contains(k)) return false;
523 if (val(*k) != other.val(*k)) return false;
524 }
525 return true;
526 }
const Sequence< const DiscreteVariable * > & variablesSequence() const final
Returns the sequence of DiscreteVariable of this instantiation.

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

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 160 of file instantiation_inl.h.

160{ return _vars_.pos(&k); }

References _vars_.

Referenced by _erase_(), _reorder_(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::prm::PRMFormAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::becomeCastDescendant(), chgVal(), decIn(), incIn(), and gum::IBayesNet< GUM_SCALAR >::operator==().

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 206 of file instantiation_inl.h.

206{ return inOverflow(); }

References inOverflow().

Here is the call graph for this function:

◆ reorder() [1/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 274 of file instantiation_inl.h.

274{ reorder(i.variablesSequence()); }
void reorder(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.

References Instantiation(), reorder(), and variablesSequence().

Here is the call graph for this function:

◆ reorder() [2/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 444 of file instantiation_inl.h.

444 {
445 if (_master_ != nullptr) {
446 GUM_ERROR(OperationNotAllowed, "Reordering impossible in slave instantiation")
447 }
448
449 _reorder_(original);
450 }
void _reorder_(const Sequence< const DiscreteVariable * > &v)
Reorder vars of this instantiation giving the order in v.

References _master_, _reorder_(), and GUM_ERROR.

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

Here is the call graph for this function:
Here is the caller 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 57 of file multiDimInterface_inl.h.

57 {
58 if (!contains(x)) { GUM_ERROR(NotFound, "could not find the variable") }
59
60 if (contains(y)) { GUM_ERROR(DuplicateElement, "variable " << y << " already in MultiDim") }
61
62 if (x.domainSize() != y.domainSize()) {
63 GUM_ERROR(OperationNotAllowed, "incompatible variables")
64 }
65
66 replace_(&x, &y);
67 }
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.
virtual bool contains(const DiscreteVariable &v) const =0
Returns true if var is in *this.

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

Here is the call 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 496 of file instantiation_inl.h.

496 {
497 _vars_.setAtPos(_vars_.pos(x), y);
498 }

References _vars_.

◆ 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 248 of file instantiation_inl.h.

248 {
249 _overflow_ = false;
250 Size s = nbrDim();
251
252 for (Idx p = 0; p < s; ++p)
253 _vals_[p] = 0;
254
256 }

References _masterFirstNotification_(), _overflow_, _vals_, and nbrDim().

Referenced by gum::prm::PRMInference< GUM_SCALAR >::PRMInference(), gum::prm::PRMFormAttribute< GUM_SCALAR >::_fillCpf_(), gum::credal::CredalNet< GUM_SCALAR >::_intervalToCredal_(), gum::GraphicalModelInference< GUM_SCALAR >::_isHardEvidence_(), gum::prm::StructuredBayesBall< GUM_SCALAR >::_isHardEvidence_(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::_threadUpdate_(), gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence(), gum::prm::PRMInference< GUM_SCALAR >::addEvidence(), gum::MultiDimContainer< GUM_ELEMENT >::apply(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::prm::PRMFormAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::becomeCastDescendant(), gum::credal::CredalNet< GUM_SCALAR >::bnToCredal(), gum::prm::o3prmr::O3prmrInterpreter::checkObserve(), gum::GraphicalModelInference< GUM_SCALAR >::chgEvidence(), gum::MultiDimBucket< GUM_ELEMENT >::compute(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copy(), gum::prm::PRMFormAttribute< GUM_SCALAR >::copyCpf(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::copyCpf(), gum::MultiDimContainer< GUM_ELEMENT >::copyFrom(), gum::MultiDimContainer< GUM_ELEMENT >::copyFrom(), gum::MCBayesNetGenerator< GUM_SCALAR, SimpleCPTGenerator, SimpleCPTDisturber >::disturbReducCPT(), gum::SimpleCPTDisturber< GUM_SCALAR >::disturbReducCPT(), gum::DecisionTensor< GUM_SCALAR >::divideEvenZero(), gum::Tensor< GUM_SCALAR >::draw(), gum::prm::GroundedInference< GUM_SCALAR >::evidenceAdded_(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), gum::Tensor< GUM_SCALAR >::fillWith(), gum::Tensor< GUM_SCALAR >::findAll(), gum::MultiDimContainer< double >::get(), gum::prm::PRMAggregate< GUM_SCALAR >::getCastDescendant(), gum::prm::PRMFormAttribute< GUM_SCALAR >::getCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::getCastDescendant(), gum::credal::CredalNet< GUM_SCALAR >::idmLearning(), gum::credal::CredalNet< GUM_SCALAR >::intervalToCredal(), gum::credal::CredalNet< GUM_SCALAR >::intervalToCredalWithFiles(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), gum::credal::CredalNet< GUM_SCALAR >::lagrangeNormalization(), gum::Tensor< GUM_SCALAR >::operator&(), gum::prm::PRMInference< double >::operator=(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::InfluenceDiagram< GUM_SCALAR >::operator==(), gum::Tensor< GUM_SCALAR >::operator|(), gum::Tensor< GUM_SCALAR >::operator~(), gum::MultiDimContainer< double >::populate(), gum::prm::PRMInference< GUM_SCALAR >::posterior(), gum::prm::StructuredInference< GUM_SCALAR >::posterior_(), gum::prm::o3prmr::O3prmrInterpreter::query(), setFirstNotVar(), gum::Estimator< GUM_SCALAR >::setFromLBP(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), gum::prm::PRMFormAttribute< GUM_SCALAR >::swap(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::swap(), gum::credal::CredalNet< GUM_SCALAR >::toString(), gum::Tensor< GUM_SCALAR >::toString(), gum::prm::PRMFormAttribute< GUM_SCALAR >::type_(), and gum::prm::PRMScalarAttribute< GUM_SCALAR >::type_().

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 277 of file instantiation_inl.h.

277 {
278 _overflow_ = false;
279 Idx s = nbrDim();
280
281 for (Size p = 0; p < s; ++p)
282 if (i.contains(_vars_[p])) _chgVal_(p, 0);
283 }

References Instantiation(), _chgVal_(), _overflow_, _vars_, contains(), and nbrDim().

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

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 334 of file instantiation_inl.h.

334 {
335 _overflow_ = false;
336 Idx s = nbrDim();
337
338 for (Size p = 0; p < s; ++p) {
339 if (_vars_[p] == &v) {
340 Idx oldval = _vals_[p];
341 setFirst();
342 _chgVal_(p, oldval);
343 return;
344 }
345 }
346
347 setFirst();
348 }
void setFirst()
Assign the first values to the tuple of the Instantiation.

References _chgVal_(), _overflow_, _vals_, _vars_, nbrDim(), and setFirst().

Referenced by gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_(), and gum::Tensor< GUM_SCALAR >::randomCPT().

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 312 of file instantiation_inl.h.

312 {
313 _overflow_ = false;
314 Idx s = nbrDim();
315
316 for (Size p = 0; p < s; ++p)
317 if (!i.contains(_vars_[p])) _chgVal_(p, 0);
318 }

References Instantiation(), _chgVal_(), _overflow_, _vars_, contains(), and nbrDim().

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

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 404 of file instantiation_inl.h.

404 {
405 _overflow_ = false;
406 _chgVal_(_vars_.pos(&v), 0);
407 }

References _chgVal_(), _overflow_, and _vars_.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::Tensor< GUM_SCALAR >::randomCPT(), and gum::Tensor< GUM_SCALAR >::toString().

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 259 of file instantiation_inl.h.

259 {
260 _overflow_ = false;
261 Size s = nbrDim();
262
263 for (Idx p = 0; p < s; ++p)
264 _vals_[p] = _vars_[p]->domainSize() - 1;
265
267 }

References _masterLastNotification_(), _overflow_, _vals_, _vars_, domainSize(), and nbrDim().

Referenced by setLastNotVar(), and gum::Tensor< GUM_SCALAR >::toString().

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 298 of file instantiation_inl.h.

298 {
299 _overflow_ = false;
300 Idx s = nbrDim();
301
302 for (Size p = 0; p < s; ++p)
303 if (i.contains(_vars_[p])) _chgVal_(p, _vars_[p]->domainSize() - 1);
304 }

References Instantiation(), _chgVal_(), _overflow_, _vars_, contains(), domainSize(), and nbrDim().

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 351 of file instantiation_inl.h.

351 {
352 _overflow_ = false;
353 Idx s = nbrDim();
354
355 for (Size p = 0; p < s; ++p) {
356 if (_vars_[p] == &v) {
357 Idx oldval = _vals_[p];
358 setLast();
359 _chgVal_(p, oldval);
360 return;
361 }
362 }
363
364 setLast();
365 }
void setLast()
Assign the last values in the Instantiation.

References _chgVal_(), _overflow_, _vals_, _vars_, nbrDim(), and setLast().

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 321 of file instantiation_inl.h.

321 {
322 _overflow_ = false;
323 Idx s = nbrDim();
324
325 for (Size p = 0; p < s; ++p)
326 if (!i.contains(_vars_[p])) _chgVal_(p, _vars_[p]->domainSize() - 1);
327 }

References Instantiation(), _chgVal_(), _overflow_, _vars_, contains(), domainSize(), and nbrDim().

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 410 of file instantiation_inl.h.

410 {
411 _overflow_ = false;
412 _chgVal_(_vars_.pos(&v), v.domainSize() - 1);
413 }

References _chgVal_(), _overflow_, _vars_, and gum::DiscreteVariable::domainSize().

Referenced by gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples().

Here is the call graph for this function:
Here is the caller 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 useful 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 286 of file instantiation_inl.h.

286 {
287 _overflow_ = false;
288 Idx s = i.nbrDim();
289
290 for (Size p = 0; p < s; ++p) {
291 if (auto pPos = _vars_.tryPos(&i.variable(p))) _chgVal_(*pPos, i.val(p));
292 }
293
294 return *this;
295 }

References Instantiation(), _chgVal_(), _overflow_, _vars_, nbrDim(), val(), and variable().

Referenced by gum::SimpleCPTDisturber< GUM_SCALAR >::disturbReducCPT(), operator=(), gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule(), gum::prm::PRMFactory< GUM_SCALAR >::setCPFByRule(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), and gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked().

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 191 of file instantiation.cpp.

193 {
194 for (const auto& elt: map) {
195 const DiscreteVariable& var = *elt.second;
196
197 if (!external.contains(*elt.first)) {
198 GUM_ERROR(NotFound, var.name() << " : missing variable in external instantiation")
199 }
200
201 Idx val = external.val(*elt.first);
202
203 if (!contains(var)) {
204 GUM_ERROR(NotFound, var.name() << " : missing variable in instantiation")
205 }
206
207 chgVal(var, val);
208 }
209 }

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

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 241 of file instantiation.cpp.

241 {
242 if (m != _master_) { GUM_ERROR(OperationNotAllowed, "only master can do this") }
243
244 _reorder_(_master_->variablesSequence());
245 }

References _master_, _reorder_(), and GUM_ERROR.

Here is the call 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 157 of file instantiation.cpp.

157 {
158 std::string sstr;
159 // check if the value of the instantiation is correct
160
161 if (_overflow_) sstr = "<invalid>";
162
163 sstr += "<";
164
165 bool first = true;
166
167 for (const auto var: _vars_) {
168 if (!first) sstr += "|";
169
170 first = false;
171 sstr += var->name();
172 sstr += ":";
173 sstr += var->label(val(*var));
174 }
175
176 sstr += ">";
177
178 return sstr;
179 }

References _overflow_, _vars_, and val().

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

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 213 of file instantiation_inl.h.

213{ _overflow_ = false; }

References _overflow_.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::_fillProbaWithValuesTable_(), and gum::Tensor< GUM_SCALAR >::randomCPT().

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:
// 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();
}
Multidimensional matrix stored as an array in memory.

Definition at line 210 of file instantiation_inl.h.

210{ _overflow_ = false; }

References _overflow_.

◆ val() [1/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 175 of file instantiation_inl.h.

175 {
176 return _vals_[_vars_.pos(&var)];
177 }

References _vals_, and _vars_.

◆ val() [2/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 166 of file instantiation_inl.h.

166 {
167 if (i >= _vals_.size()) {
168 GUM_ERROR(NotFound, i << " is out of bound index for the instantiation.")
169 }
170
171 return _vals_[i];
172 }

References _vals_, and GUM_ERROR.

Referenced by gum::GraphicalModelInference< GUM_SCALAR >::_isHardEvidence_(), gum::credal::InferenceEngine< GUM_SCALAR >::addEvidence(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::aggregator::Amplitude< GUM_SCALAR >::buildValue_(), gum::aggregator::Median< GUM_SCALAR >::buildValue_(), gum::aggregator::MultiDimAggregator< GUM_ELEMENT >::buildValue_(), gum::HashFunc< Instantiation >::castToSize(), gum::prm::o3prmr::O3prmrInterpreter::checkObserve(), gum::Tensor< GUM_SCALAR >::draw(), gum::MonteCarloSampling< GUM_SCALAR >::draw_(), gum::learning::BNDatabaseGenerator< GUM_SCALAR >::drawSamples(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::MarginalTargetedMRFInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::JointTargetedMRFInference< GUM_SCALAR >::evidenceJointImpact(), gum::SDYNA::feedback(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), gum::Tensor< GUM_ELEMENT >::findAll(), gum::MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >::get(), gum::MultiDimLogit< GUM_SCALAR >::get(), gum::MultiDimNoisyAND< GUM_SCALAR >::get(), gum::MultiDimNoisyORCompound< GUM_SCALAR >::get(), gum::MultiDimNoisyORNet< GUM_SCALAR >::get(), gum::prm::PRMAggregate< GUM_SCALAR >::getCastDescendant(), gum::prm::PRMFormAttribute< GUM_SCALAR >::getCastDescendant(), gum::prm::PRMScalarAttribute< GUM_SCALAR >::getCastDescendant(), hamming(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::InfluenceDiagram< GUM_SCALAR >::operator==(), operator==(), gum::FMDPSimulator::perform(), gum::prm::o3prmr::O3prmrInterpreter::query(), gum::Tensor< GUM_SCALAR >::randomCPT(), gum::credal::CredalNet< GUM_SCALAR >::setCPT(), setVals(), setValsFrom(), gum::BayesNetFactory< GUM_SCALAR >::setVariableValuesUnchecked(), toString(), gum::Tensor< GUM_SCALAR >::toString(), gum::Estimator< GUM_SCALAR >::update(), and val().

◆ val() [3/3]

INLINE Idx gum::Instantiation::val ( std::string_view name) const

Returns the number of variables in the Instantiation.

Returns
Returns the number of variables in the Instantiation.

Definition at line 180 of file instantiation_inl.h.

180{ return val(variable(name)); }

References val(), and variable().

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 183 of file instantiation_inl.h.

183 {
184 return _vals_[_vars_.pos(pvar)];
185 }

References _vals_, and _vars_.

Referenced by gum::StatesCounter::_incState_(), gum::StatesChecker::_insertState_(), gum::StatesChecker::addState(), gum::MultiDimWithOffset< GUM_ELEMENT >::getOffs_(), and gum::StatesCounter::incState().

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 188 of file instantiation_inl.h.

188{ return *(_vars_.atPos(i)); }

References _vars_.

Referenced by gum::BayesNet< double >::_unsafeChangeTensor_(), gum::aggregator::Median< GUM_SCALAR >::buildValue_(), chgVal(), chgVal(), gum::GibbsBNdistance< GUM_SCALAR >::computeKL_(), decIn(), erase(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), incIn(), gum::JointTargetedInference< GUM_SCALAR >::jointMutualInformation(), gum::JointTargetedMRFInference< GUM_SCALAR >::jointMutualInformation(), operator=(), gum::IBayesNet< GUM_SCALAR >::operator==(), gum::IMarkovRandomField< GUM_SCALAR >::operator==(), gum::InfluenceDiagram< GUM_SCALAR >::operator==(), gum::credal::CredalNet< GUM_SCALAR >::setCPT(), setVals(), gum::Estimator< GUM_SCALAR >::update(), and val().

Here is the caller graph for this function:

◆ variable() [2/2]

INLINE const DiscreteVariable & gum::Instantiation::variable ( std::string_view 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. @warging This function is not O(1)
Exceptions
NotFoundRaised if the element cannot be found.

Implements gum::MultiDimInterface.

Definition at line 191 of file instantiation_inl.h.

191 {
192 for (const auto& v: _vars_) {
193 if (v->name() == name) return *v;
194 }
195
196 GUM_ERROR(NotFound, "'" << name << "' can not be found in the instantiation.")
197 }

References _vars_, and GUM_ERROR.

◆ 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 425 of file instantiation_inl.h.

425 {
426 return _vars_;
427 }

References _vars_.

Referenced by gum::StatesCounter::_incState_(), gum::StatesChecker::_insertState_(), gum::HashFunc< Instantiation >::castToSize(), gum::SDYNA::feedback(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), operator==(), reorder(), gum::StatesChecker::reset(), gum::StatesCounter::reset(), gum::credal::CredalNet< GUM_SCALAR >::setCPT(), gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns(), and gum::prm::PRMFactory< GUM_SCALAR >::setRawCPFByColumns().

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 1139 of file instantiation.h.

Referenced by Instantiation(), Instantiation(), Instantiation(), Instantiation(), Instantiation(), Instantiation(), _add_(), chgVal(), chgVal(), dec(), decIn(), decNotVar(), decOut(), decVar(), inc(), incIn(), incNotVar(), incOut(), incVar(), inOverflow(), 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: