84 template <
typename GUM_SCALAR >
89 const std::string& label);
110 Tensor(
const std::vector< const DiscreteVariable* >& vars);
133 Tensor(
const Tensor< GUM_SCALAR >& src);
134 Tensor< GUM_SCALAR >&
operator=(
const Tensor< GUM_SCALAR >& src);
139 Tensor(Tensor< GUM_SCALAR >&& from);
140 Tensor< GUM_SCALAR >&
operator=(Tensor< GUM_SCALAR >&& src);
154 Tensor< GUM_SCALAR >*
newFactory()
const final;
162 const Tensor< GUM_SCALAR >&
random()
const;
168 const Tensor< GUM_SCALAR >&
randomCPT()
const;
173 const Tensor< GUM_SCALAR >&
noising(GUM_SCALAR alpha)
const;
237 GUM_SCALAR
sum()
const;
241 GUM_SCALAR
max()
const;
243 GUM_SCALAR
min()
const;
255 std::pair< Set< Instantiation >, GUM_SCALAR >
argmax()
const;
258 std::pair< Set< Instantiation >, GUM_SCALAR >
argmin()
const;
275 Tensor< GUM_SCALAR >
reorganize(
const std::vector< const DiscreteVariable* >& vars)
const;
281 Tensor< GUM_SCALAR >
reorganize(
const std::vector< std::string >& vars)
const;
296 Tensor< GUM_SCALAR >
putFirst(
const std::string& varname)
const;
306 const Tensor< GUM_SCALAR >&
fillWith(
const Tensor< GUM_SCALAR >& src)
const;
324 const Tensor< GUM_SCALAR >&
fillWith(
const Tensor< GUM_SCALAR >& src,
325 const std::vector< std::string >& mapSrc)
const;
335 const Tensor< GUM_SCALAR >&
fillWith(
const std::vector< GUM_SCALAR >& data)
const;
342 const Tensor< GUM_SCALAR >&
fillWith(
const GUM_SCALAR& val)
const;
348 const Tensor< GUM_SCALAR >&
abs()
const;
353 const Tensor< GUM_SCALAR >&
sq()
const;
358 const Tensor< GUM_SCALAR >&
log2()
const;
365 const Tensor< GUM_SCALAR >&
sgn()
const;
371 Tensor< GUM_SCALAR >
new_abs()
const;
377 Tensor< GUM_SCALAR >
new_sq()
const;
383 Tensor< GUM_SCALAR >
new_log2()
const;
390 Tensor< GUM_SCALAR >
new_sgn()
const;
396 const Tensor< GUM_SCALAR >&
normalize()
const;
406 GUM_SCALAR
KL(
const Tensor< GUM_SCALAR >& p)
const;
420 const Tensor< GUM_SCALAR >&
scale(GUM_SCALAR v)
const;
425 const Tensor< GUM_SCALAR >&
translate(GUM_SCALAR v)
const;
430 const Tensor< GUM_SCALAR >&
inverse()
const;
435 [[nodiscard]]
Idx draw()
const;
449 Tensor< GUM_SCALAR >
operator+(
const Tensor< GUM_SCALAR >& p2)
const;
450 Tensor< GUM_SCALAR >
operator+(
const GUM_SCALAR& v)
const;
451 Tensor< GUM_SCALAR >
operator-(
const Tensor< GUM_SCALAR >& p2)
const;
452 Tensor< GUM_SCALAR >
operator-(
const GUM_SCALAR& v)
const;
453 Tensor< GUM_SCALAR >
operator*(
const Tensor< GUM_SCALAR >& p2)
const;
454 Tensor< GUM_SCALAR >
operator*(
const GUM_SCALAR& v)
const;
455 Tensor< GUM_SCALAR >
operator/(
const Tensor< GUM_SCALAR >& p2)
const;
456 Tensor< GUM_SCALAR >
operator/(
const GUM_SCALAR& v)
const;
457 Tensor< GUM_SCALAR >&
operator+=(
const Tensor< GUM_SCALAR >& r);
458 Tensor< GUM_SCALAR >&
operator+=(
const GUM_SCALAR& v);
459 Tensor< GUM_SCALAR >&
operator*=(
const Tensor< GUM_SCALAR >& r);
460 Tensor< GUM_SCALAR >&
operator*=(
const GUM_SCALAR& v);
461 Tensor< GUM_SCALAR >&
operator-=(
const Tensor< GUM_SCALAR >& r);
462 Tensor< GUM_SCALAR >&
operator-=(
const GUM_SCALAR& v);
463 Tensor< GUM_SCALAR >&
operator/=(
const Tensor< GUM_SCALAR >& r);
464 Tensor< GUM_SCALAR >&
operator/=(
const GUM_SCALAR& v);
468 Tensor< GUM_SCALAR >
operator|(
const Tensor< GUM_SCALAR >& p2)
const;
469 Tensor< GUM_SCALAR >
operator&(
const Tensor< GUM_SCALAR >& p2)
const;
472 bool operator==(
const Tensor< GUM_SCALAR >& r)
const;
476 [[nodiscard]] std::string
toString()
const final;
491#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
495 template <
typename GUM_SCALAR >
496 inline Tensor< GUM_SCALAR >
log2(
const Tensor< GUM_SCALAR >& arg) {
497 return arg.new_log2();
500 template <
typename GUM_SCALAR >
501 inline Tensor< GUM_SCALAR >
abs(
const Tensor< GUM_SCALAR >& arg) {
502 return arg.new_abs();
505 template <
typename GUM_SCALAR >
506 inline Tensor< GUM_SCALAR >
sq(
const Tensor< GUM_SCALAR >& arg) {
Base class for discrete random variable.
Class for assigning/browsing values to tuples of discrete variables.
Abstract base class for all multi dimensionnal containers.
MultiDimDecorator(MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
Class constructor.
<agrum/base/multidim/multiDimImplementation.h>
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Tensor< GUM_SCALAR > & operator-=(const Tensor< GUM_SCALAR > &r)
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
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...
const Tensor< GUM_SCALAR > & normalizeAsCPT(const Idx &varId=0) const
normalisation of this as a CPT for the variable varId
Idx draw() const
get a value at random from a 1-D distribution
Tensor< GUM_SCALAR > operator|(const Tensor< GUM_SCALAR > &p2) const
the function to be used to add two Tensors
GUM_SCALAR minNonZero() const
min of all non zero elements 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.
Tensor< GUM_SCALAR > extract(const Instantiation &inst) const
create a new Tensor extracted from *this given a partial instantiation
const Tensor< GUM_SCALAR > & random() const
generate a random Tensor with each parameter in [0,1]
Tensor< GUM_SCALAR > new_sq() const
Create a new tensor and apply $x^2$ on every element of the container.
Tensor< GUM_SCALAR > putFirst(const DiscreteVariable *var) const
create a new Tensor with a certain variable in first
Tensor< GUM_SCALAR > prodIn(const gum::VariableSet &kept_vars) const
Projection using multiplication 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).
gum::VariableSet complementVars_(const gum::VariableSet &del_vars) const
Tensor< GUM_SCALAR > * newFactory() const final
Default implementation of MultiDimContainer::set().
static Tensor< GUM_SCALAR > evEq(const DiscreteVariable &v, double val)
numerical evidence generator
Tensor< GUM_SCALAR > sumOut(const gum::VariableSet &del_vars) const
Projection using sum as operation (and implementation-optimized operations).
Tensor< GUM_SCALAR > reorganize(const std::vector< const DiscreteVariable * > &vars) const
create a new Tensor with another order
Tensor< GUM_SCALAR > operator&(const Tensor< GUM_SCALAR > &p2) const
the function to be used to add two Tensors
Size memoryFootprint() const
compute the (approximated) footprint in memory of the tensor
Tensor< GUM_SCALAR > new_sgn() const
Create a new tensor and apply sgn(x)$ on every element of the container.
GUM_SCALAR maxNonOne() const
max of all non one elements in the Tensor
bool operator==(const Tensor< GUM_SCALAR > &r) const
the function to be used to add two Tensors
static Tensor< GUM_SCALAR > deterministicTensor(const DiscreteVariable &var, Idx value)
Tensor< GUM_SCALAR > new_log2() const
Create a new tensor and apply $log_2(x)$ on every element of the container.
static Tensor< GUM_SCALAR > uniformTensor(const DiscreteVariable &var)
const Tensor< GUM_SCALAR > & scale(GUM_SCALAR v) const
multiply (each value of) *this by v
GUM_SCALAR entropy() const
entropy of the Tensor
Tensor< GUM_SCALAR > minOut(const gum::VariableSet &del_vars) const
Projection using min as operation (and implementation-optimized operations).
GUM_SCALAR KL(const Tensor< GUM_SCALAR > &p) const
compute KL divergence between this and p Checks the compatibility and then compute KL divergence
static Tensor< GUM_SCALAR > evGt(const DiscreteVariable &v, double val)
numerical evidence generator
~Tensor() final
Destructor.
Tensor< GUM_SCALAR > sumIn(const gum::VariableSet &kept_vars) const
Projection using sum as operation (and implementation-optimized operations).
Set< Instantiation > findAll(GUM_SCALAR v) const
set of instantiation corresponding to the parameter v in the Tensor
static Tensor< GUM_SCALAR > evIn(const DiscreteVariable &v, double val1, double val2)
numerical evidence generator
const Tensor< GUM_SCALAR > & sq() const
apply $x^2$ on every element of the container
const Tensor< GUM_SCALAR > & normalize() const
normalisation of this do nothing if sum is 0
std::pair< Set< Instantiation >, GUM_SCALAR > argmax() const
Pair of the set of instantiation corresponding to the max and this max in the Tensor.
const Tensor< GUM_SCALAR > & translate(GUM_SCALAR v) const
add v to (each value of) *this
const Tensor< GUM_SCALAR > & noising(GUM_SCALAR alpha) const
add a noise in a CPT by mixing (1-alpha)this+alpha.randomCPT()
const Tensor< GUM_SCALAR > & sgn() const
apply sgn(x)$ on every element of the container
bool isEvidence() const
is an evidence ? (marginal-like but has not to sum to 1)
Tensor< GUM_SCALAR > & operator=(const Tensor< GUM_SCALAR > &src)
Default constructor.
const Tensor< GUM_SCALAR > & randomDistribution() const
generate a random Distribution in the Tensor
GUM_SCALAR sum() const
sum of all elements in the Tensor
const Tensor< GUM_SCALAR > & randomCPT() const
generate a random CPT in the Tensor
Tensor< GUM_SCALAR > operator/(const Tensor< GUM_SCALAR > &p2) const
the function to be used to divide two Tensors
Tensor< GUM_SCALAR > minIn(const gum::VariableSet &kept_vars) const
Projection using min as operation (and implementation-optimized operations).
Tensor()
Default constructor.
GUM_SCALAR max() const
max of all elements in the Tensor
GUM_SCALAR expectedValue(std::function< GUM_SCALAR(const gum::Instantiation &) >) const
ExpectedValue computes the expectation of f over *this.
Tensor< GUM_SCALAR > new_abs() const
Create a new tensor and apply abs on every element of the container.
Tensor< GUM_SCALAR > maxIn(const gum::VariableSet &kept_vars) const
Projection using max as operation (and implementation-optimized operations).
GUM_SCALAR product() const
product of all elements in the Tensor
Tensor< GUM_SCALAR > & operator<<(const DiscreteVariable &v)
the function to be used to add two Tensors
const Tensor< GUM_SCALAR > & abs() const
Apply abs on every element of the container.
const Tensor< GUM_SCALAR > & log2() const
apply $log_2(x)$ on every element of the container
Tensor< GUM_SCALAR > prodOut(const gum::VariableSet &del_vars) const
Projection using multiplication as operation (and implementation-optimized operations).
Tensor< GUM_SCALAR > operator-(const Tensor< GUM_SCALAR > &p2) const
the function to be used to subtract two Tensors
Tensor< GUM_SCALAR > & operator*=(const Tensor< GUM_SCALAR > &r)
the function to be used to add two Tensors
Tensor< GUM_SCALAR > isNonZeroMap() const
create a boolean-like tensor using the predicate isNonZero
std::string toString() const final
the function to be used to add two Tensors
GUM_SCALAR min() const
min of all elements in the Tensor
static Tensor< GUM_SCALAR > evLt(const DiscreteVariable &v, double val)
numerical evidence generator
Tensor< GUM_SCALAR > & operator+=(const Tensor< GUM_SCALAR > &r)
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
const Tensor< GUM_SCALAR > & inverse() const
the function to inverse (each value of) *this
Tensor< GUM_SCALAR > operator~() const
the function to be used to add two Tensors
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Headers for MultiDimDecorator.
gum is the global namespace for all aGrUM entities
value_type & operator*()
Returns the value pointed to by the iterator.
Set< const DiscreteVariable * > VariableSet
Tensor< GUM_SCALAR > log2(const Tensor< GUM_SCALAR > &arg)
Tensor< GUM_SCALAR > sq(const Tensor< GUM_SCALAR > &arg)
Tensor< GUM_SCALAR > abs(const Tensor< GUM_SCALAR > &arg)
Implementation of the Tensor class.