aGrUM  0.14.3
gum::Potential< GUM_SCALAR > Class Template Reference

aGrUM's Potential is a multi-dimensional array with tensor operators. More...

#include <agrum/multidim/potential.h>

+ Inheritance diagram for gum::Potential< GUM_SCALAR >:
+ Collaboration diagram for gum::Potential< GUM_SCALAR >:

Public Member Functions

Constructors, Destructors and Copy
 Potential ()
 Default constructor. More...
 
 Potential (MultiDimImplementation< GUM_SCALAR > *aContent)
 Creates an potential around aContent. More...
 
 Potential (MultiDimImplementation< GUM_SCALAR > *aContent, const MultiDimContainer< GUM_SCALAR > &src)
 Copy constructor. More...
 
 Potential (const Potential< GUM_SCALAR > &src)
 Copy constructor & assignment. More...
 
Potential< GUM_SCALAR > & operator= (const Potential< GUM_SCALAR > &src)
 Default constructor. More...
 
 Potential (Potential< GUM_SCALAR > &&from)
 move constructor & assignement More...
 
Potential< GUM_SCALAR > & operator= (Potential< GUM_SCALAR > &&src)
 Default constructor. More...
 
 ~Potential ()
 Destructor. More...
 
MultiDimContainer implementation
virtual Potential< GUM_SCALAR > * newFactory () const
 Default implementation of MultiDimContainer::set(). More...
 
Class operation for Potential instances
Potential< GUM_SCALAR > margSumOut (const Set< const DiscreteVariable * > &del_vars) const
 Projection using sum as operation (and implementation-optimized operations) More...
 
Potential< GUM_SCALAR > margSumIn (const Set< const DiscreteVariable * > &kept_vars) const
 Projection using sum as operation (and implementation-optimized operations) More...
 
Potential< GUM_SCALAR > margProdOut (const Set< const DiscreteVariable * > &del_vars) const
 Projection using multiplication as operation (and implementation-optimized operations) More...
 
Potential< GUM_SCALAR > margProdIn (const Set< const DiscreteVariable * > &kept_vars) const
 Projection using multiplication as operation (and implementation-optimized operations) More...
 
Potential< GUM_SCALAR > margMinOut (const Set< const DiscreteVariable * > &del_vars) const
 Projection using min as operation (and implementation-optimized operations) More...
 
Potential< GUM_SCALAR > margMinIn (const Set< const DiscreteVariable * > &kept_vars) const
 Projection using min as operation (and implementation-optimized operations) More...
 
Potential< GUM_SCALAR > margMaxOut (const Set< const DiscreteVariable * > &del_vars) const
 Projection using max as operation (and implementation-optimized operations) More...
 
Potential< GUM_SCALAR > margMaxIn (const Set< const DiscreteVariable * > &kept_vars) const
 Projection using max as operation (and implementation-optimized operations) More...
 
Potential< GUM_SCALAR > isNonZeroMap () const
 create a boolean-like potential using the predicate isNonZero More...
 
GUM_SCALAR sum () const
 sum of all elements in the Potential More...
 
GUM_SCALAR product () const
 product of all elements in the Potential More...
 
GUM_SCALAR max () const
 max of all elements in the Potential More...
 
GUM_SCALAR min () const
 min of all elements in the Potential More...
 
GUM_SCALAR maxNonOne () const
 max of all non one elements in the Potential More...
 
GUM_SCALAR minNonZero () const
 min of all non zero elements in the Potential More...
 
Set< InstantiationfindAll (GUM_SCALAR v) const
 set of instantiation corresponding to the parameter v in the Potential More...
 
Set< Instantiationargmax () const
 set of instantiation corresponding to the max in the Potential More...
 
Set< Instantiationargmin () const
 set of instantiation corresponding to the min in the Potential More...
 
GUM_SCALAR entropy () const
 entropy of the Potential More...
 
Potential< GUM_SCALAR > reorganize (const std::vector< const DiscreteVariable * > &vars) const
 create a new Potential with another order More...
 
Potential< GUM_SCALAR > extract (const Instantiation &inst) const
 create a new Potential extracted from *this given a partial instantiation More...
 
Potential< GUM_SCALAR > putFirst (const DiscreteVariable *var) const
 create a new Potential with a certain variable in first More...
 
const Potential< GUM_SCALAR > & fillWith (const Potential< GUM_SCALAR > &src) const
 copy a Potential data using name of variables and labels (not necessarily the same variables in the same orders) More...
 
const Potential< GUM_SCALAR > & fillWith (const Potential< GUM_SCALAR > &src, const std::vector< std::string > &mapSrc) const
 copy a Potential data using the sequence of names in mapSrc to find the corresponding variables. More...
 
const Potential< GUM_SCALAR > & fillWith (const std::vector< GUM_SCALAR > &v) const
 Automatically fills the potential with the values in v. More...
 
const Potential< GUM_SCALAR > & fillWith (const GUM_SCALAR &v) const
 Automatically fills this MultiDimContainer with the value v. More...
 
const Potential< GUM_SCALAR > & abs () const
 Apply abs on every element of the container. More...
 
const Potential< GUM_SCALAR > & normalize () const
 normalisation of this do nothing if sum is 0 More...
 
const Potential< GUM_SCALAR > & sq () const
 apply $x^2$ on every element of the container More...
 
GUM_SCALAR KL (const Potential< GUM_SCALAR > &p) const
 compute KL divergence between this and p Checks the compatibility and then compute KL divergence More...
 
void normalizeAsCPT () const
 normalisation of this as a CPT More...
 
const Potential< GUM_SCALAR > & scale (GUM_SCALAR v) const
 create a new potential multiplied by v from *this More...
 
const Potential< GUM_SCALAR > & translate (GUM_SCALAR v) const
 create a new potential added with v from *this More...
 
Idx draw () const
 get a value at random from a 1-D distribution More...
 
Potential algebra operators
Potential< GUM_SCALAR > operator+ (const Potential< GUM_SCALAR > &p2) const
 the function to be used to add two Potentials More...
 
Potential< GUM_SCALAR > operator- (const Potential< GUM_SCALAR > &p2) const
 the function to be used to subtract two Potentials More...
 
Potential< GUM_SCALAR > operator* (const Potential< GUM_SCALAR > &p2) const
 the function to be used to multiply two Potentials More...
 
Potential< GUM_SCALAR > operator/ (const Potential< GUM_SCALAR > &p2) const
 the function to be used to divide two Potentials More...
 
Potential< GUM_SCALAR > & operator+= (const Potential< GUM_SCALAR > &r)
 the function to be used to add two Potentials More...
 
Potential< GUM_SCALAR > & operator*= (const Potential< GUM_SCALAR > &r)
 the function to be used to add two Potentials More...
 
Potential< GUM_SCALAR > & operator-= (const Potential< GUM_SCALAR > &r)
 the function to be used to add two Potentials More...
 
Potential< GUM_SCALAR > & operator/= (const Potential< GUM_SCALAR > &r)
 the function to be used to add two Potentials More...
 
bool operator== (const Potential< GUM_SCALAR > &r) const
 the function to be used to add two Potentials More...
 
bool operator!= (const Potential< GUM_SCALAR > &r) const
 the function to be used to add two Potentials More...
 
virtual const std::string toString () const
 the function to be used to add two Potentials More...
 
MultiDimInterface implementation
virtual Idx nbrDim () const final
 Returns the number of vars in the multidimensional container. More...
 
virtual Size domainSize () const final
 Returns the product of the variables domain size. More...
 
virtual void add (const DiscreteVariable &v) final
 Adds a new var to the variables of the multidimensional matrix. More...
 
virtual void erase (const DiscreteVariable &var) final
 Removes a var from the variables of the multidimensional matrix. More...
 
virtual const Sequence< const DiscreteVariable *> & variablesSequence () const final
 Returns a const ref to the sequence of DiscreteVariable*. More...
 
virtual const DiscreteVariablevariable (Idx) const final
 Returns a const ref to the ith var. More...
 
virtual const DiscreteVariablevariable (const std::string &name) const final
 Returns the variable with the name. More...
 
virtual Idx pos (const DiscreteVariable &var) const final
 Returns the index of a variable. More...
 
virtual bool contains (const DiscreteVariable &var) const final
 Returns true if var is in *this. More...
 
virtual bool empty () const final
 Returns true if no var is in *this. More...
 
MultiDimAdressable implementation
virtual bool unregisterSlave (Instantiation &i) final
 Unregister i as a slave of this MultiDimAdressable. More...
 
virtual bool registerSlave (Instantiation &i) final
 Register i as a slave of this MultiDimAdressable. More...
 
virtual void changeNotification (const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval) final
 Listen to changes in a given Instantiation. More...
 
virtual void setChangeNotification (const Instantiation &i) final
 Listen to an assignment of a value in a Instantiation. More...
 
virtual void setFirstNotification (const Instantiation &i) final
 Listen to setFirst in a given Instantiation. More...
 
virtual void setLastNotification (const Instantiation &i) final
 Listen to setLast in a given Instantiation. More...
 
virtual void setIncNotification (const Instantiation &i) final
 Listen to increment in a given Instantiation. More...
 
virtual void setDecNotification (const Instantiation &i) final
 Listen to increment in each recorded Instantiation. More...
 
virtual void notifyChange () const final
 
MultiDimContainer implementation
virtual void set (const Instantiation &i, const GUM_SCALAR &value) const final
 Default implementation of MultiDimContainer::set(). More...
 
virtual GUM_SCALAR get (const Instantiation &i) const final
 Default implementation of MultiDimContainer::get(). More...
 
virtual void fill (const GUM_SCALAR &d) const final
 Default implementation of MultiDimContainer::set(). More...
 
virtual void populate (const std::vector< GUM_SCALAR > &v) const final
 Automatically fills this MultiDimContainer with the values in v. More...
 
virtual void apply (std::function< GUM_SCALAR(GUM_SCALAR) > f) const final
 Apply a function on every element of the container. More...
 
