![]() |
aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
|
aGrUM's Tensor is a multi-dimensional array with tensor operators. More...
#include <agrum/base/multidim/tensor.h>
Public Member Functions | |
Constructors, Destructors and Copy | |
| Tensor () | |
| Default constructor. | |
| Tensor (const std::vector< const DiscreteVariable * > &vars) | |
| Default constructor. | |
| Tensor (MultiDimImplementation< GUM_SCALAR > *aContent) | |
| Creates an tensor around aContent. | |
| Tensor (MultiDimImplementation< GUM_SCALAR > *aContent, const MultiDimContainer< GUM_SCALAR > &src) | |
| Copy constructor. | |
| Tensor (const Tensor< GUM_SCALAR > &src) | |
| Copy constructor & assignment. | |
| Tensor< GUM_SCALAR > & | operator= (const Tensor< GUM_SCALAR > &src) |
| Default constructor. | |
| Tensor (Tensor< GUM_SCALAR > &&from) | |
| move constructor & assignement | |
| Tensor< GUM_SCALAR > & | operator= (Tensor< GUM_SCALAR > &&src) |
| Default constructor. | |
| ~Tensor () final | |
| Destructor. | |
MultiDimContainer implementation | |
| Tensor< GUM_SCALAR > * | newFactory () const final |
| Default implementation of MultiDimContainer::set(). | |
Class operation for Tensor instances | |
| const Tensor< GUM_SCALAR > & | random () const |
| generate a random Tensor with each parameter in [0,1] | |
| const Tensor< GUM_SCALAR > & | randomDistribution () const |
| generate a random Distribution in the Tensor | |
| const Tensor< GUM_SCALAR > & | randomCPT () const |
| generate a random CPT in the Tensor | |
| const Tensor< GUM_SCALAR > & | noising (GUM_SCALAR alpha) const |
| add a noise in a CPT by mixing (1-alpha)this+alpha.randomCPT() | |
| Tensor< GUM_SCALAR > | sumOut (const gum::VariableSet &del_vars) const |
| Projection using sum as operation (and implementation-optimized operations). | |
| Tensor< GUM_SCALAR > | sumIn (const gum::VariableSet &kept_vars) const |
| Projection using sum as operation (and implementation-optimized operations). | |
| Tensor< GUM_SCALAR > | prodOut (const gum::VariableSet &del_vars) const |
| Projection using multiplication as operation (and implementation-optimized operations). | |
| Tensor< GUM_SCALAR > | prodIn (const gum::VariableSet &kept_vars) const |
| Projection using multiplication as operation (and implementation-optimized operations). | |
| Tensor< GUM_SCALAR > | minOut (const gum::VariableSet &del_vars) const |
| Projection using min as operation (and implementation-optimized operations). | |
| Tensor< GUM_SCALAR > | minIn (const gum::VariableSet &kept_vars) const |
| Projection using min as operation (and implementation-optimized operations). | |
| Tensor< GUM_SCALAR > | maxOut (const gum::VariableSet &del_vars) const |
| Projection using max as operation (and implementation-optimized operations). | |
| Tensor< GUM_SCALAR > | maxIn (const gum::VariableSet &kept_vars) const |
| Projection using max as operation (and implementation-optimized operations). | |
| Tensor< GUM_SCALAR > | isNonZeroMap () const |
| create a boolean-like tensor using the predicate isNonZero | |
| GUM_SCALAR | sum () const |
| sum of all elements in the Tensor | |
| GUM_SCALAR | product () const |
| product of all elements in the Tensor | |
| GUM_SCALAR | max () const |
| max of all elements in the Tensor | |
| GUM_SCALAR | min () const |
| min of all elements in the Tensor | |
| GUM_SCALAR | maxNonOne () const |
| max of all non one elements in the Tensor | |
| GUM_SCALAR | minNonZero () const |
| min of all non zero elements in the Tensor | |
| Set< Instantiation > | findAll (GUM_SCALAR v) const |
| set of instantiation corresponding to the parameter v in the Tensor | |
| std::pair< Set< Instantiation >, GUM_SCALAR > | argmax () const |
| Pair of the set of instantiation corresponding to the max and this max in the Tensor. | |
| std::pair< Set< Instantiation >, GUM_SCALAR > | argmin () const |
| Pair of the set of instantiation corresponding to the min and this min in the Tensor. | |
| GUM_SCALAR | expectedValue (std::function< GUM_SCALAR(const gum::Instantiation &) >) const |
| ExpectedValue computes the expectation of f over *this. | |
| GUM_SCALAR | entropy () const |
| entropy of the Tensor | |
| GUM_SCALAR | mean () const |
| compute the mean of a numerical discrete random variable @raise | |
| GUM_SCALAR | variance () const |
| compute the variance of a numerical discrete random variable @raise | |
| GUM_SCALAR | stdDev () const |
| compute the stdDev of a numerical discrete random variable | |
| Tensor< GUM_SCALAR > | reorganize (const std::vector< const DiscreteVariable * > &vars) const |
| create a new Tensor with another order | |
| Tensor< GUM_SCALAR > | reorganize (const std::vector< std::string > &vars) const |
| create a new Tensor with another order | |
| Tensor< GUM_SCALAR > | extract (const Instantiation &inst) const |
| create a new Tensor extracted from *this given a partial instantiation | |
| Tensor< GUM_SCALAR > | putFirst (const DiscreteVariable *var) const |
| create a new Tensor with a certain variable in first | |
| Tensor< GUM_SCALAR > | putFirst (std::string_view varname) const |
| create a new Tensor with a certain variable in first | |
| const Tensor< GUM_SCALAR > & | fillWith (const Tensor< GUM_SCALAR > &src) const |
| copy a Tensor data using name of variables and labels (not necessarily the same variables in the same orders) | |
| const Tensor< GUM_SCALAR > & | fillWith (const Tensor< GUM_SCALAR > &src, const std::vector< std::string > &mapSrc) const |
| copy a Tensor data using the sequence of names in mapSrc to find the corresponding variables. | |
| const Tensor< GUM_SCALAR > & | fillWith (const std::vector< GUM_SCALAR > &data) const |
| Automatically fills the tensor with the values in v. | |
| const Tensor< GUM_SCALAR > & | fillWith (const GUM_SCALAR &val) const |
| Automatically fills this MultiDimContainer with the value v. | |
| const Tensor< GUM_SCALAR > & | abs () const |
| Apply abs on every element of the container. | |
| const Tensor< GUM_SCALAR > & | sq () const |
| apply $x^2$ on every element of the container | |
| const Tensor< GUM_SCALAR > & | log2 () const |
| apply $log_2(x)$ on every element of the container | |
| const Tensor< GUM_SCALAR > & | sgn () const |
| apply sgn(x)$ on every element of the container | |
| Tensor< GUM_SCALAR > | new_abs () const |
| Create a new tensor and apply abs on every element of the container. | |
| Tensor< GUM_SCALAR > | new_sq () const |
| Create a new tensor and apply $x^2$ on every element of the container. | |
| Tensor< GUM_SCALAR > | new_log2 () const |
| Create a new tensor and apply $log_2(x)$ on every element of the container. | |
| Tensor< GUM_SCALAR > | new_sgn () const |
| Create a new tensor and apply sgn(x)$ on every element of the container. | |
| const Tensor< GUM_SCALAR > & | normalize () const |
| normalisation of this do nothing if sum is 0 | |
| GUM_SCALAR | KL (const Tensor< GUM_SCALAR > &p) const |
| compute KL divergence between this and p Checks the compatibility and then compute KL divergence | |
| const Tensor< GUM_SCALAR > & | normalizeAsCPT (const Idx &varId=0) const |
| normalisation of this as a CPT for the variable varId | |
| const Tensor< GUM_SCALAR > & | scale (GUM_SCALAR v) const |
| multiply (each value of) *this by v | |
| const Tensor< GUM_SCALAR > & | translate (GUM_SCALAR v) const |
| add v to (each value of) *this | |
| const Tensor< GUM_SCALAR > & | inverse () const |
| the function to inverse (each value of) *this | |
| Idx | draw () const |
| get a value at random from a 1-D distribution | |
| Size | memoryFootprint () const |
| compute the (approximated) footprint in memory of the tensor | |
Tensor algebra operators | |
| Tensor< GUM_SCALAR > | operator+ (const Tensor< GUM_SCALAR > &p2) const |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > | operator+ (const GUM_SCALAR &v) const |
| the function to be used to add a GUM_SCALAR to a Tensor | |
| Tensor< GUM_SCALAR > | operator- (const Tensor< GUM_SCALAR > &p2) const |
| the function to be used to subtract two Tensors | |
| Tensor< GUM_SCALAR > | operator- (const GUM_SCALAR &v) const |
| the function to be used to substract a GUM_SCALAR from a Tensor | |
| Tensor< GUM_SCALAR > | operator* (const Tensor< GUM_SCALAR > &p2) const |
| the function to be used to multiply two Tensors | |
| Tensor< GUM_SCALAR > | operator* (const GUM_SCALAR &v) const |
| the function to be used to multiply a Tensor and a scalar | |
| Tensor< GUM_SCALAR > | operator/ (const Tensor< GUM_SCALAR > &p2) const |
| the function to be used to divide two Tensors | |
| Tensor< GUM_SCALAR > | operator/ (const GUM_SCALAR &v) const |
| the function to be used to divide a Tensor by a scalar | |
| Tensor< GUM_SCALAR > & | operator+= (const Tensor< GUM_SCALAR > &r) |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > & | operator+= (const GUM_SCALAR &v) |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > & | operator*= (const Tensor< GUM_SCALAR > &r) |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > & | operator*= (const GUM_SCALAR &v) |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > & | operator-= (const Tensor< GUM_SCALAR > &r) |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > & | operator-= (const GUM_SCALAR &v) |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > & | operator/= (const Tensor< GUM_SCALAR > &r) |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > & | operator/= (const GUM_SCALAR &v) |
| the function to be used to add two Tensors | |
| bool | isEvidence () const |
| is an evidence ? (marginal-like but has not to sum to 1) | |
| Tensor< GUM_SCALAR > | operator| (const Tensor< GUM_SCALAR > &p2) const |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > | operator& (const Tensor< GUM_SCALAR > &p2) const |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > | operator~ () const |
| the function to be used to add two Tensors | |
| bool | operator== (const Tensor< GUM_SCALAR > &r) const |
| the function to be used to add two Tensors | |
| Tensor< GUM_SCALAR > & | operator<< (const DiscreteVariable &v) |
| the function to be used to add two Tensors | |
| std::string | toString () const final |
| the function to be used to add two Tensors | |
MultiDimInterface implementation | |
| Idx | nbrDim () const final |
| Returns the number of vars in the multidimensional container. | |
| Size | domainSize () const final |
| Returns the product of the variables domain size. | |
| void | add (const DiscreteVariable &v) final |
| Adds a new var to the variables of the multidimensional matrix. | |
| void | erase (const DiscreteVariable &var) final |
| Removes a var from the variables of the multidimensional matrix. | |
| const Sequence< const DiscreteVariable * > & | variablesSequence () const final |
| Returns a const ref to the sequence of DiscreteVariable*. | |
| const DiscreteVariable & | variable (Idx) const final |
| Returns a const ref to the ith var. | |
| Idx | pos (const DiscreteVariable &var) const final |
| Returns the index of a variable. | |
| bool | contains (const DiscreteVariable &var) const final |
| Returns true if var is in *this. | |
| bool | empty () const final |
| Returns true if no var is in *this. | |
Accessors / Modifiers | |
| virtual const DiscreteVariable & | variable (std::string_view name) const =0 |
| Returns the variable with the name. | |
| virtual const DiscreteVariable & | variable (std::string_view name) const=0 |
| Returns the variable with the name. | |
| void | replace (const DiscreteVariable &x, const DiscreteVariable &y) |
| Replace variables in this multidim. | |
MultiDimAddressable implementation | |
| bool | unregisterSlave (Instantiation &i) final |
| Unregister i as a slave of this MultiDimAdressable. | |
| bool | registerSlave (Instantiation &i) final |
| Register i as a slave of this MultiDimAdressable. | |
| void | changeNotification (const Instantiation &i, const DiscreteVariable *const var, Idx oldval, Idx newval) final |
| Listen to changes in a given Instantiation. | |
| void | setChangeNotification (const Instantiation &i) final |
| Listen to an assignment of a value in a Instantiation. | |
| void | setFirstNotification (const Instantiation &i) final |
| Listen to setFirst in a given Instantiation. | |
| void | setLastNotification (const Instantiation &i) final |
| Listen to setLast in a given Instantiation. | |
| void | setIncNotification (const Instantiation &i) final |
| Listen to increment in a given Instantiation. | |
| void | setDecNotification (const Instantiation &i) final |
| Listen to increment in each recorded Instantiation. | |
| virtual void | notifyChange () const final |
MultiDimContainer implementation | |
| void | set (const Instantiation &i, const GUM_SCALAR &value) const final |
| Default implementation of MultiDimContainer::set(). | |
| GUM_SCALAR | get (const Instantiation &i) const final |
| Default implementation of MultiDimContainer::get(). | |
| void | fill (const GUM_SCALAR &d) const final |
| Default implementation of MultiDimContainer::set(). | |
| void | populate (const std::vector< GUM_SCALAR > &v) const final |
| Automatically fills this MultiDimContainer with the values in v. | |
| void | apply (std::function< GUM_SCALAR(GUM_SCALAR) > f) const final |
| Apply a function on every element of the container. | |
| GUM_SCALAR | reduce (std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const final |
| compute lfold for this container | |
| void | beginMultipleChanges () final |
| Default implementation of MultiDimContainer::set(). | |
| void | endMultipleChanges () final |
| Default implementation of MultiDimContainer::set(). | |
| std::string | toString (const Instantiation *i) const override |
| Default implementation of MultiDimContainer::set(). | |
Accessors / Modifiers | |
| virtual void | populate (std::initializer_list< GUM_SCALAR > l) const |
| Automatically fills this MultiDimContainer with the values in l. | |
| GUM_SCALAR | operator[] (const Instantiation &i) const |
| An [] operator using a Instantiation as argument. | |
Various methods. | |
| const MultiDimImplementation< GUM_SCALAR > * | content () const final |
| Returns the implementation for this object (may be *this). | |
Copy methods. | |
| virtual void | copyFrom (const MultiDimContainer< GUM_SCALAR > &src) const |
| Basic copy of a MultiDimContainer. | |
| virtual void | copyFrom (const MultiDimContainer< GUM_SCALAR > &src, Instantiation *p_i) const |
| Basic copy of a MultiDimContainer. | |
| virtual void | extractFrom (const MultiDimContainer< GUM_SCALAR > &src, const Instantiation &mask) |
| Basic extraction of a MultiDimContainer. | |
| MultiDimAdressable & | getMasterRef () override |
| In order to insure the dereference for decorators, we need to virtualize the access to master pointer. | |
| const MultiDimAdressable & | getMasterRef () const override |
| In order to insure the dereference for decorators, we need to virtualize the access to master pointer. | |
| virtual void | copy (const MultiDimContainer< GUM_SCALAR > &src) |
| Removes all variables in this MultiDimContainer and copy the content of src, variables included. | |
Various methods. | |
| bool | operator== (const MultiDimContainer< GUM_SCALAR > &p) const |
| Test if this MultiDimContainer is equal to p. | |
Static Public Member Functions | |
| static Tensor< GUM_SCALAR > | deterministicTensor (const DiscreteVariable &var, Idx value) |
| static Tensor< GUM_SCALAR > | deterministicTensor (const DiscreteVariable &var, std::string_view label) |
| static Tensor< GUM_SCALAR > | uniformTensor (const DiscreteVariable &var) |
| static Tensor< GUM_SCALAR > | evEq (const DiscreteVariable &v, double val) |
| numerical evidence generator | |
| static Tensor< GUM_SCALAR > | evIn (const DiscreteVariable &v, double val1, double val2) |
| numerical evidence generator | |
| static Tensor< GUM_SCALAR > | evGt (const DiscreteVariable &v, double val) |
| numerical evidence generator | |
| static Tensor< GUM_SCALAR > | evLt (const DiscreteVariable &v, double val) |
| numerical evidence generator | |
Protected Member Functions | |
| void | replace_ (const DiscreteVariable *x, const DiscreteVariable *y) override |
| This is called by MultiDimContainer::replace() to proceed with the replacing between x and y. | |
| void | swapContent_ (MultiDimImplementation< GUM_SCALAR > *aContent) const |
| protected method to swap the implementation behind the Tensor | |
| GUM_SCALAR & | get_ (const Instantiation &i) const final |
| Return a data, given a Instantiation - final method. | |
Protected Attributes | |
| MultiDimImplementation< GUM_SCALAR > * | content_ |
| The true container. | |
| GUM_SCALAR | empty_value_ |
| value of the MultiDimDecorator if no dimension. | |
Private Member Functions | |
| gum::VariableSet | _complementVars_ (const gum::VariableSet &del_vars) const |
aGrUM's Tensor 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.
| GUM_SCALAR | The type of the scalar stored in this multidimensional matrix. |
| gum::Tensor< GUM_SCALAR >::Tensor | ( | ) |
Default constructor.
Creates an empty null dimensional matrix with a MultiDimArray as its implementation.
Definition at line 62 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::MultiDimDecorator(), and Tensor().
Referenced by Tensor(), Tensor(), Tensor(), Tensor(), Tensor(), abs(), and operator=().
| gum::Tensor< GUM_SCALAR >::Tensor | ( | const std::vector< const DiscreteVariable * > & | vars | ) |
Default constructor.
Creates an empty null dimensional matrix with a MultiDimArray as its implementation and add the vars
Definition at line 70 of file tensor_tpl.h.
References Tensor(), and gum::MultiDimDecorator< GUM_SCALAR >::add().
|
explicit |
Creates an tensor around aContent.
| aContent | The implementation of this Tensor. |
Definition at line 78 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::MultiDimDecorator(), and Tensor().
| gum::Tensor< GUM_SCALAR >::Tensor | ( | MultiDimImplementation< GUM_SCALAR > * | aContent, |
| const MultiDimContainer< GUM_SCALAR > & | src ) |
Copy constructor.
The newly created Tensor 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.
| aContent | The implementation to use in this Tensor. |
| src | The MultiDimContainer to copy. |
Definition at line 104 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::MultiDimDecorator(), Tensor(), gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::MultiDimDecorator< GUM_SCALAR >::beginMultipleChanges(), gum::MultiDimContainer< GUM_ELEMENT >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimContainer< GUM_ELEMENT >::copyFrom(), gum::MultiDimInterface::empty(), gum::MultiDimDecorator< GUM_SCALAR >::endMultipleChanges(), and gum::MultiDimInterface::variablesSequence().
| gum::Tensor< GUM_SCALAR >::Tensor | ( | const Tensor< GUM_SCALAR > & | src | ) |
Copy constructor & assignment.
Definition at line 86 of file tensor_tpl.h.
| gum::Tensor< GUM_SCALAR >::Tensor | ( | Tensor< GUM_SCALAR > && | from | ) |
move constructor & assignement
move constructor
Definition at line 97 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::MultiDimDecorator(), and Tensor().
|
final |
Destructor.
Definition at line 144 of file tensor_tpl.h.
|
nodiscardprivate |
Definition at line 647 of file tensor_tpl.h.
References gum::Set< Key >::contains(), gum::Set< Key >::insert(), and gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence().
Referenced by maxIn(), minIn(), prodIn(), and sumIn().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::abs | ( | ) | const |
Apply abs on every element of the container.
Definition at line 421 of file tensor_tpl.h.
References Tensor(), abs(), and gum::MultiDimDecorator< GUM_SCALAR >::apply().
Referenced by abs().
|
finalvirtualinherited |
Adds a new var to the variables of the multidimensional matrix.
| v | The new var. |
| DuplicateElement | Raised if the variable already belongs to the sequence of variables. |
| OperationNotAllowed | Raised if this object is non mutable. |
Implements gum::MultiDimInterface.
Definition at line 130 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::Tensor(), gum::Tensor< GUM_SCALAR >::Tensor(), and gum::Counterfactual< GUM_ELEMENT >::_adaptToOriginalVariables_().
|
finalvirtualinherited |
Apply a function on every element of the container.
| f | the function to apply |
Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 218 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::abs(), gum::Tensor< GUM_SCALAR >::log2(), and gum::Tensor< GUM_SCALAR >::sgn().
| std::pair< Set< Instantiation >, GUM_SCALAR > gum::Tensor< GUM_SCALAR >::argmax | ( | ) | const |
Pair of the set of instantiation corresponding to the max and this max in the Tensor.
Definition at line 772 of file tensor_tpl.h.
References findAll(), and max().
| std::pair< Set< Instantiation >, GUM_SCALAR > gum::Tensor< GUM_SCALAR >::argmin | ( | ) | const |
Pair of the set of instantiation corresponding to the min and this min in the Tensor.
Definition at line 779 of file tensor_tpl.h.
References findAll(), and min().
|
finalvirtualinherited |
Default implementation of MultiDimContainer::set().
Calls get_ as a r-value.
Implements gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 230 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::Tensor().
|
finalvirtualinherited |
Listen to changes in a given Instantiation.
| i | The Instantiation to listen. |
| var | The changed dim. |
| oldval | The old value. |
| newval | The changed value. |
Implements gum::MultiDimAdressable.
Definition at line 155 of file multiDimDecorator_tpl.h.
|
finalvirtualinherited |
Returns true if var is in *this.
| v | A DiscreteVariable. |
Implements gum::MultiDimInterface.
Definition at line 141 of file multiDimDecorator_tpl.h.
|
finalvirtualinherited |
Returns the implementation for this object (may be *this).
Implements gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 250 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::Tensor(), gum::Tensor< GUM_SCALAR >::max(), gum::Tensor< GUM_SCALAR >::maxIn(), gum::Tensor< GUM_SCALAR >::maxOut(), gum::Tensor< GUM_SCALAR >::memoryFootprint(), gum::Tensor< GUM_SCALAR >::minIn(), gum::Tensor< GUM_SCALAR >::minOut(), gum::Tensor< GUM_SCALAR >::newFactory(), gum::Tensor< GUM_SCALAR >::operator*(), gum::Tensor< GUM_SCALAR >::operator+(), gum::Tensor< GUM_SCALAR >::operator-(), gum::Tensor< GUM_SCALAR >::operator/(), gum::Tensor< GUM_SCALAR >::prodIn(), gum::Tensor< GUM_SCALAR >::prodOut(), gum::Tensor< GUM_SCALAR >::sum(), gum::Tensor< GUM_SCALAR >::sumIn(), and gum::Tensor< GUM_SCALAR >::toString().
|
virtualinherited |
Removes all variables in this MultiDimContainer and copy the content of src, variables included.
| src | The MultiDimContainer to copy. |
Definition at line 314 of file multiDimContainer_tpl.h.
|
virtualinherited |
Basic copy of a MultiDimContainer.
This method is virtual because it should be optimized in certain MultiDimContainer.
| src | The MultiDimContainer src which values are copied. This is a full copy with no verification of dimensions. |
| OperationNotAllowed | Raised if src does not have the same domain size than this MultiDimContainer. |
Definition at line 250 of file multiDimContainer_tpl.h.
|
virtualinherited |
Basic copy of a MultiDimContainer.
This method is virtual because it should be optimized in certain MultiDimContainer.
| src | The MultiDimContainer src which values are copied. |
| p_i | Give the order to iterate in this MultiDimContainer during the copy (nullptr will correctly copy if this is a reorganization of src). |
| OperationNotAllowed | Raised if src does not have the same domain size than this MultiDimContainer. |
Definition at line 266 of file multiDimContainer_tpl.h.
|
static |
Definition at line 1206 of file tensor_tpl.h.
References gum::Instantiation::chgVal().
Referenced by gum::GraphicalModelInference< GUM_SCALAR >::_createHardEvidence_(), and deterministicTensor().
|
static |
Definition at line 1222 of file tensor_tpl.h.
References deterministicTensor(), and gum::DiscreteVariable::index().
|
finalvirtualinherited |
Returns the product of the variables domain size.
Implements gum::MultiDimInterface.
Definition at line 128 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::random(), gum::Tensor< GUM_SCALAR >::randomCPT(), and gum::Tensor< GUM_SCALAR >::randomDistribution().
|
nodiscard |
get a value at random from a 1-D distribution
Definition at line 736 of file tensor_tpl.h.
References gum::Instantiation::end(), gum::MultiDimDecorator< GUM_SCALAR >::get(), 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_().
|
finalvirtualinherited |
Returns true if no var is in *this.
Implements gum::MultiDimInterface.
Definition at line 143 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::max(), gum::Tensor< GUM_SCALAR >::maxIn(), gum::Tensor< GUM_SCALAR >::maxNonOne(), gum::Tensor< GUM_SCALAR >::maxOut(), gum::Tensor< GUM_SCALAR >::min(), gum::Tensor< GUM_SCALAR >::minIn(), gum::Tensor< GUM_SCALAR >::minOut(), gum::Tensor< GUM_SCALAR >::normalize(), gum::Tensor< GUM_SCALAR >::normalizeAsCPT(), gum::Tensor< GUM_SCALAR >::operator*(), gum::Tensor< GUM_SCALAR >::operator+(), gum::Tensor< GUM_SCALAR >::operator-(), gum::Tensor< GUM_SCALAR >::operator/(), gum::Tensor< GUM_SCALAR >::operator==(), gum::Tensor< GUM_SCALAR >::prodIn(), gum::Tensor< GUM_SCALAR >::prodOut(), gum::Tensor< GUM_SCALAR >::product(), gum::Tensor< GUM_SCALAR >::sum(), and gum::Tensor< GUM_SCALAR >::sumIn().
|
finalvirtualinherited |
Default implementation of MultiDimContainer::set().
Calls get_ as a r-value.
Implements gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 232 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::Tensor().
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::entropy | ( | ) | const |
entropy of the Tensor
Definition at line 283 of file tensor_tpl.h.
References expectedValue().
|
finalvirtualinherited |
Removes a var from the variables of the multidimensional matrix.
| OperationNotAllowed | Raised if this object is non mutable. |
| NotFound | Raised if v does not belong to this. |
Implements gum::MultiDimInterface.
Definition at line 132 of file multiDimDecorator_tpl.h.
References MultiDimDecorator().
|
static |
numerical evidence generator
Definition at line 1135 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_ELEMENT >::add(), gum::Instantiation::chgVal(), gum::DiscreteVariable::closestIndex(), fillWith(), and gum::MultiDimDecorator< GUM_ELEMENT >::set().
Referenced by gum::IBayesNet< GUM_SCALAR >::evEq(), evGt(), and evLt().
|
static |
numerical evidence generator
Definition at line 1169 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_ELEMENT >::add(), gum::Instantiation::chgVal(), gum::DiscreteVariable::closestIndex(), gum::DiscreteVariable::domainSize(), evEq(), fillWith(), and gum::MultiDimDecorator< GUM_ELEMENT >::set().
Referenced by gum::IBayesNet< GUM_SCALAR >::evGt().
|
static |
numerical evidence generator
Definition at line 1149 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_ELEMENT >::add(), gum::Instantiation::chgVal(), gum::DiscreteVariable::closestIndex(), fillWith(), GUM_ERROR, and gum::MultiDimDecorator< GUM_ELEMENT >::set().
Referenced by gum::IBayesNet< GUM_SCALAR >::evIn().
|
static |
numerical evidence generator
Definition at line 1185 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_ELEMENT >::add(), gum::Instantiation::chgVal(), gum::DiscreteVariable::closestIndex(), evEq(), fillWith(), and gum::MultiDimDecorator< GUM_ELEMENT >::set().
Referenced by gum::IBayesNet< GUM_SCALAR >::evLt().
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::expectedValue | ( | std::function< GUM_SCALAR(const gum::Instantiation &) > | f | ) | const |
ExpectedValue computes the expectation of f over *this.
ExpectedValue assumes (and does not check) that the Tensor contains a joint distribution.
Definition at line 233 of file tensor_tpl.h.
Referenced by entropy().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::extract | ( | const Instantiation & | inst | ) | const |
create a new Tensor extracted from *this given a partial instantiation
Definition at line 728 of file tensor_tpl.h.
|
virtualinherited |
Basic extraction of a MultiDimContainer.
This method is virtual because it should be optimized in certain MultiDimContainer.
| src | The MultiDimContainer src which datas are copied. |
| mask | partial instantiation of variables of the Tensor : the |
extraction will concern every variable not in the instantiation and the copy of data will use the (relevant) values in this instantiation.
Definition at line 280 of file multiDimContainer_tpl.h.
|
finalvirtualinherited |
Default implementation of MultiDimContainer::set().
Calls get_ as a r-value.
Implements gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 192 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::fillWith().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::fillWith | ( | const GUM_SCALAR & | val | ) | const |
Automatically fills this MultiDimContainer with the value v.
| v | contains the data. |
Definition at line 297 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::fill().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::fillWith | ( | const std::vector< GUM_SCALAR > & | data | ) | const |
Automatically fills the tensor with the values in v.
| v | Vector of values. |
| SizeError | Raised if v size's does not matches this MultiDimContainer domain size. |
Definition at line 291 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::populate().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::fillWith | ( | const Tensor< GUM_SCALAR > & | src | ) | const |
copy a Tensor data using name of variables and labels (not necessarily the same variables in the same orders)
| InvalidArgument | if the Tensor is not compatible with this |
Definition at line 304 of file tensor_tpl.h.
References GUM_ERROR, and gum::Set< Key >::insert().
Referenced by gum::Counterfactual< GUM_ELEMENT >::_adaptToOriginalVariables_(), gum::DecisionTensor< GUM_SCALAR >::clear(), evEq(), evGt(), evIn(), evLt(), noising(), random(), randomCPT(), and randomDistribution().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::fillWith | ( | const Tensor< GUM_SCALAR > & | src, |
| const std::vector< std::string > & | mapSrc ) const |
copy a Tensor data using the sequence of names in mapSrc to find the corresponding variables.
For instance, to copy the tensor 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):
| InvalidArgument | if the Tensor is not compatible with this |
Definition at line 346 of file tensor_tpl.h.
References gum::Instantiation::add(), gum::Instantiation::end(), GUM_ERROR, gum::MultiDimDecorator< GUM_SCALAR >::set(), gum::Instantiation::setFirst(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().
| Set< Instantiation > gum::Tensor< GUM_SCALAR >::findAll | ( | GUM_SCALAR | v | ) | const |
set of instantiation corresponding to the parameter v in the Tensor
Definition at line 758 of file tensor_tpl.h.
References gum::Instantiation::end(), gum::MultiDimDecorator< GUM_SCALAR >::get(), gum::Set< Key >::insert(), and gum::Instantiation::setFirst().
Referenced by argmax(), and argmin().
|
finalvirtualinherited |
Default implementation of MultiDimContainer::get().
Calls get_ as a l-value.
Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 190 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::draw(), gum::Tensor< GUM_SCALAR >::findAll(), setIncNotification(), and gum::Tensor< GUM_SCALAR >::toString().
|
finalprotectedvirtualinherited |
Return a data, given a Instantiation - final method.
| i | The instantiation. |
| NullElement | |
| NotFound |
Implements gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 279 of file multiDimDecorator_tpl.h.
References gum::MultiDimContainer< GUM_SCALAR >::MultiDimContainer(), and content_.
|
overrideinherited |
In order to insure the dereference for decorators, we need to virtualize the access to master pointer.
Definition at line 305 of file multiDimContainer_tpl.h.
|
overrideinherited |
In order to insure the dereference for decorators, we need to virtualize the access to master pointer.
Definition at line 298 of file multiDimContainer_tpl.h.
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::inverse | ( | ) | const |
the function to inverse (each value of) *this
Definition at line 491 of file tensor_tpl.h.
|
nodiscard |
is an evidence ? (marginal-like but has not to sum to 1)
Definition at line 879 of file tensor_tpl.h.
References max(), min(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), and sum().
Referenced by operator&(), operator|(), and operator~().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::isNonZeroMap | ( | ) | const |
create a boolean-like tensor using the predicate isNonZero
Definition at line 637 of file tensor_tpl.h.
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::KL | ( | const Tensor< GUM_SCALAR > & | p | ) | const |
compute KL divergence between this and p Checks the compatibility and then compute KL divergence
| gum::InvalidArgument | if p is not compatible with $this (dimension, variables) |
| gum::FatalError | if a zero is found in p or this and not in the other. |
Definition at line 391 of file tensor_tpl.h.
References gum::contains(), GUM_ERROR, and gum::MultiDimDecorator< GUM_SCALAR >::nbrDim().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::log2 | ( | ) | const |
apply $log_2(x)$ on every element of the container
Definition at line 379 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::apply().
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::max | ( | ) | const |
max of all elements in the Tensor
Definition at line 175 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, and gum::projectMax().
Referenced by argmax(), isEvidence(), maxIn(), and maxOut().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::maxIn | ( | const gum::VariableSet & | kept_vars | ) | const |
Projection using max as operation (and implementation-optimized operations).
| kept_vars | is the set of vars to keep |
Definition at line 624 of file tensor_tpl.h.
References _complementVars_(), gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Set< Key >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, max(), and gum::projectMax().
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::maxNonOne | ( | ) | const |
max of all non one elements in the Tensor
Definition at line 194 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, and gum::MultiDimDecorator< GUM_SCALAR >::reduce().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::maxOut | ( | const gum::VariableSet & | del_vars | ) | const |
Projection using max as operation (and implementation-optimized operations).
| del_vars | is the set of vars to eliminate |
Definition at line 563 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, gum::Set< Key >::exists(), max(), gum::projectMax(), gum::Set< Key >::size(), and gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence().
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::mean | ( | ) | const |
compute the mean of a numerical discrete random variable @raise
Definition at line 249 of file tensor_tpl.h.
References GUM_ERROR, gum::isCloseToOne(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), and sum().
| Size gum::Tensor< GUM_SCALAR >::memoryFootprint | ( | ) | const |
compute the (approximated) footprint in memory of the tensor
Definition at line 1201 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content().
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::min | ( | ) | const |
min of all elements in the Tensor
Definition at line 184 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::MultiDimDecorator< GUM_SCALAR >::empty_value_.
Referenced by argmin(), isEvidence(), minIn(), and minOut().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::minIn | ( | const gum::VariableSet & | kept_vars | ) | const |
Projection using min as operation (and implementation-optimized operations).
| kept_vars | is the set of vars to keep |
Definition at line 611 of file tensor_tpl.h.
References _complementVars_(), gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Set< Key >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, min(), and gum::projectMin().
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::minNonZero | ( | ) | const |
min of all non zero elements in the Tensor
Definition at line 215 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::minOut | ( | const gum::VariableSet & | del_vars | ) | const |
Projection using min as operation (and implementation-optimized operations).
| del_vars | is the set of vars to eliminate |
Definition at line 541 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, gum::Set< Key >::exists(), min(), gum::projectMin(), gum::Set< Key >::size(), and gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence().
|
finalvirtualinherited |
Returns the number of vars in the multidimensional container.
Implements gum::MultiDimInterface.
Definition at line 126 of file multiDimDecorator_tpl.h.
References content_, and empty_value_.
Referenced by gum::Tensor< GUM_SCALAR >::draw(), gum::Tensor< GUM_SCALAR >::isEvidence(), gum::Tensor< GUM_SCALAR >::KL(), gum::Tensor< GUM_SCALAR >::mean(), gum::Tensor< GUM_SCALAR >::putFirst(), gum::Tensor< GUM_SCALAR >::putFirst(), gum::Tensor< GUM_SCALAR >::reorganize(), and gum::Tensor< GUM_SCALAR >::variance().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::new_abs | ( | ) | const |
Create a new tensor and apply abs on every element of the container.
Definition at line 837 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::new_log2 | ( | ) | const |
Create a new tensor and apply $log_2(x)$ on every element of the container.
Definition at line 847 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::new_sgn | ( | ) | const |
Create a new tensor and apply sgn(x)$ on every element of the container.
fill the tensor with -1 for a GUM_SCALAR<0,1 if >0 and 0 if ==0
Definition at line 852 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::new_sq | ( | ) | const |
Create a new tensor and apply $x^2$ on every element of the container.
Definition at line 842 of file tensor_tpl.h.
|
nodiscardfinalvirtual |
Default implementation of MultiDimContainer::set().
Calls get_ as a r-value.
Implements gum::MultiDimDecorator< GUM_SCALAR >.
Definition at line 150 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), and newFactory().
Referenced by newFactory().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::noising | ( | GUM_SCALAR | alpha | ) | const |
add a noise in a CPT by mixing (1-alpha)this+alpha.randomCPT()
Definition at line 828 of file tensor_tpl.h.
References fillWith(), GUM_ERROR, and scale().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::normalize | ( | ) | const |
normalisation of this do nothing if sum is 0
Definition at line 432 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, and sum().
Referenced by gum::GibbsOperator< GUM_SCALAR >::_GibbsSample_().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::normalizeAsCPT | ( | const Idx & | varId = 0 | ) | const |
normalisation of this as a CPT for the variable varId
If the Tensor is empty, the argument is not used.
| FatalError | it some distribution sums to 0, or if varId>=nbrDim() |
Definition at line 447 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::MultiDimDecorator< GUM_SCALAR >::empty_value_.
|
finalvirtualinherited |
Definition at line 170 of file multiDimDecorator_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator& | ( | const Tensor< GUM_SCALAR > & | p2 | ) | const |
the function to be used to add two Tensors
Definition at line 902 of file tensor_tpl.h.
References gum::Instantiation::end(), GUM_ERROR, isEvidence(), gum::Instantiation::setFirst(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator* | ( | const GUM_SCALAR & | v | ) | const |
the function to be used to multiply a Tensor and a scalar
Definition at line 957 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator* | ( | const Tensor< GUM_SCALAR > & | p2 | ) | const |
the function to be used to multiply two Tensors
Definition at line 948 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::MultiDimDecorator< GUM_SCALAR >::empty_value_.
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator*= | ( | const GUM_SCALAR & | v | ) |
the function to be used to add two Tensors
Definition at line 998 of file tensor_tpl.h.
References scale().
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator*= | ( | const Tensor< GUM_SCALAR > & | r | ) |
the function to be used to add two Tensors
Definition at line 992 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator+ | ( | const GUM_SCALAR & | v | ) | const |
the function to be used to add a GUM_SCALAR to a Tensor
Definition at line 873 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator+ | ( | const Tensor< GUM_SCALAR > & | p2 | ) | const |
the function to be used to add two Tensors
Definition at line 864 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::MultiDimDecorator< GUM_SCALAR >::empty_value_.
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator+= | ( | const GUM_SCALAR & | v | ) |
the function to be used to add two Tensors
Definition at line 986 of file tensor_tpl.h.
References translate().
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator+= | ( | const Tensor< GUM_SCALAR > & | r | ) |
the function to be used to add two Tensors
Definition at line 980 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator- | ( | const GUM_SCALAR & | v | ) | const |
the function to be used to substract a GUM_SCALAR from a Tensor
Definition at line 942 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator- | ( | const Tensor< GUM_SCALAR > & | p2 | ) | const |
the function to be used to subtract two Tensors
Definition at line 930 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::MultiDimDecorator< GUM_SCALAR >::empty_value_.
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator-= | ( | const GUM_SCALAR & | v | ) |
the function to be used to add two Tensors
Definition at line 1010 of file tensor_tpl.h.
References translate().
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator-= | ( | const Tensor< GUM_SCALAR > & | r | ) |
the function to be used to add two Tensors
Definition at line 1004 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator/ | ( | const GUM_SCALAR & | v | ) | const |
the function to be used to divide a Tensor by a scalar
Definition at line 975 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator/ | ( | const Tensor< GUM_SCALAR > & | p2 | ) | const |
the function to be used to divide two Tensors
Definition at line 963 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::MultiDimDecorator< GUM_SCALAR >::empty_value_.
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator/= | ( | const GUM_SCALAR & | v | ) |
the function to be used to add two Tensors
Definition at line 1022 of file tensor_tpl.h.
References scale().
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator/= | ( | const Tensor< GUM_SCALAR > & | r | ) |
the function to be used to add two Tensors
Definition at line 1016 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator<< | ( | const DiscreteVariable & | v | ) |
the function to be used to add two Tensors
Definition at line 852 of file tensor_tpl.h.
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator= | ( | const Tensor< GUM_SCALAR > & | src | ) |
Default constructor.
Creates an empty null dimensional matrix with a MultiDimArray as its implementation.
Definition at line 124 of file tensor_tpl.h.
References Tensor(), and gum::MultiDimDecorator< GUM_ELEMENT >::operator=().
| Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::operator= | ( | Tensor< GUM_SCALAR > && | src | ) |
Default constructor.
Creates an empty null dimensional matrix with a MultiDimArray as its implementation.
Definition at line 133 of file tensor_tpl.h.
|
inherited |
Test if this MultiDimContainer is equal to p.
| p | The MultiDimContainer to test for equality. |
Definition at line 359 of file multiDimContainer_tpl.h.
| bool gum::Tensor< GUM_SCALAR >::operator== | ( | const Tensor< GUM_SCALAR > & | r | ) | const |
the function to be used to add two Tensors
Definition at line 1028 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), and gum::MultiDimDecorator< GUM_SCALAR >::empty_value_.
|
inherited |
An [] operator using a Instantiation as argument.
| i | An Instantiation. |
Definition at line 184 of file multiDimContainer_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator| | ( | const Tensor< GUM_SCALAR > & | p2 | ) | const |
the function to be used to add two Tensors
Definition at line 887 of file tensor_tpl.h.
References gum::Instantiation::end(), GUM_ERROR, isEvidence(), gum::Instantiation::setFirst(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::operator~ | ( | ) | const |
the function to be used to add two Tensors
Definition at line 917 of file tensor_tpl.h.
References gum::Instantiation::end(), GUM_ERROR, isEvidence(), and gum::Instantiation::setFirst().
|
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.
| v | Vector of values. |
| SizeError | Raised if v size's does not matches this MultiDimContainer domain size. |
Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 212 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::fillWith().
|
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.
| l | contains the data. |
| SizeError | Raised if l size's does not matches this MultiDimContainer domain size. |
Definition at line 230 of file multiDimContainer_tpl.h.
|
finalvirtualinherited |
Returns the index of a variable.
| v | The variable for which the index is returned. |
| NotFound | Raised if v is not in this multidimensional matrix. |
Implements gum::MultiDimInterface.
Definition at line 139 of file multiDimDecorator_tpl.h.
References content_, and newFactory().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::prodIn | ( | const gum::VariableSet & | kept_vars | ) | const |
Projection using multiplication as operation (and implementation-optimized operations).
| kept_vars | is the set of vars to keep |
Definition at line 598 of file tensor_tpl.h.
References _complementVars_(), gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Set< Key >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, product(), and gum::projectProduct().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::prodOut | ( | const gum::VariableSet & | del_vars | ) | const |
Projection using multiplication as operation (and implementation-optimized operations).
| del_vars | is the set of vars to eliminate |
Definition at line 519 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, gum::Set< Key >::exists(), product(), gum::projectProduct(), gum::Set< Key >::size(), and gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence().
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::product | ( | ) | const |
product of all elements in the Tensor
Definition at line 166 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content_, and gum::MultiDimDecorator< GUM_SCALAR >::empty().
Referenced by prodIn(), and prodOut().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::putFirst | ( | const DiscreteVariable * | var | ) | const |
create a new Tensor with a certain variable in first
| InvalidArgument | if the var is not in the tensor |
Definition at line 698 of file tensor_tpl.h.
References gum::contains(), GUM_ERROR, gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), reorganize(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().
Referenced by putFirst().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::putFirst | ( | std::string_view | varname | ) | const |
create a new Tensor with a certain variable in first
| InvalidArgument | if the var is not in the tensor |
Definition at line 713 of file tensor_tpl.h.
References GUM_ERROR, gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), putFirst(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::random | ( | ) | const |
generate a random Tensor with each parameter in [0,1]
Definition at line 785 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::domainSize(), fillWith(), and gum::randomProba().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::randomCPT | ( | ) | const |
generate a random CPT in the Tensor
Definition at line 810 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::domainSize(), gum::Instantiation::end(), fillWith(), gum::Instantiation::incNotVar(), gum::Instantiation::incVar(), gum::randomDistribution(), gum::MultiDimDecorator< GUM_SCALAR >::set(), gum::Instantiation::setFirstNotVar(), gum::Instantiation::setFirstVar(), gum::Instantiation::unsetEnd(), gum::Instantiation::val(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::randomDistribution | ( | ) | const |
generate a random Distribution in the Tensor
Definition at line 799 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::domainSize(), fillWith(), and gum::randomDistribution().
|
finalvirtualinherited |
compute lfold for this container
| f | the function to apply |
| base | the initial value |
Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 225 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::maxNonOne().
|
finalvirtualinherited |
Register i as a slave of this MultiDimAdressable.
| i | The Instantiation to enslave. |
Implements gum::MultiDimAdressable.
Definition at line 153 of file multiDimDecorator_tpl.h.
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::reorganize | ( | const std::vector< const DiscreteVariable * > & | vars | ) | const |
create a new Tensor with another order
| InvalidArgument | if not all and only the vars of the tensor are in vars |
Definition at line 658 of file tensor_tpl.h.
References gum::contains(), and GUM_ERROR.
Referenced by putFirst(), and reorganize().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::reorganize | ( | const std::vector< std::string > & | vars | ) | const |
create a new Tensor with another order
| InvalidArgument | if not all and only the vars of the tensor are in vars |
Definition at line 680 of file tensor_tpl.h.
References gum::HashTable< Key, Val >::exists(), GUM_ERROR, gum::HashTable< Key, Val >::insert(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), and reorganize().
|
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.
| x | The variable in this which will be replaced. |
| y | The variable replacing y. |
| NotFound | Raised if x does not belong to this MultiDim. |
| OperationNotAllowed | If y and x are not interchangeable. |
| DuplicateElement | If y is already in this MultiDim. |
Definition at line 190 of file multiDimInterface_inl.h.
|
overrideprotectedvirtualinherited |
This is called by MultiDimContainer::replace() to proceed with the replacing between x and y.
This is called only when everything have been checked.
| x | The variable to replace in |
| y | The second variable to swap. |
Implements gum::MultiDimInterface.
Definition at line 260 of file multiDimDecorator_tpl.h.
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::scale | ( | GUM_SCALAR | v | ) | const |
multiply (each value of) *this by v
Definition at line 479 of file tensor_tpl.h.
Referenced by noising(), operator*=(), and operator/=().
|
finalvirtualinherited |
Default implementation of MultiDimContainer::set().
Calls get_ as a r-value.
Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 183 of file multiDimDecorator_tpl.h.
Referenced by gum::Tensor< GUM_SCALAR >::fillWith(), and gum::Tensor< GUM_SCALAR >::randomCPT().
|
finalvirtualinherited |
Listen to an assignment of a value in a Instantiation.
| i | The Instantiation to listen. |
Implements gum::MultiDimAdressable.
Definition at line 160 of file multiDimDecorator_tpl.h.
|
finalvirtualinherited |
Listen to increment in each recorded Instantiation.
| i | The Instantiation to listen. |
Implements gum::MultiDimAdressable.
Definition at line 168 of file multiDimDecorator_tpl.h.
|
finalvirtualinherited |
Listen to setFirst in a given Instantiation.
| i | The Instantiation to listen. |
Implements gum::MultiDimAdressable.
Definition at line 162 of file multiDimDecorator_tpl.h.
|
finalvirtualinherited |
Listen to increment in a given Instantiation.
| i | The Instantiation to listen. |
Implements gum::MultiDimAdressable.
Definition at line 166 of file multiDimDecorator_tpl.h.
References gum::MultiDimContainer< GUM_SCALAR >::MultiDimContainer(), content_, and get().
|
finalvirtualinherited |
Listen to setLast in a given Instantiation.
| i | The Instantiation to listen. |
Implements gum::MultiDimAdressable.
Definition at line 164 of file multiDimDecorator_tpl.h.
References empty_value_.
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::sgn | ( | ) | const |
apply sgn(x)$ on every element of the container
fill the tensor with -1 for a GUM_SCALAR<0,1 if >0 and 0 if ==0
Definition at line 385 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::apply().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::sq | ( | ) | const |
apply $x^2$ on every element of the container
Definition at line 373 of file tensor_tpl.h.
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::stdDev | ( | ) | const |
compute the stdDev of a numerical discrete random variable
@raise
Definition at line 277 of file tensor_tpl.h.
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::sum | ( | ) | const |
sum of all elements in the Tensor
Definition at line 157 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, and gum::projectSum().
Referenced by gum::GibbsOperator< GUM_SCALAR >::_GibbsSample_(), isEvidence(), mean(), normalize(), sumIn(), and variance().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::sumIn | ( | const gum::VariableSet & | kept_vars | ) | const |
Projection using sum as operation (and implementation-optimized operations).
| kept_vars | is the set of vars to keep |
Definition at line 585 of file tensor_tpl.h.
References _complementVars_(), gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::MultiDimDecorator< GUM_SCALAR >::content_, gum::MultiDimDecorator< GUM_SCALAR >::empty(), gum::Set< Key >::empty(), gum::MultiDimDecorator< GUM_SCALAR >::empty_value_, gum::projectSum(), and sum().
| Tensor< GUM_SCALAR > gum::Tensor< GUM_SCALAR >::sumOut | ( | const gum::VariableSet & | del_vars | ) | const |
Projection using sum as operation (and implementation-optimized operations).
| del_vars | is the set of vars to eliminate |
Definition at line 497 of file tensor_tpl.h.
|
protectedinherited |
protected method to swap the implementation behind the Tensor
Definition at line 266 of file multiDimDecorator_tpl.h.
|
overridevirtualinherited |
Default implementation of MultiDimContainer::set().
Calls get_ as a r-value.
Implements gum::MultiDimAdressable.
Definition at line 236 of file multiDimDecorator_tpl.h.
|
nodiscardfinalvirtual |
the function to be used to add two Tensors
Reimplemented from gum::MultiDimContainer< GUM_SCALAR >.
Definition at line 1039 of file tensor_tpl.h.
References gum::MultiDimDecorator< GUM_SCALAR >::content(), gum::Instantiation::decNotVar(), gum::Instantiation::end(), gum::MultiDimDecorator< GUM_SCALAR >::get(), gum::Instantiation::incNotVar(), gum::Instantiation::incVar(), gum::Instantiation::setFirst(), gum::Instantiation::setFirstVar(), gum::Instantiation::setLast(), and gum::Instantiation::val().
| const Tensor< GUM_SCALAR > & gum::Tensor< GUM_SCALAR >::translate | ( | GUM_SCALAR | v | ) | const |
add v to (each value of) *this
Definition at line 485 of file tensor_tpl.h.
Referenced by operator+=(), and operator-=().
|
static |
Definition at line 1228 of file tensor_tpl.h.
|
finalvirtualinherited |
Unregister i as a slave of this MultiDimAdressable.
| i | The Instantiation to free. |
Implements gum::MultiDimAdressable.
Definition at line 151 of file multiDimDecorator_tpl.h.
References MultiDimDecorator().
|
pure virtualinherited |
Returns the variable with the name.
| name | The index of the variable |
| NotFound | Raised if the element cannot be found. |
|
finalvirtualinherited |
Returns a const ref to the ith var.
param i An index of this multidimensional matrix.
| NotFound | Raised if i does not reference a variable in this multidimensional matrix. |
Implements gum::MultiDimInterface.
Definition at line 136 of file multiDimDecorator_tpl.h.
References content_, and empty_value_.
Referenced by gum::Tensor< GUM_SCALAR >::draw(), gum::Tensor< GUM_SCALAR >::fillWith(), gum::Tensor< GUM_SCALAR >::operator&(), gum::Tensor< GUM_SCALAR >::operator|(), gum::Tensor< GUM_SCALAR >::putFirst(), gum::Tensor< GUM_SCALAR >::putFirst(), gum::Tensor< GUM_SCALAR >::randomCPT(), and gum::Tensor< GUM_SCALAR >::variance().
|
pure virtualinherited |
Returns the variable with the name.
| name | The index of the variable |
| NotFound | Raised if the element cannot be found. |
Implemented in gum::Instantiation, gum::MultiDimDecorator< GUM_ELEMENT >, gum::MultiDimImplementation< GUM_ELEMENT >, gum::MultiDimImplementation< GUM_ELEMENT > *(*)(const MultiDimImplementation< GUM_ELEMENT > *, const HashTable< const DiscreteVariable *, Idx > &), gum::MultiDimImplementation< GUM_ELEMENT > *(*)(const MultiDimImplementation< GUM_ELEMENT > *, const MultiDimImplementation< GUM_ELEMENT > *), and gum::VariableSet &)< GUM_ELEMENT >.
|
finalvirtualinherited |
Returns a const ref to the sequence of DiscreteVariable*.
Implements gum::MultiDimInterface.
Definition at line 135 of file multiDimDecorator_tpl.h.
Referenced by gum::Counterfactual< GUM_ELEMENT >::_adaptToOriginalVariables_(), gum::Tensor< GUM_SCALAR >::_complementVars_(), gum::Tensor< GUM_SCALAR >::maxOut(), gum::Tensor< GUM_SCALAR >::minOut(), and gum::Tensor< GUM_SCALAR >::prodOut().
| GUM_SCALAR gum::Tensor< GUM_SCALAR >::variance | ( | ) | const |
compute the variance of a numerical discrete random variable @raise
Definition at line 262 of file tensor_tpl.h.
References GUM_ERROR, gum::isCloseToOne(), gum::isNumerical(), gum::MultiDimDecorator< GUM_SCALAR >::nbrDim(), sum(), and gum::MultiDimDecorator< GUM_SCALAR >::variable().
|
mutableprotectedinherited |
The true container.
Definition at line 271 of file multiDimDecorator.h.
Referenced by get_(), gum::Tensor< GUM_SCALAR >::max(), gum::Tensor< GUM_SCALAR >::maxIn(), gum::Tensor< GUM_SCALAR >::maxNonOne(), gum::Tensor< GUM_SCALAR >::maxOut(), gum::Tensor< GUM_SCALAR >::min(), gum::Tensor< GUM_SCALAR >::minIn(), gum::Tensor< GUM_SCALAR >::minOut(), nbrDim(), gum::Tensor< GUM_SCALAR >::normalize(), gum::Tensor< GUM_SCALAR >::normalizeAsCPT(), gum::Tensor< GUM_SCALAR >::operator==(), pos(), gum::Tensor< GUM_SCALAR >::prodIn(), gum::Tensor< GUM_SCALAR >::prodOut(), gum::Tensor< GUM_SCALAR >::product(), setIncNotification(), gum::Tensor< GUM_SCALAR >::sum(), gum::Tensor< GUM_SCALAR >::sumIn(), and variable().
|
mutableprotectedinherited |
value of the MultiDimDecorator if no dimension.
Definition at line 285 of file multiDimDecorator.h.
Referenced by gum::Tensor< GUM_SCALAR >::max(), gum::Tensor< GUM_SCALAR >::maxIn(), gum::Tensor< GUM_SCALAR >::maxNonOne(), gum::Tensor< GUM_SCALAR >::maxOut(), gum::Tensor< GUM_SCALAR >::min(), gum::Tensor< GUM_SCALAR >::minIn(), gum::Tensor< GUM_SCALAR >::minOut(), nbrDim(), gum::Tensor< GUM_SCALAR >::normalize(), gum::Tensor< GUM_SCALAR >::normalizeAsCPT(), gum::Tensor< GUM_SCALAR >::operator*(), gum::Tensor< GUM_SCALAR >::operator+(), gum::Tensor< GUM_SCALAR >::operator-(), gum::Tensor< GUM_SCALAR >::operator/(), gum::Tensor< GUM_SCALAR >::operator==(), gum::Tensor< GUM_SCALAR >::prodIn(), gum::Tensor< GUM_SCALAR >::prodOut(), setLastNotification(), gum::Tensor< GUM_SCALAR >::sum(), gum::Tensor< GUM_SCALAR >::sumIn(), and variable().