84 template < GUM_Numeric GUM_SCALAR >
89 std::string_view 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 [[nodiscard]] 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;
277 GUM_SCALAR
mean()
const;
294 GUM_SCALAR
stdDev()
const;
300 Tensor< GUM_SCALAR >
reorganize(
const std::vector< const DiscreteVariable* >& vars)
const;
306 Tensor< GUM_SCALAR >
reorganize(
const std::vector< std::string >& vars)
const;
321 Tensor< GUM_SCALAR >
putFirst(std::string_view varname)
const;
331 const Tensor< GUM_SCALAR >&
fillWith(
const Tensor< GUM_SCALAR >& src)
const;
349 const Tensor< GUM_SCALAR >&
fillWith(
const Tensor< GUM_SCALAR >& src,
350 const std::vector< std::string >& mapSrc)
const;
360 const Tensor< GUM_SCALAR >&
fillWith(
const std::vector< GUM_SCALAR >& data)
const;
367 const Tensor< GUM_SCALAR >&
fillWith(
const GUM_SCALAR& val)
const;
373 const Tensor< GUM_SCALAR >&
abs()
const;
378 const Tensor< GUM_SCALAR >&
sq()
const;
383 const Tensor< GUM_SCALAR >&
log2()
const;
390 const Tensor< GUM_SCALAR >&
sgn()
const;
396 Tensor< GUM_SCALAR >
new_abs()
const;
402 Tensor< GUM_SCALAR >
new_sq()
const;
408 Tensor< GUM_SCALAR >
new_log2()
const;
415 Tensor< GUM_SCALAR >
new_sgn()
const;
421 const Tensor< GUM_SCALAR >&
normalize()
const;
431 GUM_SCALAR
KL(
const Tensor< GUM_SCALAR >& p)
const;
445 const Tensor< GUM_SCALAR >&
scale(GUM_SCALAR v)
const;
450 const Tensor< GUM_SCALAR >&
translate(GUM_SCALAR v)
const;
455 const Tensor< GUM_SCALAR >&
inverse()
const;
460 [[nodiscard]]
Idx draw()
const;
474 Tensor< GUM_SCALAR >
operator+(
const Tensor< GUM_SCALAR >& p2)
const;
475 Tensor< GUM_SCALAR >
operator+(
const GUM_SCALAR& v)
const;
476 Tensor< GUM_SCALAR >
operator-(
const Tensor< GUM_SCALAR >& p2)
const;
477 Tensor< GUM_SCALAR >
operator-(
const GUM_SCALAR& v)
const;
478 Tensor< GUM_SCALAR >
operator*(
const Tensor< GUM_SCALAR >& p2)
const;
479 Tensor< GUM_SCALAR >
operator*(
const GUM_SCALAR& v)
const;
480 Tensor< GUM_SCALAR >
operator/(
const Tensor< GUM_SCALAR >& p2)
const;
481 Tensor< GUM_SCALAR >
operator/(
const GUM_SCALAR& v)
const;
482 Tensor< GUM_SCALAR >&
operator+=(
const Tensor< GUM_SCALAR >& r);
483 Tensor< GUM_SCALAR >&
operator+=(
const GUM_SCALAR& v);
484 Tensor< GUM_SCALAR >&
operator*=(
const Tensor< GUM_SCALAR >& r);
485 Tensor< GUM_SCALAR >&
operator*=(
const GUM_SCALAR& v);
486 Tensor< GUM_SCALAR >&
operator-=(
const Tensor< GUM_SCALAR >& r);
487 Tensor< GUM_SCALAR >&
operator-=(
const GUM_SCALAR& v);
488 Tensor< GUM_SCALAR >&
operator/=(
const Tensor< GUM_SCALAR >& r);
489 Tensor< GUM_SCALAR >&
operator/=(
const GUM_SCALAR& v);
493 Tensor< GUM_SCALAR >
operator|(
const Tensor< GUM_SCALAR >& p2)
const;
494 Tensor< GUM_SCALAR >
operator&(
const Tensor< GUM_SCALAR >& p2)
const;
497 bool operator==(
const Tensor< GUM_SCALAR >& r)
const;
501 [[nodiscard]] std::string
toString()
const final;
516#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
520 template < GUM_Numeric GUM_SCALAR >
521 inline Tensor< GUM_SCALAR >
log2(
const Tensor< GUM_SCALAR >& arg);
523 template < GUM_Numeric GUM_SCALAR >
524 inline Tensor< GUM_SCALAR >
abs(
const Tensor< GUM_SCALAR >& arg);
526 template < GUM_Numeric GUM_SCALAR >
527 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.
MultiDimDecorator(MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
aGrUM's Tensor is a multi-dimensional array with tensor operators.
GUM_SCALAR mean() const
compute the mean of a numerical discrete random variable @raise
Tensor< GUM_SCALAR > & operator-=(const Tensor< GUM_SCALAR > &r)
the function to be used to add two Tensors
const Tensor< GUM_SCALAR > & translate(GUM_SCALAR v) const
add v to (each value of) *this
Tensor< GUM_SCALAR > & operator/=(const Tensor< GUM_SCALAR > &r)
the function to be used to add two Tensors
Tensor< GUM_SCALAR > sumOut(const gum::VariableSet &del_vars) const
Projection using sum as operation (and implementation-optimized operations).
GUM_SCALAR variance() const
compute the variance of a numerical discrete random variable @raise
Tensor()
Default constructor.
Idx draw() const
get a value at random from a 1-D distribution
GUM_SCALAR entropy() const
entropy of the Tensor
Tensor< GUM_SCALAR > operator|(const Tensor< GUM_SCALAR > &p2) const
the function to be used to add two Tensors
const Tensor< GUM_SCALAR > & log2() const
apply $log_2(x)$ on every element of the container
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 > isNonZeroMap() const
create a boolean-like tensor using the predicate isNonZero
Tensor< GUM_SCALAR > minOut(const gum::VariableSet &del_vars) const
Projection using min as operation (and implementation-optimized operations).
GUM_SCALAR stdDev() const
compute the stdDev of a numerical discrete random variable
Tensor< GUM_SCALAR > putFirst(const DiscreteVariable *var) const
create a new Tensor with a certain variable in first
Tensor< GUM_SCALAR > maxIn(const gum::VariableSet &kept_vars) const
Projection using max as operation (and implementation-optimized operations).
static Tensor< GUM_SCALAR > evEq(const DiscreteVariable &v, double val)
numerical evidence generator
Tensor< GUM_SCALAR > sumIn(const gum::VariableSet &kept_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
std::pair< Set< Instantiation >, GUM_SCALAR > argmax() const
Pair of the set of instantiation corresponding to the max and this max in the Tensor.
Tensor< GUM_SCALAR > operator&(const Tensor< GUM_SCALAR > &p2) const
the function to be used to add two Tensors
GUM_SCALAR max() const
max of all elements in the Tensor
Tensor< GUM_SCALAR > * newFactory() const final
Default implementation of MultiDimContainer::set().
const Tensor< GUM_SCALAR > & sgn() const
apply sgn(x)$ on every element of the container
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
Tensor< GUM_SCALAR > prodIn(const gum::VariableSet &kept_vars) const
Projection using multiplication as operation (and implementation-optimized operations).
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)
static Tensor< GUM_SCALAR > evGt(const DiscreteVariable &v, double val)
numerical evidence generator
GUM_SCALAR minNonZero() const
min of all non zero elements in the Tensor
~Tensor() final
Destructor.
GUM_SCALAR KL(const Tensor< GUM_SCALAR > &p) const
compute KL divergence between this and p Checks the compatibility and then compute KL divergence
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
Tensor< GUM_SCALAR > prodOut(const gum::VariableSet &del_vars) const
Projection using multiplication as operation (and implementation-optimized operations).
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...
Tensor< GUM_SCALAR > maxOut(const gum::VariableSet &del_vars) const
Projection using max as operation (and implementation-optimized operations).
const Tensor< GUM_SCALAR > & noising(GUM_SCALAR alpha) const
add a noise in a CPT by mixing (1-alpha)this+alpha.randomCPT()
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.
gum::VariableSet _complementVars_(const gum::VariableSet &del_vars) const
Tensor< GUM_SCALAR > operator/(const Tensor< GUM_SCALAR > &p2) const
the function to be used to divide two Tensors
const Tensor< GUM_SCALAR > & normalizeAsCPT(const Idx &varId=0) const
normalisation of this as a CPT for the variable varId
const Tensor< GUM_SCALAR > & normalize() const
normalisation of this do nothing if sum is 0
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.
const Tensor< GUM_SCALAR > & inverse() const
the function to inverse (each value of) *this
Tensor< GUM_SCALAR > & operator<<(const DiscreteVariable &v)
the function to be used to add two Tensors
Tensor< GUM_SCALAR > minIn(const gum::VariableSet &kept_vars) const
Projection using min 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
const Tensor< GUM_SCALAR > & scale(GUM_SCALAR v) const
multiply (each value of) *this by v
GUM_SCALAR min() const
min of all elements in the Tensor
Tensor< GUM_SCALAR > & operator*=(const Tensor< GUM_SCALAR > &r)
the function to be used to add two Tensors
GUM_SCALAR product() const
product of all 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.
const Tensor< GUM_SCALAR > & sq() const
apply $x^2$ on every element of the container
std::string toString() const final
the function to be used to add two Tensors
const Tensor< GUM_SCALAR > & randomCPT() const
generate a random CPT in the Tensor
GUM_SCALAR sum() const
sum of all elements in the Tensor
static Tensor< GUM_SCALAR > evLt(const DiscreteVariable &v, double val)
numerical evidence generator
const Tensor< GUM_SCALAR > & abs() const
Apply abs on every element of the container.
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
Tensor< GUM_SCALAR > operator~() const
the function to be used to add two Tensors
const Tensor< GUM_SCALAR > & randomDistribution() const
generate a random Distribution in the Tensor
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.