virtual GUM_SCALAR reduce (std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const final
 compute lfold for this container More...
 
virtual void beginMultipleChanges () final
 Default implementation of MultiDimContainer::set(). More...
 
virtual void endMultipleChanges () final
 Default implementation of MultiDimContainer::set(). More...
 
virtual void endMultipleChanges (const GUM_SCALAR &) final
 Default implementation of MultiDimContainer::set(). More...
 
virtual const std::string toString (const Instantiation *i) const
 Default implementation of MultiDimContainer::set(). More...
 
Accessors / Modifiers
virtual void populate (std::initializer_list< GUM_SCALAR > l) const
 Automatically fills this MultiDimContainer with the values in l. More...
 
GUM_SCALAR operator[] (const Instantiation &i) const
 An [] operator using a Instantiation as argument. More...
 
Various methods.
virtual const MultiDimImplementation< GUM_SCALAR > * content () const final
 Returns the implementation for this object (may be *this). More...
 
virtual MultiDimImplementation< GUM_SCALAR > * content () final
 Returns the implementation for this object (may be *this). More...
 
Copy methods.
virtual void copyFrom (const MultiDimContainer< GUM_SCALAR > &src) const
 Basic copy of a MultiDimContainer. More...
 
virtual void copyFrom (const MultiDimContainer< GUM_SCALAR > &src, Instantiation *p_i) const
 Basic copy of a MultiDimContainer. More...
 
virtual void extractFrom (const MultiDimContainer< GUM_SCALAR > &src, const Instantiation &mask)
 Basic extraction of a MultiDimContainer. More...
 
virtual MultiDimAdressablegetMasterRef ()
 In order to insure the dereference for decorators, we need to virtualize the access to master pointer. More...
 
virtual const MultiDimAdressablegetMasterRef () const
 In order to insure the dereference for decorators, we need to virtualize the access to master pointer. More...
 
virtual void copy (const MultiDimContainer< GUM_SCALAR > &src)
 Removes all variables in this MultiDimContainer and copy the content of src, variables included. More...
 
Various methods.
bool operator== (const MultiDimContainer< GUM_SCALAR > &p) const
 Test if this MultiDimContainer is equal to p. More...
 
bool operator!= (const MultiDimContainer< GUM_SCALAR > &p) const
 Test if this MultiDimContainer is different of p. More...
 
Accessors / Modifiers
void replace (const DiscreteVariable &x, const DiscreteVariable &y)
 Replace variables in this multidim. More...
 

Protected Attributes

MultiDimImplementation< GUM_SCALAR > * _content
 The true container. More...
 
GUM_SCALAR _empty_value
 value of the MultiDimDecorator if no dimension. More...
 

Protected Member Functions

Set< const DiscreteVariable *> _complementVars (const Set< const DiscreteVariable * > &del_vars) const
 
virtual void _replace (const DiscreteVariable *x, const DiscreteVariable *y)
 This is called by MultiDimContainer::replace() to proceed with the replacing between x and y. More...
 
void _swapContent (MultiDimImplementation< GUM_SCALAR > *aContent) const
 protecte method to swap the implementation behind the Potential More...
 
GUM_SCALAR & _get (const Instantiation &i) const final
 Return a data, given a Insantiation - final method. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::Potential< GUM_SCALAR >

aGrUM's Potential is a multi-dimensional array with tensor operators.

It is used to represent probabilities and utilities in aGrUMs' multidimensional (graphical) models.

Using the decorator pattern, this representation is independent from the implementation of the multidimensional matrix.

Template Parameters
GUM_SCALARThe type of the scalar stored in this multidimensional matrix.

Definition at line 57 of file potential.h.

Constructor & Destructor Documentation

◆ Potential() [1/5]

template<typename GUM_SCALAR >
INLINE gum::Potential< GUM_SCALAR >::Potential ( )

Default constructor.

Creates an empty null dimensional matrix with a MultiDimArray as its implementation.

Definition at line 35 of file potential_tpl.h.

35  :
36  MultiDimDecorator< GUM_SCALAR >(new MultiDimArray< GUM_SCALAR >(),
37  GUM_SCALAR(1)) {
38  GUM_CONSTRUCTOR(Potential);
39  }
Potential()
Default constructor.
Definition: potential_tpl.h:35

◆ Potential() [2/5]

template<typename GUM_SCALAR >
INLINE gum::Potential< GUM_SCALAR >::Potential ( MultiDimImplementation< GUM_SCALAR > *  aContent)

Creates an potential around aContent.

Parameters
aContentThe implementation of this Potential.

Definition at line 43 of file potential_tpl.h.

44  :
45  MultiDimDecorator< GUM_SCALAR >(aContent, GUM_SCALAR(1)) {
46  // for debugging purposes
47  GUM_CONSTRUCTOR(Potential);
48  }
Potential()
Default constructor.
Definition: potential_tpl.h:35

◆ Potential() [3/5]

template<typename GUM_SCALAR >
gum::Potential< GUM_SCALAR >::Potential ( MultiDimImplementation< GUM_SCALAR > *  aContent,
const MultiDimContainer< GUM_SCALAR > &  src 
)

Copy constructor.

The newly created Potential share the variables and the values from src, but no instantiation is associated to it. It allows to force the chosen implementation and to copy the data from src.

Parameters
aContentThe implementation to use in this Potential.
srcThe MultiDimContainer to copy.

Definition at line 71 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::MultiDimDecorator< GUM_SCALAR >::beginMultipleChanges(), gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimContainer< GUM_SCALAR >::content(), gum::MultiDimInterface::empty(), gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges(), gum::Potential< GUM_SCALAR >::operator=(), and gum::MultiDimInterface::variablesSequence().

73  :
74  MultiDimDecorator< GUM_SCALAR >(aContent) {
75  // for debugging purposes
76  GUM_CONSTRUCTOR(Potential);
77 
78  if (!src.empty()) {
79  this->beginMultipleChanges();
80 
81  for (Idx i = 0; i < src.variablesSequence().size(); i++) {
82  this->add(*(src.variablesSequence()[i]));
83  }
84 
85  this->endMultipleChanges();
86  this->content()->copyFrom(*src.content());
87  }
88  }
virtual void beginMultipleChanges() final
Default implementation of MultiDimContainer::set().
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
virtual void endMultipleChanges() final
Default implementation of MultiDimContainer::set().
virtual void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
Potential()
Default constructor.
Definition: potential_tpl.h:35
+ Here is the call graph for this function:

◆ Potential() [4/5]

template<typename GUM_SCALAR >
INLINE gum::Potential< GUM_SCALAR >::Potential ( const Potential< GUM_SCALAR > &  src)

Copy constructor & assignment.

Definition at line 51 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_empty_value.

51  :
52  Potential< GUM_SCALAR >(static_cast< MultiDimImplementation< GUM_SCALAR >* >(
53  src.content()->newFactory()),
54  *(src.content())) {
55  this->_empty_value = src._empty_value;
56  // todo how to optimize copy of content ?
57  // GUM_CONS_CPY not here because in called Potential
58  // GUM_CONS_CPY( Potential );
59  }
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.

◆ Potential() [5/5]

template<typename GUM_SCALAR >
INLINE gum::Potential< GUM_SCALAR >::Potential ( Potential< GUM_SCALAR > &&  from)

move constructor & assignement

move constructor

Definition at line 63 of file potential_tpl.h.

63  :
64  MultiDimDecorator< GUM_SCALAR >(
65  std::forward< MultiDimDecorator< GUM_SCALAR > >(from)) {
66  GUM_CONS_MOV(Potential);
67  }
Potential()
Default constructor.
Definition: potential_tpl.h:35

◆ ~Potential()

template<typename GUM_SCALAR >
gum::Potential< GUM_SCALAR >::~Potential ( )

Destructor.

Definition at line 112 of file potential_tpl.h.

112  {
113  // for debugging purposes
114  GUM_DESTRUCTOR(Potential);
115  }
Potential()
Default constructor.
Definition: potential_tpl.h:35

Member Function Documentation

◆ _complementVars()

template<typename GUM_SCALAR >
Set< const DiscreteVariable *> gum::Potential< GUM_SCALAR >::_complementVars ( const Set< const DiscreteVariable * > &  del_vars) const
protected

Definition at line 499 of file potential_tpl.h.

References gum::Set< Key, Alloc >::contains(), gum::Set< Key, Alloc >::insert(), and gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence().

Referenced by gum::Potential< GUM_SCALAR >::margMaxIn(), gum::Potential< GUM_SCALAR >::margMinIn(), gum::Potential< GUM_SCALAR >::margProdIn(), gum::Potential< GUM_SCALAR >::margSumIn(), and gum::Potential< GUM_SCALAR >::toString().

500  {
501  Set< const DiscreteVariable* > cplt;
502 
503  for (const auto x : this->variablesSequence())
504  if (!vars.contains(x)) cplt.insert(x);
505 
506  return cplt;
507  }
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns a const ref to the sequence of DiscreteVariable*.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _get()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR & gum::MultiDimDecorator< GUM_SCALAR >::_get ( const Instantiation i) const
finalprotectedvirtualinherited

Return a data, given a Insantiation - final method.

Parameters
iThe instantiation.
Exceptions
NullElement
NotFound

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 139 of file multiDimDecorator_tpl.h.

References GUM_ERROR.

139  {
140  GUM_ERROR(OperationNotAllowed, "_get in the implementation !");
141  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52

◆ _replace()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::_replace ( const DiscreteVariable x,
const DiscreteVariable y 
)
protectedvirtualinherited

This is called by MultiDimContainer::replace() to proceed with the replacing between x and y.

This is called only when everything have been checked.

Parameters
xThe variable to replace in
yThe second variable to swap.

Implements gum::MultiDimInterface.

Definition at line 413 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::content().

414  {
415  this->content()->replace(*x, *y);
416  }
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
+ Here is the call graph for this function:

◆ _swapContent()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::_swapContent ( MultiDimImplementation< GUM_SCALAR > *  aContent) const
protectedinherited

protecte method to swap the implementation behind the Potential

Warning
unsafe method for slave Instantiations !

Definition at line 390 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

391  {
392  if (aContent != nullptr) {
393  // TODO : frees all slave instantiations
394  // TODO : control the dimensions ?
395  MultiDimImplementation< GUM_SCALAR >* tmp = _content;
396  _content = aContent;
397  // registers all instantiations
398  delete (tmp);
399  }
400  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.

◆ abs()

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::abs ( ) const

Apply abs on every element of the container.

Definition at line 338 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::apply().

338  {
339  this->apply([](GUM_SCALAR x) {
340  if (x >= 0)
341  return x;
342  else
343  return -x;
344  });
345  return *this;
346  }
virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const final
Apply a function on every element of the container.
+ Here is the call graph for this function:

◆ add()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::add ( const DiscreteVariable v)
finalvirtualinherited

Adds a new var to the variables of the multidimensional matrix.

See also
operator<<(MultiDimInterface& c, const DiscreteVariable& v)
Warning
Note that the variable passed in argument is not duplicated, that is, only a pointer toward the variable is kept by the MultiDimInterface.
Parameters
vThe new var.
Exceptions
DuplicateElementRaised if the variable already belongs to the sequence of variables.
OperationNotAllowedRaised if this object is non mutable.

Implements gum::MultiDimInterface.

Definition at line 173 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::DiscreteVariable::domainSize(), and GUM_ERROR.

Referenced by gum::prm::gspan::StrictSearch< GUM_SCALAR >::__elimination_cost(), gum::prm::PRMSystem< double >::__groundPotential(), gum::prm::GroundedInference< GUM_SCALAR >::_evidenceAdded(), gum::prm::PRMInference< double >::addEvidence(), gum::BayesNetInference< GUM_SCALAR >::addEvidence(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::prm::copyPotential(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::prm::PRMInference< double >::joint(), gum::prm::PRMInference< double >::marginal(), gum::prm::PRMInference< double >::operator=(), gum::Potential< GUM_SCALAR >::Potential(), gum::prm::PRMInference< double >::PRMInference(), and gum::Potential< GUM_SCALAR >::reorganize().

173  {
174  if (v.domainSize() < 1) {
175  GUM_ERROR(InvalidArgument,
176  "Empty variable " << v << " cannot be added in a Potential");
177  }
178  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->add(v);
179  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ apply()

template<typename GUM_SCALAR >
void gum::MultiDimDecorator< GUM_SCALAR >::apply ( std::function< GUM_SCALAR(GUM_SCALAR) >  f) const
finalvirtualinherited

Apply a function on every element of the container.

Parameters
fthe function to apply

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 336 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, and gum::MultiDimDecorator< GUM_SCALAR >::empty().

Referenced by gum::Potential< GUM_SCALAR >::abs(), gum::Potential< GUM_SCALAR >::isNonZeroMap(), gum::Potential< GUM_SCALAR >::normalize(), gum::Potential< GUM_SCALAR >::operator-(), gum::Potential< GUM_SCALAR >::operator/(), gum::Potential< GUM_SCALAR >::scale(), gum::Potential< GUM_SCALAR >::sq(), and gum::Potential< GUM_SCALAR >::translate().

337  {
338  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->empty()) {
340  } else {
341  _content->apply(f);
342  }
343  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ argmax()

template<typename GUM_SCALAR >
INLINE Set< Instantiation > gum::Potential< GUM_SCALAR >::argmax ( ) const

set of instantiation corresponding to the max in the Potential

Definition at line 595 of file potential_tpl.h.

References gum::Potential< GUM_SCALAR >::findAll(), and gum::Potential< GUM_SCALAR >::max().

595  {
596  return findAll(max());
597  }
Set< Instantiation > findAll(GUM_SCALAR v) const
set of instantiation corresponding to the parameter v in the Potential
GUM_SCALAR max() const
max of all elements in the Potential
+ Here is the call graph for this function:

◆ argmin()

template<typename GUM_SCALAR >
INLINE Set< Instantiation > gum::Potential< GUM_SCALAR >::argmin ( ) const

set of instantiation corresponding to the min in the Potential

Definition at line 600 of file potential_tpl.h.

References gum::Potential< GUM_SCALAR >::findAll(), and gum::Potential< GUM_SCALAR >::min().

600  {
601  return findAll(min());
602  }
GUM_SCALAR min() const
min of all elements in the Potential
Set< Instantiation > findAll(GUM_SCALAR v) const
set of instantiation corresponding to the parameter v in the Potential
+ Here is the call graph for this function:

◆ beginMultipleChanges()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::beginMultipleChanges ( )
finalvirtualinherited

Default implementation of MultiDimContainer::set().

Calls _get as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 371 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::BayesNet< double >::__copyPotentials(), gum::BayesNetInference< GUM_SCALAR >::__createHardEvidence(), gum::Potential< GUM_SCALAR >::Potential(), and gum::Potential< GUM_SCALAR >::reorganize().

371  {
372  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)
374  }
virtual void beginMultipleChanges() final
Default implementation of MultiDimContainer::set().
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
+ Here is the caller graph for this function:

◆ changeNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::changeNotification ( const Instantiation i,
const DiscreteVariable *const  var,
Idx  oldval,
Idx  newval 
)
finalvirtualinherited

Listen to changes in a given Instantiation.

Parameters
iThe Instantiation to listen.
varThe changed dim.
oldvalThe old value.
newvalThe changed value.

Implements gum::MultiDimAdressable.

Definition at line 184 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

188  {
189  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->changeNotification(
190  i, var, oldval, newval);
191  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void changeNotification(const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval) final
Listen to changes in a given Instantiation.

◆ contains()

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimDecorator< GUM_SCALAR >::contains ( const DiscreteVariable v) const
finalvirtualinherited

Returns true if var is in *this.

Parameters
vA DiscreteVariable.
Returns
Returns true if var is in *this.

Implements gum::MultiDimInterface.

Definition at line 272 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::prm::PRMInference< double >::addEvidence(), gum::Potential< GUM_SCALAR >::KL(), gum::Potential< GUM_SCALAR >::putFirst(), and gum::Potential< GUM_SCALAR >::reorganize().

272  {
273  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->contains(d);
274  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual bool contains(const DiscreteVariable &var) const final
Returns true if var is in *this.
+ Here is the caller graph for this function:

◆ content() [1/2]

template<typename GUM_SCALAR >
INLINE const MultiDimImplementation< GUM_SCALAR > * gum::MultiDimDecorator< GUM_SCALAR >::content ( ) const
finalvirtualinherited

Returns the implementation for this object (may be *this).

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 366 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::MultiDimDecorator< GUM_SCALAR >::_replace(), gum::prm::copyPotential(), gum::Potential< GUM_SCALAR >::margMaxIn(), gum::Potential< GUM_SCALAR >::margMaxOut(), gum::Potential< GUM_SCALAR >::margMinIn(), gum::Potential< GUM_SCALAR >::margMinOut(), gum::Potential< GUM_SCALAR >::margProdIn(), gum::Potential< GUM_SCALAR >::margProdOut(), gum::Potential< GUM_SCALAR >::margSumIn(), gum::Potential< GUM_SCALAR >::margSumOut(), gum::Potential< GUM_SCALAR >::max(), gum::Potential< GUM_SCALAR >::min(), gum::MultiDimDecorator< GUM_SCALAR >::MultiDimDecorator(), gum::Potential< GUM_SCALAR >::newFactory(), gum::Potential< GUM_SCALAR >::operator*(), gum::Potential< GUM_SCALAR >::operator+(), gum::Potential< GUM_SCALAR >::operator-(), gum::Potential< GUM_SCALAR >::operator/(), gum::MultiDimDecorator< GUM_SCALAR >::operator=(), gum::Potential< GUM_SCALAR >::Potential(), gum::Potential< GUM_SCALAR >::product(), and gum::Potential< GUM_SCALAR >::sum().

366  {
367  return _content;
368  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
+ Here is the caller graph for this function:

◆ content() [2/2]

template<typename GUM_SCALAR >
INLINE MultiDimImplementation< GUM_SCALAR > * gum::MultiDimDecorator< GUM_SCALAR >::content ( )
finalvirtualinherited

Returns the implementation for this object (may be *this).

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 359 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

359  {
360  return _content;
361  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.

◆ copy()

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::copy ( const MultiDimContainer< GUM_SCALAR > &  src)
virtualinherited

Removes all variables in this MultiDimContainer and copy the content of src, variables included.

Parameters
srcThe MultiDimContainer to copy.

Reimplemented in gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >, gum::MultiDimFunctionGraph< GUM_SCALAR >, and gum::MultiDimFunctionGraph< GUM_SCALAR, ExactTerminalNodePolicy >.

Definition at line 279 of file multiDimContainer_tpl.h.

References gum::MultiDimInterface::add(), gum::MultiDimContainer< GUM_SCALAR >::beginMultipleChanges(), gum::MultiDimContainer< GUM_SCALAR >::copyFrom(), gum::MultiDimContainer< GUM_SCALAR >::endMultipleChanges(), gum::MultiDimInterface::erase(), gum::MultiDimInterface::nbrDim(), and gum::MultiDimInterface::variable().

Referenced by gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__eraseArc(), and gum::MCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::disturbBN().

280  {
281  this->beginMultipleChanges();
282 
283  Size nbr = this->nbrDim();
284 
285  for (Idx i = 0; i < nbr; i++) {
286  this->erase(this->variable(0));
287  }
288 
289  for (Idx i = 0; i < src.nbrDim(); i++) {
290  this->add(src.variable(i));
291  }
292 
293  this->endMultipleChanges();
294  this->copyFrom(src);
295  }
virtual void endMultipleChanges()=0
Call this method after doing important changes in this MultiDimContainer.
virtual void add(const DiscreteVariable &v)=0
Adds a new var to the variables of the multidimensional matrix.
virtual Idx nbrDim() const =0
Returns the number of vars in the multidimensional container.
virtual const DiscreteVariable & variable(Idx i) const =0
Returns a const ref to the ith var.
virtual void beginMultipleChanges()=0
Call this method before doing important changes in this MultiDimContainer.
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src) const
Basic copy of a MultiDimContainer.
virtual void erase(const DiscreteVariable &v)=0
Removes a var from the variables of the multidimensional matrix.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copyFrom() [1/2]

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::copyFrom ( const MultiDimContainer< GUM_SCALAR > &  src) const
virtualinherited

Basic copy of a MultiDimContainer.

This method is virtual because it should be optimized in certain MultiDimContainer.

Parameters
srcThe MultiDimContainer src which values are copied. This is a full copy with no verification of dimensions.
Exceptions
OperationNotAllowedRaised if src does not have the same domain size than this MultiDimContainer.

Reimplemented in gum::aggregator::MultiDimAggregator< GUM_SCALAR >, gum::MultiDimICIModel< GUM_SCALAR >, and gum::MultiDimArray< GUM_SCALAR >.

Definition at line 262 of file multiDimContainer_tpl.h.

References gum::MultiDimInterface::domainSize(), gum::Instantiation::end(), GUM_ERROR, and gum::Instantiation::setFirst().

Referenced by gum::BayesNet< double >::__copyPotentials(), gum::MultiDimContainer< GUM_SCALAR >::copy(), gum::MultiDimArray< GUM_SCALAR >::copyFrom(), gum::MultiDimICIModel< GUM_SCALAR >::copyFrom(), gum::aggregator::MultiDimAggregator< GUM_SCALAR >::copyFrom(), and gum::Potential< GUM_SCALAR >::reorganize().

263  {
264  if (src.domainSize() != domainSize()) {
265  GUM_ERROR(OperationNotAllowed, "Domain sizes do not fit");
266  }
267 
268  Instantiation i_dest(*this);
269  Instantiation i_src(src);
270 
271  for (i_dest.setFirst(), i_src.setFirst(); !i_dest.end(); ++i_dest, ++i_src) {
272  set(i_dest, src[i_src]);
273  }
274  }
virtual Size domainSize() const =0
Returns the product of the variables domain size.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copyFrom() [2/2]

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::copyFrom ( const MultiDimContainer< GUM_SCALAR > &  src,
Instantiation p_i 
) const
virtualinherited

Basic copy of a MultiDimContainer.

This method is virtual because it should be optimized in certain MultiDimContainer.

Parameters
srcThe MultiDimContainer src which values are copied.
p_iGive the order to iterate in this MultiDimContainer during the copy (nullptr will correctly copy if this is a reorganization of src).
Exceptions
OperationNotAllowedRaised if src does not have the same domain size than this MultiDimContainer.

Reimplemented in gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >, gum::MultiDimFunctionGraph< GUM_SCALAR >, and gum::MultiDimFunctionGraph< GUM_SCALAR, ExactTerminalNodePolicy >.

Definition at line 215 of file multiDimContainer_tpl.h.

References gum::MultiDimInterface::domainSize(), gum::Instantiation::end(), GUM_ERROR, gum::Instantiation::incIn(), and gum::Instantiation::setFirst().

216  {
217  if (src.domainSize() != domainSize()) {
218  GUM_ERROR(OperationNotAllowed, "Domain sizes do not fit");
219  }
220 
221  if (p_i == nullptr) { // if null, we just follow the same order
222  Instantiation i(src);
223  for (i.setFirst(); !i.end(); ++i) {
224  set(i, src[i]);
225  }
226  } else {
227  Instantiation i_dest(*this);
228  Instantiation i_src(src);
229  for (i_dest.setFirst(), i_src.setFirst(); !i_dest.end();
230  i_dest.incIn(*p_i), ++i_src) {
231  set(i_dest, src[i_src]);
232  }
233  }
234  }
virtual Size domainSize() const =0
Returns the product of the variables domain size.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ domainSize()

template<typename GUM_SCALAR >
INLINE Size gum::MultiDimDecorator< GUM_SCALAR >::domainSize ( ) const
finalvirtualinherited

Returns the product of the variables domain size.

Returns
Returns the product of the variables domain size.

Implements gum::MultiDimInterface.

Definition at line 166 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::prm::gspan::StrictSearch< GUM_SCALAR >::__elimination_cost(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__verticesSampling(), gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), gum::Potential< GUM_SCALAR >::fillWith(), gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT(), gum::SimpleUTGenerator::generateUT(), and gum::credal::CredalNet< GUM_SCALAR >::toString().

166  {
167  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->domainSize();
168  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual Size domainSize() const final
Returns the product of the variables domain size.
+ Here is the caller graph for this function:

◆ draw()

template<typename GUM_SCALAR >
Idx gum::Potential< GUM_SCALAR >::draw ( ) const

get a value at random from a 1-D distribution

Definition at line 558 of file potential_tpl.h.

References gum::DiscreteVariable::domainSize(), gum::Instantiation::end(), GUM_ERROR, gum::Instantiation::inc(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), gum::randomProba(), gum::Instantiation::setFirst(), gum::Instantiation::val(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

Referenced by gum::GibbsOperator< GUM_SCALAR >::__GibbsSample().

558  {
559  if (this->nbrDim() != 1) {
560  GUM_ERROR(FatalError, "To draw from a potential, the dimension must be 1")
561  }
562 
563  GUM_SCALAR r = static_cast< GUM_SCALAR >(randomProba());
564  Instantiation Ip(*this);
565  for (Ip.setFirst(); !Ip.end(); Ip.inc()) {
566  r -= this->get(Ip);
567  if (r <= 0) return Ip.val(0);
568  }
569  return this->variable(0).domainSize() - 1;
570  }
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
double randomProba()
Returns a random double between 0 and 1 included (i.e.
virtual Size domainSize() const =0
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ empty()

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimDecorator< GUM_SCALAR >::empty ( ) const
finalvirtualinherited

Returns true if no var is in *this.

Returns
Returns true if no var is in *this.

Implements gum::MultiDimInterface.

Definition at line 277 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::MultiDimDecorator< GUM_SCALAR >::apply(), gum::Potential< GUM_SCALAR >::entropy(), gum::MultiDimDecorator< GUM_SCALAR >::fill(), gum::Potential< GUM_SCALAR >::findAll(), gum::MultiDimDecorator< GUM_SCALAR >::get(), gum::Potential< GUM_SCALAR >::margMaxIn(), gum::Potential< GUM_SCALAR >::margMaxOut(), gum::Potential< GUM_SCALAR >::margMinIn(), gum::Potential< GUM_SCALAR >::margMinOut(), gum::Potential< GUM_SCALAR >::margProdIn(), gum::Potential< GUM_SCALAR >::margProdOut(), gum::Potential< GUM_SCALAR >::margSumIn(), gum::Potential< GUM_SCALAR >::margSumOut(), gum::Potential< GUM_SCALAR >::max(), gum::Potential< GUM_SCALAR >::maxNonOne(), gum::Potential< GUM_SCALAR >::min(), gum::Potential< GUM_SCALAR >::minNonZero(), gum::Potential< GUM_SCALAR >::normalize(), gum::Potential< GUM_SCALAR >::normalizeAsCPT(), gum::Potential< GUM_SCALAR >::operator*(), gum::Potential< GUM_SCALAR >::operator+(), gum::Potential< GUM_SCALAR >::operator-(), gum::Potential< GUM_SCALAR >::operator/(), gum::Potential< GUM_SCALAR >::operator==(), gum::MultiDimDecorator< GUM_SCALAR >::populate(), gum::Potential< GUM_SCALAR >::product(), gum::MultiDimDecorator< GUM_SCALAR >::reduce(), gum::Potential< GUM_SCALAR >::sum(), and gum::MultiDimDecorator< GUM_SCALAR >::toString().

277  {
278  if (_content == nullptr) return true;
279  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->empty();
280  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
+ Here is the caller graph for this function:

◆ endMultipleChanges() [1/2]

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges ( )
finalvirtualinherited

Default implementation of MultiDimContainer::set().

Calls _get as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 377 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::BayesNet< double >::__copyPotentials(), gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges(), gum::Potential< GUM_SCALAR >::Potential(), and gum::Potential< GUM_SCALAR >::reorganize().

377  {
378  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)
379  ->endMultipleChanges();
380  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void endMultipleChanges() final
Default implementation of MultiDimContainer::set().
+ Here is the caller graph for this function:

◆ endMultipleChanges() [2/2]

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges ( const GUM_SCALAR &  x)
finalvirtualinherited

Default implementation of MultiDimContainer::set().

Calls _get as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 384 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, and gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges().

384  {
385  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->endMultipleChanges(
386  x);
387  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void endMultipleChanges() final
Default implementation of MultiDimContainer::set().
+ Here is the call graph for this function:

◆ entropy()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::Potential< GUM_SCALAR >::entropy ( ) const

entropy of the Potential

Definition at line 205 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::MultiDimDecorator< GUM_SCALAR >::reduce().

205  {
206  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
207  return static_cast< GUM_SCALAR >(0);
208  }
209 
210  return this->reduce(
211  [](GUM_SCALAR z, GUM_SCALAR p) {
212  return (p == 0.0) ? z : (z - p * log2(p));
213  },
214  0.0);
215  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
virtual GUM_SCALAR reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const final
compute lfold for this container
+ Here is the call graph for this function:

◆ erase()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::erase ( const DiscreteVariable v)
finalvirtualinherited

Removes a var from the variables of the multidimensional matrix.

See also
operator>>(MultiDimInterface& c, const DiscreteVariable& v)
Exceptions
OperationNotAllowedRaised if this object is non mutable.
NotFoundRaised if v does not belong to this.

Implements gum::MultiDimInterface.

Definition at line 247 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::prm::gspan::StrictSearch< GUM_SCALAR >::__elimination_cost(), gum::prm::StructuredInference< GUM_SCALAR >::__removeBarrenNodes(), gum::prm::GroundedInference< GUM_SCALAR >::_evidenceRemoved(), and gum::prm::eliminateNode().

247  {
248  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->erase(d);
249  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void erase(const DiscreteVariable &var) final
Removes a var from the variables of the multidimensional matrix.
+ Here is the caller graph for this function:

◆ extract()

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::extract ( const Instantiation inst) const

create a new Potential extracted from *this given a partial instantiation

Definition at line 550 of file potential_tpl.h.

References gum::MultiDimContainer< GUM_SCALAR >::extractFrom().

550  {
551  Potential< GUM_SCALAR > p;
552  p.extractFrom(*this, inst);
553 
554  return p;
555  }
+ Here is the call graph for this function:

◆ extractFrom()

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::extractFrom ( const MultiDimContainer< GUM_SCALAR > &  src,
const Instantiation mask 
)
virtualinherited

Basic extraction of a MultiDimContainer.

This method is virtual because it should be optimized in certain MultiDimContainer.

Parameters
srcThe MultiDimContainer src which datas are copied.
maskpartial instantiation of variables of the Potential : the extraction will concern every variable not in the instantiation and the copy of data will use the values in this instantiation.

Definition at line 237 of file multiDimContainer_tpl.h.

References gum::MultiDimInterface::add(), gum::MultiDimContainer< GUM_SCALAR >::beginMultipleChanges(), gum::Instantiation::contains(), gum::Instantiation::end(), gum::MultiDimContainer< GUM_SCALAR >::endMultipleChanges(), gum::MultiDimInterface::erase(), GUM_ERROR, gum::Instantiation::incOut(), gum::MultiDimInterface::nbrDim(), gum::Instantiation::setFirstOut(), gum::Instantiation::setVals(), and gum::MultiDimInterface::variable().

Referenced by gum::Potential< GUM_SCALAR >::extract().

238  {
239  this->beginMultipleChanges();
240 
241  Size nbr = this->nbrDim();
242 
243  for (Idx i = 0; i < nbr; i++) {
244  this->erase(this->variable(0));
245  }
246 
247  for (Idx i = 0; i < src.nbrDim(); i++) {
248  if (!imask.contains(src.variable(i))) this->add(src.variable(i));
249  }
250 
251  if (this->nbrDim() == 0) { GUM_ERROR(FatalError, "Empty potential"); }
252 
253  this->endMultipleChanges();
254 
255  Instantiation inst(src);
256  inst.setVals(imask);
257  for (inst.setFirstOut(imask); !inst.end(); inst.incOut(imask))
258  set(inst, src[inst]);
259  }
virtual void endMultipleChanges()=0
Call this method after doing important changes in this MultiDimContainer.
virtual void add(const DiscreteVariable &v)=0
Adds a new var to the variables of the multidimensional matrix.
virtual Idx nbrDim() const =0
Returns the number of vars in the multidimensional container.
virtual const DiscreteVariable & variable(Idx i) const =0
Returns a const ref to the ith var.
virtual void beginMultipleChanges()=0
Call this method before doing important changes in this MultiDimContainer.
virtual void erase(const DiscreteVariable &v)=0
Removes a var from the variables of the multidimensional matrix.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fill()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::fill ( const GUM_SCALAR &  d) const
finalvirtualinherited

Default implementation of MultiDimContainer::set().

Calls _get as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 289 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, and gum::MultiDimDecorator< GUM_SCALAR >::empty().

Referenced by gum::Potential< GUM_SCALAR >::fillWith().

289  {
290  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->empty()) {
291  _empty_value = d;
292  } else {
293  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->fill(d);
294  }
295  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual void fill(const GUM_SCALAR &d) const final
Default implementation of MultiDimContainer::set().
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fillWith() [1/4]

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::fillWith ( const Potential< GUM_SCALAR > &  src) const

copy a Potential data using name of variables and labels (not necessarily the same variables in the same orders)

Warning
a strict control on names of variables and labels are made
Exceptions
InvalidArgumentif the Potential is not compatible with this

Definition at line 233 of file potential_tpl.h.

References gum::Instantiation::chgVal(), gum::Set< Key, Alloc >::contains(), gum::MultiDimDecorator< GUM_SCALAR >::domainSize(), gum::MultiDimDecorator< GUM_SCALAR >::get(), GUM_ERROR, gum::Set< Key, Alloc >::insert(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), gum::Potential< GUM_SCALAR >::toString(), gum::MultiDimDecorator< GUM_SCALAR >::variable(), and gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence().

Referenced by gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__insertEvidence(), gum::credal::CNMonteCarloSampling< GUM_SCALAR, BNInferenceEngine >::__verticesSampling(), gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT(), gum::Potential< GUM_SCALAR >::margMaxIn(), gum::Potential< GUM_SCALAR >::margMaxOut(), gum::Potential< GUM_SCALAR >::margMinIn(), gum::Potential< GUM_SCALAR >::margMinOut(), gum::Potential< GUM_SCALAR >::margProdIn(), gum::Potential< GUM_SCALAR >::margProdOut(), gum::Potential< GUM_SCALAR >::margSumIn(), gum::Potential< GUM_SCALAR >::margSumOut(), and gum::Estimator< GUM_SCALAR >::posterior().

233  {
234  if (src.domainSize() != this->domainSize()) {
235  GUM_ERROR(InvalidArgument, "Potential to copy has not the same dimension.");
236  }
237  gum::Set< std::string > son; // set of names
238  for (const auto& v : src.variablesSequence()) {
239  son.insert(v->name());
240  }
241  for (const auto& v : this->variablesSequence()) {
242  if (!son.contains(v->name())) {
243  GUM_ERROR(InvalidArgument,
244  "Variable <" << v->name() << "> not present in src.");
245  }
246  // we check size, labels and order of labels in the same time
247  if (v->toString() != src.variable(v->name()).toString()) {
248  GUM_ERROR(InvalidArgument,
249  "Variables <" << v->name() << "> are not identical.");
250  }
251  }
252 
253  Instantiation Isrc(src);
254  Instantiation Idst(*this);
255  for (Isrc.setFirst(); !Isrc.end(); ++Isrc) {
256  for (Idx i = 0; i < this->nbrDim(); i++) {
257  Idst.chgVal(Isrc.variable(i).name(), Isrc.val(i));
258  }
259  this->set(Idst, src.get(Isrc));
260  }
261 
262  return *this;
263  }
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
Definition: set_tpl.h:578
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
virtual Size domainSize() const final
Returns the product of the variables domain size.
virtual const std::string toString() const
the function to be used to add two Potentials
Definition: potential.h:418
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns a const ref to the sequence of DiscreteVariable*.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fillWith() [2/4]

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::fillWith ( const Potential< GUM_SCALAR > &  src,
const std::vector< std::string > &  mapSrc 
) const

copy a Potential data using the sequence of names in mapSrc to find the corresponding variables.

For instance, to copy the potential P(A,B,C) in Q(D,E,A) with the mapping P.A<->Q.E, P.B<->Q.A, P.C<->Q.D (assuming that the corresponding variables have the same domain size and the order of labels):

Q.fillWith(P,{"C","A","B"});
Warning
a strict control on names of variables and labels are made
Exceptions
InvalidArgumentif the Potential is not compatible with this

Definition at line 266 of file potential_tpl.h.

References gum::Instantiation::add(), gum::DiscreteVariable::domainSize(), gum::Instantiation::end(), gum::MultiDimDecorator< GUM_SCALAR >::get(), GUM_ERROR, gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), gum::Instantiation::setFirst(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

268  {
269  if (src.nbrDim() != this->nbrDim()) {
270  GUM_ERROR(InvalidArgument, "Potential to copy has not the same dimension.");
271  }
272  if (src.nbrDim() != mapSrc.size()) {
273  GUM_ERROR(InvalidArgument,
274  "Potential and vector have not the same dimension.");
275  }
276  Instantiation Isrc;
277  for (Idx i = 0; i < src.nbrDim(); i++) {
278  if (src.variable(mapSrc[i]).domainSize() != this->variable(i).domainSize()) {
279  GUM_ERROR(InvalidArgument,
280  "Variables " << mapSrc[i] << " (in the argument) and "
281  << this->variable(i).name()
282  << " have not the same dimension.");
283  } else {
284  Isrc.add(src.variable(mapSrc[i]));
285  }
286  }
287  Instantiation Idst(*this);
288  for (Isrc.setFirst(); !Isrc.end(); ++Isrc, ++Idst) {
289  this->set(Idst, src.get(Isrc));
290  }
291 
292  return *this;
293  }
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
virtual Size domainSize() const =0
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ fillWith() [3/4]

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::fillWith ( const std::vector< GUM_SCALAR > &  v) const

Automatically fills the potential with the values in v.

Parameters
vVector of values.
Exceptions
SizeErrorRaised if v size's does not matches this MultiDimContainer domain size.

Definition at line 219 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::populate().

219  {
220  this->populate(v);
221  return *this;
222  }
virtual void populate(const std::vector< GUM_SCALAR > &v) const final
Automatically fills this MultiDimContainer with the values in v.
+ Here is the call graph for this function:

◆ fillWith() [4/4]

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::fillWith ( const GUM_SCALAR &  v) const

Automatically fills this MultiDimContainer with the value v.

Parameters
vcontains the data.

Definition at line 226 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::fill().

226  {
227  this->fill(v);
228  return *this;
229  }
virtual void fill(const GUM_SCALAR &d) const final
Default implementation of MultiDimContainer::set().
+ Here is the call graph for this function:

◆ findAll()

template<typename GUM_SCALAR >
Set< Instantiation > gum::Potential< GUM_SCALAR >::findAll ( GUM_SCALAR  v) const

set of instantiation corresponding to the parameter v in the Potential

Definition at line 581 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Instantiation::end(), gum::Set< Key, Alloc >::insert(), and gum::Instantiation::setFirst().

Referenced by gum::Potential< GUM_SCALAR >::argmax(), and gum::Potential< GUM_SCALAR >::argmin().

581  {
582  Instantiation I(*this);
583  Set< Instantiation > res;
584 
585  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
586  return res;
587  }
588  for (I.setFirst(); !I.end(); ++I) {
589  if (this->get(I) == v) res.insert(I);
590  }
591  return res;
592  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::MultiDimDecorator< GUM_SCALAR >::get ( const Instantiation i) const
finalvirtualinherited

Default implementation of MultiDimContainer::get().

Calls _get as a l-value.

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 145 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, and gum::MultiDimDecorator< GUM_SCALAR >::empty().

Referenced by gum::prm::StructuredBayesBall< GUM_SCALAR >::__isHardEvidence(), gum::prm::GroundedInference< GUM_SCALAR >::_evidenceAdded(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::prm::PRMInference< double >::addEvidence(), gum::credal::CredalNet< GUM_SCALAR >::bnToCredal(), gum::SimpleCPTDisturber< GUM_SCALAR >::disturbAugmCPT(), gum::SimpleCPTDisturber< GUM_SCALAR >::disturbReducCPT(), gum::Potential< GUM_SCALAR >::fillWith(), gum::Potential< GUM_SCALAR >::KL(), gum::prm::PRMInference< double >::marginal(), and gum::prm::o3prmr::O3prmrInterpreter::query().

145  {
146  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->empty()) {
147  return _empty_value;
148  } else {
149  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->get(i);
150  }
151  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMasterRef() [1/2]

template<typename GUM_SCALAR >
INLINE MultiDimAdressable & gum::MultiDimContainer< GUM_SCALAR >::getMasterRef ( )
virtualinherited

In order to insure the dereference for decorators, we need to virtualize the access to master pointer.

Returns
Returns the ref to content as MultiDimAdressable&

Implements gum::MultiDimAdressable.

Reimplemented in gum::MultiDimBucket< GUM_SCALAR >.

Definition at line 298 of file multiDimContainer_tpl.h.

References gum::MultiDimContainer< GUM_SCALAR >::content().

298  {
299  return static_cast< MultiDimAdressable& >(*content());
300  }
virtual const MultiDimImplementation< GUM_SCALAR > * content() const =0
Returns the implementation for this object (may be *this).
MultiDimAdressable()
Default constructor.
+ Here is the call graph for this function:

◆ getMasterRef() [2/2]

template<typename GUM_SCALAR >
INLINE const MultiDimAdressable & gum::MultiDimContainer< GUM_SCALAR >::getMasterRef ( ) const
virtualinherited

In order to insure the dereference for decorators, we need to virtualize the access to master pointer.

Returns
Returns the master of this MultiDimAdressable.

Implements gum::MultiDimAdressable.

Reimplemented in gum::MultiDimBucket< GUM_SCALAR >.

Definition at line 304 of file multiDimContainer_tpl.h.

References gum::MultiDimContainer< GUM_SCALAR >::content().

304  {
305  return static_cast< const MultiDimAdressable& >(*content());
306  }
virtual const MultiDimImplementation< GUM_SCALAR > * content() const =0
Returns the implementation for this object (may be *this).
MultiDimAdressable()
Default constructor.
+ Here is the call graph for this function:

◆ isNonZeroMap()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::isNonZeroMap ( ) const

create a boolean-like potential using the predicate isNonZero

Definition at line 487 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::apply().

487  {
488  auto p = Potential< GUM_SCALAR >(*this);
489  p.apply([](GUM_SCALAR x) {
490  if (x != static_cast< GUM_SCALAR >(0))
491  return static_cast< GUM_SCALAR >(1);
492  else
493  return static_cast< GUM_SCALAR >(0);
494  });
495  return p;
496  }
+ Here is the call graph for this function:

◆ KL()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::Potential< GUM_SCALAR >::KL ( const Potential< GUM_SCALAR > &  p) const

compute KL divergence between this and p Checks the compatibility and then compute KL divergence

Exceptions
gum::InvalidArgumentif p is not compatible with $this (dimension, variables)
gum::FatalErrorif a zero is found in p or this and not in the other.

Definition at line 303 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::contains(), gum::Instantiation::end(), gum::MultiDimDecorator< GUM_SCALAR >::get(), GUM_ERROR, gum::Instantiation::inc(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), gum::Instantiation::setFirst(), and gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence().

303  {
304  if (this->nbrDim() != p.nbrDim())
305  GUM_ERROR(
306  InvalidArgument,
307  "BNdistance between potentials with different numbers of dimensions");
308  for (const auto var : p.variablesSequence()) {
309  if (!this->contains(*var))
310  GUM_ERROR(InvalidArgument,
311  "A variable in the argument does not belong to the potential.");
312  }
313  for (const auto var : this->variablesSequence()) {
314  if (!p.contains(*var))
315  GUM_ERROR(InvalidArgument, "A variable does not belong to the argument.");
316  }
317 
318  Instantiation inst(*this);
319  GUM_SCALAR res = static_cast< GUM_SCALAR >(0);
320  for (inst.setFirst(); !inst.end(); inst.inc()) {
321  GUM_SCALAR x = this->get(inst);
322  GUM_SCALAR y = p.get(inst);
323  if (static_cast< GUM_SCALAR >(0) == x) // 0*log(0/y)=0
324  continue;
325 
326  if (static_cast< GUM_SCALAR >(0) == y)
327  // we know that x!=0;
328  GUM_ERROR(FatalError,
329  "The argument has a 0 at " << inst
330  << " while the potential has not.")
331 
332  res += x * log2(x / y);
333  }
334  return res;
335  }
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns a const ref to the sequence of DiscreteVariable*.
virtual bool contains(const DiscreteVariable &var) const final
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ margMaxIn()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::margMaxIn ( const Set< const DiscreteVariable * > &  kept_vars) const

Projection using max as operation (and implementation-optimized operations)

Parameters
kept_varsis the set of vars to keep

Definition at line 477 of file potential_tpl.h.

References gum::Potential< GUM_SCALAR >::_complementVars(), gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Potential< GUM_SCALAR >::fillWith(), and gum::projectMax().

478  {
479  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
480  return Potential< GUM_SCALAR >().fillWith(this->_empty_value);
481  }
482  return Potential< GUM_SCALAR >(
483  gum::projectMax(*this->content(), _complementVars(kept_vars)));
484  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
Set< const DiscreteVariable *> _complementVars(const Set< const DiscreteVariable * > &del_vars) const
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
const Potential< GUM_SCALAR > & fillWith(const Potential< GUM_SCALAR > &src) const
copy a Potential data using name of variables and labels (not necessarily the same variables in the s...
GUM_SCALAR projectMax(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Max
+ Here is the call graph for this function:

◆ margMaxOut()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::margMaxOut ( const Set< const DiscreteVariable * > &  del_vars) const

Projection using max as operation (and implementation-optimized operations)

Parameters
del_varsis the set of vars to eliminate

Definition at line 439 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Potential< GUM_SCALAR >::fillWith(), and gum::projectMax().

440  {
441  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
442  return Potential< GUM_SCALAR >().fillWith(this->_empty_value);
443  }
444  return Potential< GUM_SCALAR >(gum::projectMax(*this->content(), del_vars));
445  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
const Potential< GUM_SCALAR > & fillWith(const Potential< GUM_SCALAR > &src) const
copy a Potential data using name of variables and labels (not necessarily the same variables in the s...
GUM_SCALAR projectMax(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Max
+ Here is the call graph for this function:

◆ margMinIn()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::margMinIn ( const Set< const DiscreteVariable * > &  kept_vars) const

Projection using min as operation (and implementation-optimized operations)

Parameters
kept_varsis the set of vars to keep

Definition at line 467 of file potential_tpl.h.

References gum::Potential< GUM_SCALAR >::_complementVars(), gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Potential< GUM_SCALAR >::fillWith(), and gum::projectMin().

468  {
469  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
470  return Potential< GUM_SCALAR >().fillWith(this->_empty_value);
471  }
472  return Potential< GUM_SCALAR >(
473  gum::projectMin(*this->content(), _complementVars(kept_vars)));
474  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
Set< const DiscreteVariable *> _complementVars(const Set< const DiscreteVariable * > &del_vars) const
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
const Potential< GUM_SCALAR > & fillWith(const Potential< GUM_SCALAR > &src) const
copy a Potential data using name of variables and labels (not necessarily the same variables in the s...
GUM_SCALAR projectMin(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Min
+ Here is the call graph for this function:

◆ margMinOut()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::margMinOut ( const Set< const DiscreteVariable * > &  del_vars) const

Projection using min as operation (and implementation-optimized operations)

Parameters
del_varsis the set of vars to eliminate

Definition at line 430 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Potential< GUM_SCALAR >::fillWith(), and gum::projectMin().

431  {
432  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
433  return Potential< GUM_SCALAR >().fillWith(this->_empty_value);
434  }
435  return Potential< GUM_SCALAR >(gum::projectMin(*this->content(), del_vars));
436  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
const Potential< GUM_SCALAR > & fillWith(const Potential< GUM_SCALAR > &src) const
copy a Potential data using name of variables and labels (not necessarily the same variables in the s...
GUM_SCALAR projectMin(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Min
+ Here is the call graph for this function:

◆ margProdIn()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::margProdIn ( const Set< const DiscreteVariable * > &  kept_vars) const

Projection using multiplication as operation (and implementation-optimized operations)

Parameters
kept_varsis the set of vars to keep

Definition at line 457 of file potential_tpl.h.

References gum::Potential< GUM_SCALAR >::_complementVars(), gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Potential< GUM_SCALAR >::fillWith(), and gum::projectProduct().

458  {
459  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
460  return Potential< GUM_SCALAR >().fillWith(this->_empty_value);
461  }
462  return Potential< GUM_SCALAR >(
463  gum::projectProduct(*this->content(), _complementVars(kept_vars)));
464  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR projectProduct(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Product
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
Set< const DiscreteVariable *> _complementVars(const Set< const DiscreteVariable * > &del_vars) const
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
const Potential< GUM_SCALAR > & fillWith(const Potential< GUM_SCALAR > &src) const
copy a Potential data using name of variables and labels (not necessarily the same variables in the s...
+ Here is the call graph for this function:

◆ margProdOut()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::margProdOut ( const Set< const DiscreteVariable * > &  del_vars) const

Projection using multiplication as operation (and implementation-optimized operations)

Parameters
del_varsis the set of vars to eliminate

Definition at line 420 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Potential< GUM_SCALAR >::fillWith(), and gum::projectProduct().

421  {
422  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
423  return Potential< GUM_SCALAR >().fillWith(this->_empty_value);
424  }
425  return Potential< GUM_SCALAR >(
426  gum::projectProduct(*this->content(), del_vars));
427  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR projectProduct(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Product
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
const Potential< GUM_SCALAR > & fillWith(const Potential< GUM_SCALAR > &src) const
copy a Potential data using name of variables and labels (not necessarily the same variables in the s...
+ Here is the call graph for this function:

◆ margSumIn()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::margSumIn ( const Set< const DiscreteVariable * > &  kept_vars) const

Projection using sum as operation (and implementation-optimized operations)

Parameters
kept_varsis the set of vars to keep

Definition at line 447 of file potential_tpl.h.

References gum::Potential< GUM_SCALAR >::_complementVars(), gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Potential< GUM_SCALAR >::fillWith(), and gum::projectSum().

448  {
449  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
450  return Potential< GUM_SCALAR >().fillWith(this->_empty_value);
451  }
452  return Potential< GUM_SCALAR >(
453  gum::projectSum(*this->content(), _complementVars(kept_vars)));
454  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
Set< const DiscreteVariable *> _complementVars(const Set< const DiscreteVariable * > &del_vars) const
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
const Potential< GUM_SCALAR > & fillWith(const Potential< GUM_SCALAR > &src) const
copy a Potential data using name of variables and labels (not necessarily the same variables in the s...
GUM_SCALAR projectSum(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a sum
+ Here is the call graph for this function:

◆ margSumOut()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::margSumOut ( const Set< const DiscreteVariable * > &  del_vars) const

Projection using sum as operation (and implementation-optimized operations)

Parameters
del_varsis the set of vars to eliminate

Definition at line 411 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Potential< GUM_SCALAR >::fillWith(), and gum::projectSum().

Referenced by gum::prm::eliminateNode(), gum::JointTargetedInference< GUM_SCALAR >::I(), gum::LPNewprojPotential(), gum::BayesNet< double >::reverseArc(), gum::SSNewprojPotential(), and gum::VENewprojPotential().

412  {
413  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
414  return Potential< GUM_SCALAR >().fillWith(this->_empty_value);
415  }
416  return Potential< GUM_SCALAR >(gum::projectSum(*this->content(), del_vars));
417  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
const Potential< GUM_SCALAR > & fillWith(const Potential< GUM_SCALAR > &src) const
copy a Potential data using name of variables and labels (not necessarily the same variables in the s...
GUM_SCALAR projectSum(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a sum
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ max()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::Potential< GUM_SCALAR >::max ( ) const

max of all elements in the Potential

Definition at line 142 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::projectMax().

Referenced by gum::Potential< GUM_SCALAR >::argmax().

142  {
143  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
144  return this->_empty_value;
145  }
146  return gum::projectMax(*this->content());
147  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
GUM_SCALAR projectMax(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Max
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maxNonOne()

template<typename GUM_SCALAR >
GUM_SCALAR gum::Potential< GUM_SCALAR >::maxNonOne ( ) const

max of all non one elements in the Potential

Exceptions
NotFoundif all value == 1.0

Definition at line 159 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::empty(), GUM_ERROR, and gum::MultiDimDecorator< GUM_SCALAR >::reduce().

159  {
160  GUM_SCALAR res;
161 
162  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
163  res = this->_empty_value;
164  } else {
165  res = this->reduce(
166  [](GUM_SCALAR z, GUM_SCALAR p) {
167  return (p == static_cast< GUM_SCALAR >(1))
168  ? z
169  : (z == static_cast< GUM_SCALAR >(1)) ? p : (p > z ? p : z);
170  },
171  static_cast< GUM_SCALAR >(1));
172  }
173 
174  if (res == static_cast< GUM_SCALAR >(1))
175  GUM_ERROR(NotFound, "No other value than 1");
176 
177  return res;
178  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual GUM_SCALAR reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const final
compute lfold for this container
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ min()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::Potential< GUM_SCALAR >::min ( ) const

min of all elements in the Potential

Definition at line 150 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::projectMin().

Referenced by gum::Potential< GUM_SCALAR >::argmin().

150  {
151  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
152  return this->_empty_value;
153  }
154  return gum::projectMin(*this->content());
155  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
GUM_SCALAR projectMin(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Min
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ minNonZero()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::Potential< GUM_SCALAR >::minNonZero ( ) const

min of all non zero elements in the Potential

Exceptions
NotFoundif all value == 0.0

Definition at line 182 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::empty(), GUM_ERROR, and gum::MultiDimDecorator< GUM_SCALAR >::reduce().

182  {
183  GUM_SCALAR res;
184 
185  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
186  res = this->_empty_value;
187  } else {
188  res = this->reduce(
189  [](GUM_SCALAR z, GUM_SCALAR p) {
190  return (p == static_cast< GUM_SCALAR >(0))
191  ? z
192  : (z == static_cast< GUM_SCALAR >(0)) ? p : (p < z ? p : z);
193  },
194  static_cast< GUM_SCALAR >(0));
195  }
196 
197  if (res == static_cast< GUM_SCALAR >(0))
198  GUM_ERROR(NotFound, "No other value than 1");
199 
200  return res;
201  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual GUM_SCALAR reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const final
compute lfold for this container
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ nbrDim()

template<typename GUM_SCALAR >
INLINE Idx gum::MultiDimDecorator< GUM_SCALAR >::nbrDim ( ) const
finalvirtualinherited

Returns the number of vars in the multidimensional container.

Returns
Returns the number of vars in the multidimensional container.

Implements gum::MultiDimInterface.

Definition at line 317 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::GibbsOperator< GUM_SCALAR >::__GibbsSample(), gum::prm::SVED< GUM_SCALAR >::_marginal(), gum::prm::PRMInference< double >::addEvidence(), gum::BayesNet< double >::changePotential(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::Potential< GUM_SCALAR >::draw(), gum::Potential< GUM_SCALAR >::fillWith(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::BayesNetFragment< GUM_SCALAR >::installMarginal(), gum::prm::PRMInference< double >::joint(), gum::Potential< GUM_SCALAR >::KL(), gum::prm::PRMInference< double >::marginal(), gum::Potential< GUM_SCALAR >::putFirst(), gum::Potential< GUM_SCALAR >::reorganize(), gum::MultiDimDecorator< GUM_SCALAR >::set(), and gum::BayesNetFragment< GUM_SCALAR >::uninstallCPT().

317  {
318  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->nbrDim();
319  }
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
+ Here is the caller graph for this function:

◆ newFactory()

template<typename GUM_SCALAR >
INLINE Potential< GUM_SCALAR > * gum::Potential< GUM_SCALAR >::newFactory ( ) const
virtual

Default implementation of MultiDimContainer::set().

Calls _get as a r-value.

Implements gum::MultiDimDecorator< GUM_SCALAR >.

Definition at line 118 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::content().

118  {
119  return new Potential< GUM_SCALAR >(
120  static_cast< MultiDimImplementation< GUM_SCALAR >* >(
121  this->content()->newFactory()));
122  }
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
+ Here is the call graph for this function:

◆ normalize()

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::normalize ( ) const

normalisation of this do nothing if sum is 0

Definition at line 352 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::apply(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::Potential< GUM_SCALAR >::sum().

Referenced by gum::GibbsOperator< GUM_SCALAR >::__GibbsSample(), gum::prm::SVED< GUM_SCALAR >::_marginal(), gum::prm::SVE< GUM_SCALAR >::_marginal(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::JointTargetedInference< GUM_SCALAR >::I(), and gum::Estimator< GUM_SCALAR >::posterior().

352  {
353  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
354  if (this->_empty_value != static_cast< GUM_SCALAR >(0))
355  this->_empty_value = static_cast< GUM_SCALAR >(1.0);
356  } else {
357  GUM_SCALAR s = sum();
358 
359  if (s != (GUM_SCALAR)0) {
360  this->apply([s](GUM_SCALAR x) { return x / s; });
361  }
362  }
363  return *this;
364  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const final
Apply a function on every element of the container.
GUM_SCALAR sum() const
sum of all elements in the Potential
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ normalizeAsCPT()

template<typename GUM_SCALAR >
INLINE void gum::Potential< GUM_SCALAR >::normalizeAsCPT ( ) const

normalisation of this as a CPT

Exceptions
FatalErrorit some distribution sums to 0

Definition at line 367 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Instantiation::end(), GUM_ERROR, gum::Instantiation::incNotVar(), gum::Instantiation::incVar(), gum::Instantiation::setFirst(), gum::Instantiation::setFirstVar(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

Referenced by gum::ImportanceSampling< GUM_SCALAR >::_unsharpenBN().

367  {
368  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
369  if (this->_empty_value != static_cast< GUM_SCALAR >(0)) {
370  this->_empty_value = static_cast< GUM_SCALAR >(1.0);
371  } else {
372  GUM_ERROR(FatalError,
373  "Normalization for a potential that sum to 0 in " << *this);
374  }
375  } else {
376  Instantiation inst(*this);
377  const auto& v = this->variable(0);
378 
379  for (inst.setFirst(); !inst.end(); inst.incNotVar(v)) {
380  GUM_SCALAR s = (GUM_SCALAR)0.0;
381  for (inst.setFirstVar(v); !inst.end(); inst.incVar(v))
382  s += this->get(inst);
383  if (s == (GUM_SCALAR)0.0) {
384  GUM_ERROR(FatalError,
385  "Normalization for a potential that sum to 0 in " << *this);
386  }
387  if (s != (GUM_SCALAR)1.0) {
388  for (inst.setFirstVar(v); !inst.end(); inst.incVar(v))
389  this->set(inst, this->get(inst) / s);
390  }
391  inst.setFirstVar(v); // to remove inst.end()
392  }
393  }
394  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ notifyChange()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::notifyChange ( ) const
finalvirtualinherited

Definition at line 300 of file multiDimDecorator_tpl.h.

References GUM_ERROR.

300  {
301  /*( (MultiDimContainer<GUM_SCALAR> *) _content)->notifyChange();*/
302  GUM_ERROR(OperationNotAllowed, "Not implemented yet");
303  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52

◆ operator!=() [1/2]

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimContainer< GUM_SCALAR >::operator!= ( const MultiDimContainer< GUM_SCALAR > &  p) const
inherited

Test if this MultiDimContainer is different of p.

Parameters
pThe MultiDimContainer to test for inequality.
Returns
Returns true if this MultiDimContainer is different of p.

Definition at line 157 of file multiDimContainer_tpl.h.

References gum::MultiDimContainer< GUM_SCALAR >::operator==().

Referenced by gum::MultiDimContainer< GUM_SCALAR >::operator==().

157  {
158  return !operator==(p);
159  }
bool operator==(const MultiDimContainer< GUM_SCALAR > &p) const
Test if this MultiDimContainer is equal to p.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator!=() [2/2]

template<typename GUM_SCALAR>
bool gum::Potential< GUM_SCALAR >::operator!= ( const Potential< GUM_SCALAR > &  r) const
inline

the function to be used to add two Potentials

Definition at line 414 of file potential.h.

References gum::Potential< GUM_SCALAR >::operator==().

414  {
415  return !operator==(r);
416  }
bool operator==(const Potential< GUM_SCALAR > &r) const
the function to be used to add two Potentials
Definition: potential.h:400
+ Here is the call graph for this function:

◆ operator*()

template<typename GUM_SCALAR>
Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::operator* ( const Potential< GUM_SCALAR > &  p2) const
inline

the function to be used to multiply two Potentials

Definition at line 360 of file potential.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::Potential< GUM_SCALAR >::scale().

360  {
361  if (p2.empty()) return Potential< GUM_SCALAR >(*this).scale(p2._empty_value);
362  if (this->empty())
363  return Potential< GUM_SCALAR >(p2).scale(this->_empty_value);
364 
365  return Potential< GUM_SCALAR >(*this->content() * *p2.content());
366  }
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
const Potential< GUM_SCALAR > & scale(GUM_SCALAR v) const
create a new potential multiplied by v from *this
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
+ Here is the call graph for this function:

◆ operator*=()

template<typename GUM_SCALAR>
Potential< GUM_SCALAR >& gum::Potential< GUM_SCALAR >::operator*= ( const Potential< GUM_SCALAR > &  r)
inline

the function to be used to add two Potentials

Definition at line 385 of file potential.h.

385  {
386  *this = *this * r;
387  return *this;
388  }

◆ operator+()

template<typename GUM_SCALAR>
Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::operator+ ( const Potential< GUM_SCALAR > &  p2) const
inline

the function to be used to add two Potentials

Definition at line 338 of file potential.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::Potential< GUM_SCALAR >::translate().

338  {
339  if (p2.empty())
340  return Potential< GUM_SCALAR >(*this).translate(p2._empty_value);
341  if (this->empty())
342  return Potential< GUM_SCALAR >(p2).translate(this->_empty_value);
343 
344  return Potential< GUM_SCALAR >(*this->content() + *p2.content());
345  }
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
const Potential< GUM_SCALAR > & translate(GUM_SCALAR v) const
create a new potential added with v from *this
+ Here is the call graph for this function:

◆ operator+=()

template<typename GUM_SCALAR>
Potential< GUM_SCALAR >& gum::Potential< GUM_SCALAR >::operator+= ( const Potential< GUM_SCALAR > &  r)
inline

the function to be used to add two Potentials

Definition at line 380 of file potential.h.

380  {
381  *this = *this + r;
382  return *this;
383  }

◆ operator-()

template<typename GUM_SCALAR>
Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::operator- ( const Potential< GUM_SCALAR > &  p2) const
inline

the function to be used to subtract two Potentials

Definition at line 348 of file potential.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::apply(), gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::Potential< GUM_SCALAR >::translate().

348  {
349  if (p2.empty())
350  return Potential< GUM_SCALAR >(*this).translate(-p2._empty_value);
351  if (this->empty()) {
352  auto p = Potential< GUM_SCALAR >(p2);
353  p.apply([this](GUM_SCALAR x) { return this->_empty_value - x; });
354  return p;
355  }
356  return Potential< GUM_SCALAR >(*this->content() - *p2.content());
357  }
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
+ Here is the call graph for this function:

◆ operator-=()

template<typename GUM_SCALAR>
Potential< GUM_SCALAR >& gum::Potential< GUM_SCALAR >::operator-= ( const Potential< GUM_SCALAR > &  r)
inline

the function to be used to add two Potentials

Definition at line 390 of file potential.h.

390  {
391  *this = *this - r;
392  return *this;
393  }

◆ operator/()

template<typename GUM_SCALAR>
Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::operator/ ( const Potential< GUM_SCALAR > &  p2) const
inline

the function to be used to divide two Potentials

Definition at line 369 of file potential.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::apply(), gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::Potential< GUM_SCALAR >::scale().

369  {
370  if (p2.empty())
371  return Potential< GUM_SCALAR >(*this).scale(1 / p2._empty_value);
372  if (this->empty()) {
373  auto p = Potential< GUM_SCALAR >(p2);
374  p.apply([this](GUM_SCALAR x) { return this->_empty_value / x; });
375  return p;
376  }
377  return Potential< GUM_SCALAR >(*this->content() / *p2.content());
378  }
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
+ Here is the call graph for this function:

◆ operator/=()

template<typename GUM_SCALAR>
Potential< GUM_SCALAR >& gum::Potential< GUM_SCALAR >::operator/= ( const Potential< GUM_SCALAR > &  r)
inline

the function to be used to add two Potentials

Definition at line 395 of file potential.h.

395  {
396  *this = *this / r;
397  return *this;
398  }

◆ operator=() [1/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::operator= ( const Potential< GUM_SCALAR > &  src)

Default constructor.

Creates an empty null dimensional matrix with a MultiDimArray as its implementation.

Definition at line 93 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::operator=().

Referenced by gum::Potential< GUM_SCALAR >::Potential().

93  {
95  GUM_OP_CPY(Potential);
96  return *this;
97  }
MultiDimDecorator< GUM_SCALAR > & operator=(const MultiDimDecorator &from) noexcept
copy operator
Potential()
Default constructor.
Definition: potential_tpl.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [2/2]

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::operator= ( Potential< GUM_SCALAR > &&  src)

Default constructor.

Creates an empty null dimensional matrix with a MultiDimArray as its implementation.

Definition at line 102 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::operator=().

102  {
104  std::forward< MultiDimDecorator< GUM_SCALAR > >(src));
105  GUM_OP_MOV(Potential);
106  return *this;
107  }
MultiDimDecorator< GUM_SCALAR > & operator=(const MultiDimDecorator &from) noexcept
copy operator
Potential()
Default constructor.
Definition: potential_tpl.h:35
+ Here is the call graph for this function:

◆ operator==() [1/2]

template<typename GUM_SCALAR >
bool gum::MultiDimContainer< GUM_SCALAR >::operator== ( const MultiDimContainer< GUM_SCALAR > &  p) const
inherited

Test if this MultiDimContainer is equal to p.

Parameters
pThe MultiDimContainer to test for equality.
Returns
Returns true if this MultiDimContainer is equal to p.

Definition at line 126 of file multiDimContainer_tpl.h.

References gum::MultiDimInterface::domainSize(), gum::Instantiation::end(), gum::MultiDimContainer< GUM_SCALAR >::get(), gum::MultiDimInterface::nbrDim(), gum::MultiDimContainer< GUM_SCALAR >::operator!=(), gum::Instantiation::setFirst(), and gum::MultiDimInterface::variablesSequence().

Referenced by gum::MultiDimContainer< GUM_SCALAR >::operator!=(), and gum::MultiDimContainer< GUM_SCALAR >::toString().

126  {
127  if ((nbrDim() == p.nbrDim()) && (domainSize() == p.domainSize())) {
128  if (nbrDim() == 0) return true;
129 
131  var_iterator;
132 
133  for (var_iterator iter = variablesSequence().beginSafe();
134  iter != variablesSequence().endSafe();
135  ++iter) {
136  if (!p.variablesSequence().exists(*iter)) { return false; }
137  }
138  } else {
139  return false;
140  }
141 
142  Instantiation i(*this);
143 
144  AlmostDifferent< GUM_SCALAR > cmp;
145 
146  for (i.setFirst(); !i.end(); ++i) {
147  if (cmp(get(i), p.get(i))) { return false; }
148  }
149 
150  return true;
151  }
virtual Idx nbrDim() const =0
Returns the number of vars in the multidimensional container.
virtual Size domainSize() const =0
Returns the product of the variables domain size.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const =0
Returns a const ref to the sequence of DiscreteVariable*.
SequenceIteratorSafe< Key > const_iterator_safe
Types for STL compliance.
Definition: sequence.h:1035
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator==() [2/2]

template<typename GUM_SCALAR>
bool gum::Potential< GUM_SCALAR >::operator== ( const Potential< GUM_SCALAR > &  r) const
inline

the function to be used to add two Potentials

Definition at line 400 of file potential.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, and gum::MultiDimDecorator< GUM_SCALAR >::empty().

Referenced by gum::Potential< GUM_SCALAR >::operator!=().

400  {
401  if (this->empty()) {
402  if (r.empty())
403  return this->_empty_value == r._empty_value;
404  else
405  return false;
406  } else {
407  if (r.empty())
408  return false;
409  else
410  return (*this->_content) == (*r._content);
411  }
412  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator[]()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::MultiDimContainer< GUM_SCALAR >::operator[] ( const Instantiation i) const
inherited

An [] operator using a Instantiation as argument.

Warning
If i variables set is disjoint with this MultiDimContainer then 0 is assumed for dimensions (i.e. variables) not prensent in the instantiation.
Parameters
iAn Instantiation.
Returns
Returns the adressed (GUM_SCALAR) value.

Definition at line 79 of file multiDimContainer_tpl.h.

Referenced by gum::MultiDimContainer< GUM_SCALAR >::~MultiDimContainer().

79  {
80  return get(i);
81  }
+ Here is the caller graph for this function:

◆ populate() [1/2]

template<typename GUM_SCALAR >
void gum::MultiDimDecorator< GUM_SCALAR >::populate ( const std::vector< GUM_SCALAR > &  v) const
finalvirtualinherited

Automatically fills this MultiDimContainer with the values in v.

The order used to fill this MultiDimContainer is the same as with an instantiation over it.

Size cpt = 0;
Instantiation i( *this );
for (i.setFirst(); !i.end(); ++i, ++cpt) {
set(i, v[cpt]);
}
Parameters
vVector of values.
Exceptions
SizeErrorRaised if v size's does not matches this MultiDimContainer domain size.

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 322 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::empty(), and GUM_ERROR.

Referenced by gum::Potential< GUM_SCALAR >::fillWith(), and gum::SimpleUTGenerator::generateUT().

323  {
324  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->empty()) {
325  if (v.size() == 1) {
326  _empty_value = v[0];
327  } else {
328  GUM_ERROR(SizeError, "Size do not match in populate")
329  }
330  } else {
331  _content->populate(v);
332  }
333  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ populate() [2/2]

template<typename GUM_SCALAR >
void gum::MultiDimContainer< GUM_SCALAR >::populate ( std::initializer_list< GUM_SCALAR >  l) const
virtualinherited

Automatically fills this MultiDimContainer with the values in l.

The order used to fill this MultiDimContainer is the same as with an instantiation over it.

Size cpt = 0;
Instantiation i( *this );
for (i.setFirst(); !i.end(); ++i, ++cpt) {
set(i, v[cpt]);
}
Parameters
lcontains the data.
Exceptions
SizeErrorRaised if l size's does not matches this MultiDimContainer domain size.

Reimplemented in gum::MultiDimBijArray< GUM_SCALAR >, gum::MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >, gum::MultiDimFunctionGraph< GUM_SCALAR >, and gum::MultiDimFunctionGraph< GUM_SCALAR, ExactTerminalNodePolicy >.

Definition at line 178 of file multiDimContainer_tpl.h.

References gum::MultiDimInterface::domainSize(), and GUM_ERROR.

179  {
180  if (domainSize() != l.size()) {
181  GUM_ERROR(SizeError, "Sizes do not match in populate");
182  }
183 
184  Instantiation i(*this);
185  // insert all the elements
186  for (const auto& elt : l) {
187  set(i, elt);
188  ++i;
189  }
190  }
virtual Size domainSize() const =0
Returns the product of the variables domain size.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ pos()

template<typename GUM_SCALAR >
INLINE Idx gum::MultiDimDecorator< GUM_SCALAR >::pos ( const DiscreteVariable v) const
finalvirtualinherited

Returns the index of a variable.

Parameters
vThe variable for which the index is returned.
Returns
Returns the index of a variable.
Exceptions
NotFoundRaised if v is not in this multidimensional matrix.

Implements gum::MultiDimInterface.

Definition at line 266 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::credal::CredalNet< GUM_SCALAR >::approximatedBinarization().

266  {
267  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->pos(d);
268  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual Idx pos(const DiscreteVariable &var) const final
Returns the index of a variable.
+ Here is the caller graph for this function:

◆ product()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::Potential< GUM_SCALAR >::product ( ) const

product of all elements in the Potential

Definition at line 134 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::projectProduct().

134  {
135  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
136  return this->_empty_value;
137  }
138  return gum::projectProduct(*this->content());
139  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR projectProduct(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Product
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
+ Here is the call graph for this function:

◆ putFirst()

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::putFirst ( const DiscreteVariable var) const

create a new Potential with a certain variable in first

Exceptions
InvalidArgumentif the var is not in the potential

Definition at line 534 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::contains(), GUM_ERROR, gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), gum::Potential< GUM_SCALAR >::reorganize(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

534  {
535  if (!this->contains(*var)) {
536  GUM_ERROR(InvalidArgument,
537  "The variable to put first does not belong to the potential");
538  }
539 
540  std::vector< const DiscreteVariable* > vars;
541  vars.push_back(var);
542  for (Idx i = 0; i < this->nbrDim(); i++)
543  if (&(this->variable(i)) != var) vars.push_back(&(this->variable(i)));
544 
545  return this->reorganize(vars);
546  }
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
Potential< GUM_SCALAR > reorganize(const std::vector< const DiscreteVariable * > &vars) const
create a new Potential with another order
virtual bool contains(const DiscreteVariable &var) const final
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ reduce()

template<typename GUM_SCALAR >
GUM_SCALAR gum::MultiDimDecorator< GUM_SCALAR >::reduce ( std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) >  f,
GUM_SCALAR  base 
) const
finalvirtualinherited

compute lfold for this container

Parameters
fthe function to apply
basethe initial value

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 346 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, and gum::MultiDimDecorator< GUM_SCALAR >::empty().

Referenced by gum::Potential< GUM_SCALAR >::entropy(), gum::Potential< GUM_SCALAR >::maxNonOne(), and gum::Potential< GUM_SCALAR >::minNonZero().

348  {
349  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->empty()) {
350  return base;
351  } else {
352  return _content->reduce(f, base);
353  }
354  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual bool empty() const final
Returns true if no var is in *this.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ registerSlave()

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimDecorator< GUM_SCALAR >::registerSlave ( Instantiation i)
finalvirtualinherited

Register i as a slave of this MultiDimAdressable.

Parameters
iThe Instantiation to enslave.
Returns
Returns true if i becomes a slave of this MultiDimAdressable.

Implements gum::MultiDimAdressable.

Definition at line 241 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

241  {
242  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)
243  ->registerSlave(i);
244  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual bool registerSlave(Instantiation &i) final
Register i as a slave of this MultiDimAdressable.

◆ reorganize()

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > gum::Potential< GUM_SCALAR >::reorganize ( const std::vector< const DiscreteVariable * > &  vars) const

create a new Potential with another order

Exceptions
InvalidArgumentif not all and only the vars of the potential are in vars

Definition at line 510 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::MultiDimDecorator< GUM_SCALAR >::beginMultipleChanges(), gum::MultiDimDecorator< GUM_SCALAR >::contains(), gum::MultiDimContainer< GUM_SCALAR >::copyFrom(), gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges(), GUM_ERROR, and gum::MultiDimDecorator< GUM_SCALAR >::nbrDim().

Referenced by gum::Potential< GUM_SCALAR >::putFirst().

511  {
512  if (vars.size() != this->nbrDim())
513  GUM_ERROR(InvalidArgument,
514  "The vector contains " << vars.size() << " variables instead of "
515  << this->nbrDim() << ".");
516  for (const auto var : vars) {
517  if (!this->contains(*var))
518  GUM_ERROR(InvalidArgument,
519  "A variable in the vector does not belong to the potential.");
520  }
521 
522  Potential< GUM_SCALAR > p;
523  p.beginMultipleChanges();
524  for (const auto var : vars)
525  p.add(*var);
526  p.endMultipleChanges();
527  p.copyFrom(*this, nullptr); // copy *this in p using the same order
528 
529  return p;
530  }
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
virtual bool contains(const DiscreteVariable &var) const final
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 33 of file multiDimInterface_inl.h.

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

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

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

◆ scale()

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::scale ( GUM_SCALAR  v) const

create a new potential multiplied by v from *this

Definition at line 398 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::apply().

Referenced by gum::Potential< GUM_SCALAR >::operator*(), and gum::Potential< GUM_SCALAR >::operator/().

398  {
399  this->apply([v](GUM_SCALAR x) { return x * v; });
400  return *this;
401  }
virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const final
Apply a function on every element of the container.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::set ( const Instantiation i,
const GUM_SCALAR &  value 
) const
finalvirtualinherited

Default implementation of MultiDimContainer::set().

Calls _get as a r-value.

Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 154 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, and gum::MultiDimDecorator< GUM_SCALAR >::nbrDim().

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::prm::PRMSystem< double >::__groundPotential(), gum::prm::GroundedInference< GUM_SCALAR >::_evidenceAdded(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::prm::PRMInference< double >::addEvidence(), gum::credal::CredalNet< GUM_SCALAR >::bnToCredal(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::MarginalTargetedInference< GUM_SCALAR >::evidenceImpact(), gum::JointTargetedInference< GUM_SCALAR >::evidenceJointImpact(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT(), gum::credal::CredalNet< GUM_SCALAR >::idmLearning(), gum::prm::PRMInference< double >::marginal(), gum::prm::PRMInference< double >::operator=(), gum::learning::DAG2BNLearner< ALLOC >::operator=(), and gum::prm::PRMInference< double >::PRMInference().

155  {
156  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->nbrDim() == 0) {
157  _empty_value = value;
158  } else {
159  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->set(i, value);
160  }
161  }
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setChangeNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setChangeNotification ( const Instantiation i)
finalvirtualinherited

Listen to an assignment of a value in a Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 196 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

197  {
198  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)
200  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void setChangeNotification(const Instantiation &i) final
Listen to an assignment of a value in a Instantiation.

◆ setDecNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setDecNotification ( const Instantiation i)
finalvirtualinherited

Listen to increment in each recorded Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 233 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

233  {
234  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->setDecNotification(
235  i);
236  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void setDecNotification(const Instantiation &i) final
Listen to increment in each recorded Instantiation.

◆ setFirstNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setFirstNotification ( const Instantiation i)
finalvirtualinherited

Listen to setFirst in a given Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 205 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

206  {
207  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)
209  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void setFirstNotification(const Instantiation &i) final
Listen to setFirst in a given Instantiation.

◆ setIncNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setIncNotification ( const Instantiation i)
finalvirtualinherited

Listen to increment in a given Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 224 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

224  {
225  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->setIncNotification(
226  i);
227  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void setIncNotification(const Instantiation &i) final
Listen to increment in a given Instantiation.

◆ setLastNotification()

template<typename GUM_SCALAR >
INLINE void gum::MultiDimDecorator< GUM_SCALAR >::setLastNotification ( const Instantiation i)
finalvirtualinherited

Listen to setLast in a given Instantiation.

Parameters
iThe Instantiation to listen.

Implements gum::MultiDimAdressable.

Definition at line 215 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

215  {
216  static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->setLastNotification(
217  i);
218  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual void setLastNotification(const Instantiation &i) final
Listen to setLast in a given Instantiation.

◆ sq()

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::sq ( ) const

apply $x^2$ on every element of the container

Definition at line 296 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::apply().

296  {
297  this->apply([](GUM_SCALAR x) { return x * x; });
298  return *this;
299  }
virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const final
Apply a function on every element of the container.
+ Here is the call graph for this function:

◆ sum()

template<typename GUM_SCALAR >
INLINE GUM_SCALAR gum::Potential< GUM_SCALAR >::sum ( ) const

sum of all elements in the Potential

Definition at line 126 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, gum::MultiDimDecorator< GUM_SCALAR >::_empty_value, gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::projectSum().

Referenced by gum::GibbsOperator< GUM_SCALAR >::__GibbsSample(), and gum::Potential< GUM_SCALAR >::normalize().

126  {
127  if (static_cast< MultiDimContainer< GUM_SCALAR >* >(this->_content)->empty()) {
128  return this->_empty_value;
129  }
130  return gum::projectSum(*this->content());
131  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
GUM_SCALAR _empty_value
value of the MultiDimDecorator if no dimension.
virtual bool empty() const final
Returns true if no var is in *this.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
GUM_SCALAR projectSum(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a sum
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toString() [1/2]

template<typename GUM_SCALAR >
INLINE const std::string gum::MultiDimDecorator< GUM_SCALAR >::toString ( const Instantiation i) const
virtualinherited

Default implementation of MultiDimContainer::set().

Calls _get as a r-value.

Implements gum::MultiDimContainer< GUM_SCALAR >.

Definition at line 406 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

406  {
407  return _content->toString(i);
408  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.

◆ toString() [2/2]

template<typename GUM_SCALAR>
virtual const std::string gum::Potential< GUM_SCALAR >::toString ( ) const
inlinevirtual

the function to be used to add two Potentials

Reimplemented from gum::MultiDimDecorator< GUM_SCALAR >.

Definition at line 418 of file potential.h.

References gum::Potential< GUM_SCALAR >::_complementVars(), and gum::MultiDimDecorator< GUM_SCALAR >::toString().

Referenced by gum::Potential< GUM_SCALAR >::fillWith(), and gum::operator<<().

418  {
420  }
virtual const std::string toString() const
Default implementation of MultiDimContainer::set().
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ translate()

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::Potential< GUM_SCALAR >::translate ( GUM_SCALAR  v) const

create a new potential added with v from *this

Definition at line 405 of file potential_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::apply().

Referenced by gum::Potential< GUM_SCALAR >::operator+(), and gum::Potential< GUM_SCALAR >::operator-().

405  {
406  this->apply([v](GUM_SCALAR x) { return x + v; });
407  return *this;
408  }
virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const final
Apply a function on every element of the container.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unregisterSlave()

template<typename GUM_SCALAR >
INLINE bool gum::MultiDimDecorator< GUM_SCALAR >::unregisterSlave ( Instantiation i)
finalvirtualinherited

Unregister i as a slave of this MultiDimAdressable.

Parameters
iThe Instantiation to free.
Returns
Returns true, whatever happens.

Implements gum::MultiDimAdressable.

Definition at line 283 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

283  {
284  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)
285  ->unregisterSlave(i);
286  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual bool unregisterSlave(Instantiation &i) final
Unregister i as a slave of this MultiDimAdressable.

◆ variable() [1/2]

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::MultiDimDecorator< GUM_SCALAR >::variable ( Idx  i) const
finalvirtualinherited

Returns a const ref to the ith var.

param i An index of this multidimensional matrix.

Returns
Returns a const ref to the ith var.
Exceptions
NotFoundRaised if i does not reference a variable in this multidimensional matrix.

Implements gum::MultiDimInterface.

Definition at line 253 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::BayesNetFactory< GUM_SCALAR >::__fillProbaWithValuesTable(), gum::credal::CredalNet< GUM_SCALAR >::__intervalToCredal(), gum::BayesNet< double >::changePotential(), gum::BayesNetInference< GUM_SCALAR >::chgEvidence(), gum::Potential< GUM_SCALAR >::draw(), gum::Potential< GUM_SCALAR >::fillWith(), gum::SimpleCPTGenerator< GUM_SCALAR >::generateCPT(), gum::BayesNetFragment< GUM_SCALAR >::installCPT(), gum::BayesNetFragment< GUM_SCALAR >::installMarginal(), gum::credal::CredalNet< GUM_SCALAR >::intervalToCredal(), gum::credal::CredalNet< GUM_SCALAR >::intervalToCredalWithFiles(), gum::credal::CredalNet< GUM_SCALAR >::lagrangeNormalization(), gum::Potential< GUM_SCALAR >::normalizeAsCPT(), gum::Potential< GUM_SCALAR >::putFirst(), gum::credal::CredalNet< GUM_SCALAR >::setCPT(), gum::credal::CredalNet< GUM_SCALAR >::setCPTs(), gum::BayesNetFragment< GUM_SCALAR >::uninstallCPT(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().

253  {
254  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->variable(i);
255  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
+ Here is the caller graph for this function:

◆ variable() [2/2]

template<typename GUM_SCALAR >
INLINE const DiscreteVariable & gum::MultiDimDecorator< GUM_SCALAR >::variable ( const std::string &  name) const
finalvirtualinherited

Returns the variable with the name.

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

Implements gum::MultiDimInterface.

Definition at line 259 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content, and gum::MultiDimDecorator< GUM_SCALAR >::variable().

259  {
260  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)->variable(
261  name);
262  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
+ Here is the call graph for this function:

◆ variablesSequence()

template<typename GUM_SCALAR >
INLINE const Sequence< const DiscreteVariable *> & gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence ( ) const
finalvirtualinherited

Returns a const ref to the sequence of DiscreteVariable*.

Returns
Returns a const ref to the sequence of DiscreteVariable*.

Implements gum::MultiDimInterface.

Definition at line 309 of file multiDimDecorator_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::_content.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::__buildPatternGraph(), gum::prm::__print_pot__(), gum::BayesNetFactory< GUM_SCALAR >::__setCPTAndParents(), gum::Potential< GUM_SCALAR >::_complementVars(), gum::prm::SVED< GUM_SCALAR >::_marginal(), gum::prm::StructuredInference< GUM_SCALAR >::_marginal(), gum::learning::DAG2BNLearner< ALLOC >::createBN(), gum::credal::CredalNet< GUM_SCALAR >::fillConstraint(), gum::Potential< GUM_SCALAR >::fillWith(), gum::Potential< GUM_SCALAR >::KL(), and gum::learning::DAG2BNLearner< ALLOC >::operator=().

309  {
310  return static_cast< MultiDimContainer< GUM_SCALAR >* >(_content)
311  ->variablesSequence();
312  }
MultiDimImplementation< GUM_SCALAR > * _content
The true container.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const final
Returns a const ref to the sequence of DiscreteVariable*.
+ Here is the caller graph for this function:

Member Data Documentation

◆ _content

template<typename GUM_SCALAR>
MultiDimImplementation< GUM_SCALAR >* gum::MultiDimDecorator< GUM_SCALAR >::_content
mutableprotectedinherited

The true container.

Definition at line 247 of file multiDimDecorator.h.

Referenced by gum::MultiDimDecorator< GUM_SCALAR >::_swapContent(), gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::MultiDimDecorator< GUM_SCALAR >::apply(), gum::MultiDimDecorator< GUM_SCALAR >::beginMultipleChanges(), gum::MultiDimDecorator< GUM_SCALAR >::changeNotification(), gum::MultiDimDecorator< GUM_SCALAR >::contains(), gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::domainSize(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges(), gum::Potential< GUM_SCALAR >::entropy(), gum::MultiDimDecorator< GUM_SCALAR >::erase(), gum::MultiDimDecorator< GUM_SCALAR >::fill(), gum::Potential< GUM_SCALAR >::findAll(), gum::MultiDimDecorator< GUM_SCALAR >::get(), gum::Potential< GUM_SCALAR >::margMaxIn(), gum::Potential< GUM_SCALAR >::margMaxOut(), gum::Potential< GUM_SCALAR >::margMinIn(), gum::Potential< GUM_SCALAR >::margMinOut(), gum::Potential< GUM_SCALAR >::margProdIn(), gum::Potential< GUM_SCALAR >::margProdOut(), gum::Potential< GUM_SCALAR >::margSumIn(), gum::Potential< GUM_SCALAR >::margSumOut(), gum::Potential< GUM_SCALAR >::max(), gum::Potential< GUM_SCALAR >::maxNonOne(), gum::Potential< GUM_SCALAR >::min(), gum::Potential< GUM_SCALAR >::minNonZero(), gum::MultiDimDecorator< GUM_SCALAR >::MultiDimDecorator(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), gum::Potential< GUM_SCALAR >::normalize(), gum::Potential< GUM_SCALAR >::normalizeAsCPT(), gum::MultiDimDecorator< GUM_SCALAR >::operator=(), gum::Potential< GUM_SCALAR >::operator==(), gum::MultiDimDecorator< GUM_SCALAR >::populate(), gum::MultiDimDecorator< GUM_SCALAR >::pos(), gum::Potential< GUM_SCALAR >::product(), gum::MultiDimDecorator< GUM_SCALAR >::reduce(), gum::MultiDimDecorator< GUM_SCALAR >::registerSlave(), gum::MultiDimDecorator< GUM_SCALAR >::set(), gum::MultiDimDecorator< GUM_SCALAR >::setChangeNotification(), gum::MultiDimDecorator< GUM_SCALAR >::setDecNotification(), gum::MultiDimDecorator< GUM_SCALAR >::setFirstNotification(), gum::MultiDimDecorator< GUM_SCALAR >::setIncNotification(), gum::MultiDimDecorator< GUM_SCALAR >::setLastNotification(), gum::Potential< GUM_SCALAR >::sum(), gum::MultiDimDecorator< GUM_SCALAR >::toString(), gum::MultiDimDecorator< GUM_SCALAR >::unregisterSlave(), gum::MultiDimDecorator< GUM_SCALAR >::variable(), gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence(), and gum::MultiDimDecorator< GUM_SCALAR >::~MultiDimDecorator().

◆ _empty_value

template<typename GUM_SCALAR>
GUM_SCALAR gum::MultiDimDecorator< GUM_SCALAR >::_empty_value
mutableprotectedinherited

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