60 template <
typename GUM_SCALAR >
68 template <
typename GUM_SCALAR >
71 for (
const auto& var: vars) {
77 template <
typename GUM_SCALAR >
85 template <
typename GUM_SCALAR >
96 template <
typename GUM_SCALAR >
103 template <
typename GUM_SCALAR >
123 template <
typename GUM_SCALAR >
126 if (&src ==
this)
return *
this;
132 template <
typename GUM_SCALAR >
135 if (&src ==
this)
return *
this;
143 template <
typename GUM_SCALAR >
149 template <
typename GUM_SCALAR >
151 return new Tensor< GUM_SCALAR >(
156 template <
typename GUM_SCALAR >
165 template <
typename GUM_SCALAR >
174 template <
typename GUM_SCALAR >
183 template <
typename GUM_SCALAR >
193 template <
typename GUM_SCALAR >
201 [](GUM_SCALAR z, GUM_SCALAR p) {
202 return (p ==
static_cast< GUM_SCALAR
>(1)) ? z
203 : (z ==
static_cast< GUM_SCALAR
>(1)) ? p
206 static_cast< GUM_SCALAR
>(1));
214 template <
typename GUM_SCALAR >
222 [](GUM_SCALAR z, GUM_SCALAR p) {
223 return (p ==
static_cast< GUM_SCALAR
>(0)) ? z
224 : (z ==
static_cast< GUM_SCALAR
>(0)) ? p
227 static_cast< GUM_SCALAR
>(0));
232 template <
typename GUM_SCALAR >
236 return static_cast< GUM_SCALAR
>(0);
241 for (i.setFirst(); !i.end(); i.inc()) {
242 const GUM_SCALAR v_f = f(i);
243 if (v_f != GUM_SCALAR(0.0)) res += this->
get(i) * v_f;
249 template <
typename GUM_SCALAR >
256 template <
typename GUM_SCALAR >
257 INLINE
const Tensor< GUM_SCALAR >&
263 template <
typename GUM_SCALAR >
269 template <
typename GUM_SCALAR >
270 INLINE
const Tensor< GUM_SCALAR >&
272 if (src.domainSize() != this->domainSize()) {
276 for (
const auto& v: src.variablesSequence()) {
282 "Variable <" << v->name() <<
"> not present in src (" << son <<
").")
285 if (v->toString() != src.variable(v->name()).toString()) {
293 for (
Idx i = 0; i < this->
nbrDim(); i++) {
296 this->
set(Idst, src.get(Isrc));
302 template <
typename GUM_SCALAR >
303 INLINE
const Tensor< GUM_SCALAR >&
305 const std::vector< std::string >& mapSrc)
const {
306 if (src.nbrDim() != this->nbrDim()) {
309 if (src.nbrDim() != mapSrc.size()) {
313 for (
Idx i = 0; i < src.nbrDim(); i++) {
314 if (src.variable(mapSrc[i]).domainSize() != this->variable(i).domainSize()) {
316 "Variables " << mapSrc[i] <<
" (in the argument) and " << this->
variable(i).name()
317 <<
" have not the same dimension.")
319 Isrc.
add(src.variable(mapSrc[i]));
323 for (Isrc.
setFirst(); !Isrc.
end(); ++Isrc, ++Idst) {
324 this->
set(Idst, src.get(Isrc));
330 template <
typename GUM_SCALAR >
332 this->
apply([](GUM_SCALAR x) {
return x * x; });
336 template <
typename GUM_SCALAR >
338 this->
apply([](GUM_SCALAR x) {
return std::log2(x); });
342 template <
typename GUM_SCALAR >
344 this->
apply([](GUM_SCALAR x) {
return (GUM_SCALAR(0) < x) - (x < GUM_SCALAR(0)); });
348 template <
typename GUM_SCALAR >
350 if (this->
nbrDim() != p.nbrDim())
352 for (
const auto var: p.variablesSequence()) {
357 if (!p.contains(*var))
362 auto res =
static_cast< GUM_SCALAR
>(0);
364 GUM_SCALAR x = this->
get(inst);
365 GUM_SCALAR y = p.get(inst);
366 if (
static_cast< GUM_SCALAR
>(0) == x)
369 if (
static_cast< GUM_SCALAR
>(0) == y)
373 res += x * std::log2(x / y);
378 template <
typename GUM_SCALAR >
380 this->
apply([](GUM_SCALAR x) {
381 if (x >= 0)
return x;
389 template <
typename GUM_SCALAR >
395 GUM_SCALAR s =
sum();
397 if (s != (GUM_SCALAR)0) {
398 this->
apply([s](GUM_SCALAR x) {
return x / s; });
404 template <
typename GUM_SCALAR >
407 if (this->
empty_value_ !=
static_cast< GUM_SCALAR
>(0)) {
413 if (varId >= this->
nbrDim()) {
417 const auto& v = this->
variable(varId);
420 auto s = (GUM_SCALAR)0.0;
422 s += this->
get(inst);
423 if (s == (GUM_SCALAR)0.0) {
426 if (s != (GUM_SCALAR)1.0) {
428 this->
set(inst, this->
get(inst) / s);
436 template <
typename GUM_SCALAR >
438 this->
apply([v](GUM_SCALAR x) {
return x * v; });
442 template <
typename GUM_SCALAR >
444 this->
apply([v](GUM_SCALAR x) {
return x + v; });
448 template <
typename GUM_SCALAR >
450 this->
apply([](GUM_SCALAR x) {
return 1 / x; });
454 template <
typename GUM_SCALAR >
457 return Tensor< GUM_SCALAR >().fillWith(this->
empty_value_);
465 if (!del_vars.
exists(var)) {
470 if (equal) {
return Tensor< GUM_SCALAR >().fillWith(this->
sum()); }
476 template <
typename GUM_SCALAR >
477 INLINE Tensor< GUM_SCALAR >
480 return Tensor< GUM_SCALAR >().fillWith(this->
empty_value_);
488 if (!del_vars.
exists(var)) {
493 if (equal) {
return Tensor< GUM_SCALAR >().fillWith(this->
product()); }
499 template <
typename GUM_SCALAR >
502 return Tensor< GUM_SCALAR >().fillWith(this->
empty_value_);
510 if (!del_vars.
exists(var)) {
515 if (equal) {
return Tensor< GUM_SCALAR >().fillWith(this->
min()); }
521 template <
typename GUM_SCALAR >
524 return Tensor< GUM_SCALAR >().fillWith(this->
empty_value_);
532 if (!del_vars.
exists(var)) {
537 if (equal) {
return Tensor< GUM_SCALAR >().fillWith(this->
max()); }
543 template <
typename GUM_SCALAR >
546 return Tensor< GUM_SCALAR >().fillWith(this->
empty_value_);
551 if (kept_vars.
empty()) {
return Tensor< GUM_SCALAR >().fillWith(this->
sum()); }
556 template <
typename GUM_SCALAR >
557 INLINE Tensor< GUM_SCALAR >
560 return Tensor< GUM_SCALAR >().fillWith(this->
empty_value_);
565 if (kept_vars.
empty()) {
return Tensor< GUM_SCALAR >().fillWith(this->
product()); }
570 template <
typename GUM_SCALAR >
573 return Tensor< GUM_SCALAR >().fillWith(this->
empty_value_);
578 if (kept_vars.
empty()) {
return Tensor< GUM_SCALAR >().fillWith(this->
min()); }
583 template <
typename GUM_SCALAR >
586 return Tensor< GUM_SCALAR >().fillWith(this->
empty_value_);
591 if (kept_vars.
empty()) {
return Tensor< GUM_SCALAR >().fillWith(this->
max()); }
596 template <
typename GUM_SCALAR >
598 auto p = Tensor< GUM_SCALAR >(*
this);
599 p.apply([](GUM_SCALAR x) {
600 if (x !=
static_cast< GUM_SCALAR
>(0))
return static_cast< GUM_SCALAR
>(1);
601 else return static_cast< GUM_SCALAR
>(0);
606 template <
typename GUM_SCALAR >
616 template <
typename GUM_SCALAR >
619 if (vars.size() != this->nbrDim())
621 "The argument contains " << vars.size() <<
" variables instead of "
622 << this->nbrDim() <<
".")
623 for (
const auto var: vars) {
628 Tensor< GUM_SCALAR > p;
629 p.beginMultipleChanges();
630 for (
const auto var: vars)
632 p.endMultipleChanges();
633 p.copyFrom(*
this,
nullptr);
638 template <
typename GUM_SCALAR >
641 std::vector< const DiscreteVariable* > res;
645 namesToVars.
insert(this->variable(i).name(), &(this->variable(i)));
647 for (
const auto& name: vars) {
648 if (!namesToVars.
exists(name)) {
650 "'" << name <<
"' is a not a name of a variable in this tensor")
652 res.push_back(namesToVars[name]);
657 template <
typename GUM_SCALAR >
662 if (&(this->
variable(0)) == var)
return Tensor< GUM_SCALAR >(*
this);
664 std::vector< const DiscreteVariable* > vars;
672 template <
typename GUM_SCALAR >
677 if (this->
variable(i).name() == varname) {
683 "The variable '" << varname <<
"' to put first does not belong to the tensor")
687 template <
typename GUM_SCALAR >
689 Tensor< GUM_SCALAR > p;
690 p.extractFrom(*
this, inst);
695 template <
typename GUM_SCALAR >
697 if (this->
nbrDim() != 1) {
705 if (r <= 0)
return Ip.
val(0);
707 return this->
variable(0).domainSize() - 1;
710 template <
typename GUM_SCALAR >
711 std::ostream&
operator<<(std::ostream& out,
const Tensor< GUM_SCALAR >& array) {
712 out << array.toString();
717 template <
typename GUM_SCALAR >
731 template <
typename GUM_SCALAR >
734 return std::pair(
findAll(m), m);
738 template <
typename GUM_SCALAR >
741 return std::pair(
findAll(m), m);
744 template <
typename GUM_SCALAR >
748 std::vector< GUM_SCALAR > v;
758 template <
typename GUM_SCALAR >
769 template <
typename GUM_SCALAR >
779 this->
set(I, distrib[I.
val(0)]);
787 template <
typename GUM_SCALAR >
789 if ((alpha < GUM_SCALAR(0.0)) || (alpha > GUM_SCALAR(1.0))) {
792 Tensor< GUM_SCALAR > noise(*
this);
793 return fillWith(
scale(1 - alpha) + noise.randomCPT().scale(alpha)).normalizeAsCPT();
796 template <
typename GUM_SCALAR >
798 return Tensor< GUM_SCALAR >(*this).abs();
801 template <
typename GUM_SCALAR >
803 return Tensor< GUM_SCALAR >(*this).sq();
806 template <
typename GUM_SCALAR >
808 return Tensor< GUM_SCALAR >(*this).log2();
811 template <
typename GUM_SCALAR >
813 return Tensor< GUM_SCALAR >(*this).sgn();
816 template <
typename GUM_SCALAR >
823 template <
typename GUM_SCALAR >
825 if (p2.empty())
return Tensor< GUM_SCALAR >(*this).translate(p2.empty_value_);
826 if (this->
empty())
return Tensor< GUM_SCALAR >(p2).translate(this->
empty_value_);
828 return Tensor< GUM_SCALAR >(*this->
content() + *p2.content());
832 template <
typename GUM_SCALAR >
834 return Tensor< GUM_SCALAR >(*this).translate(v);
838 template <
typename GUM_SCALAR >
840 if (this->
nbrDim() != 1)
return false;
841 if (this->
sum() <= 0.0)
return false;
842 return (this->
min() >= 0.0) && (this->
max() <= 1.0);
846 template <
typename GUM_SCALAR >
850 if (this->
variable(0) != p2.variable(0))
852 Tensor< GUM_SCALAR > res(*
this);
855 res.set(I, std::max(res.get(I), p2.get(I)));
861 template <
typename GUM_SCALAR >
865 if (this->
variable(0) != p2.variable(0))
867 Tensor< GUM_SCALAR > res(*
this);
870 res.set(I, std::min(res.get(I), p2.get(I)));
876 template <
typename GUM_SCALAR >
880 Tensor< GUM_SCALAR > res(*
this);
883 res.set(I, 1 - res.get(I));
889 template <
typename GUM_SCALAR >
891 if (p2.empty())
return Tensor< GUM_SCALAR >(*this).translate(-p2.empty_value_);
893 auto p = Tensor< GUM_SCALAR >(p2);
894 p.apply([
this](GUM_SCALAR x) {
return this->
empty_value_ - x; });
897 return Tensor< GUM_SCALAR >(*this->
content() - *p2.content());
901 template <
typename GUM_SCALAR >
903 return Tensor< GUM_SCALAR >(*this).translate(-v);
907 template <
typename GUM_SCALAR >
909 if (p2.empty())
return Tensor< GUM_SCALAR >(*this).scale(p2.empty_value_);
912 return Tensor< GUM_SCALAR >(*this->
content() * *p2.content());
916 template <
typename GUM_SCALAR >
918 return Tensor< GUM_SCALAR >(*this).scale(v);
922 template <
typename GUM_SCALAR >
924 if (p2.empty())
return Tensor< GUM_SCALAR >(*this).scale(1 / p2.empty_value_);
926 auto p = Tensor< GUM_SCALAR >(p2);
927 p.apply([
this](GUM_SCALAR x) {
return this->
empty_value_ / x; });
930 return Tensor< GUM_SCALAR >(*this->
content() / *p2.content());
934 template <
typename GUM_SCALAR >
936 return Tensor< GUM_SCALAR >(*this).scale(1 / v);
939 template <
typename GUM_SCALAR >
945 template <
typename GUM_SCALAR >
951 template <
typename GUM_SCALAR >
957 template <
typename GUM_SCALAR >
963 template <
typename GUM_SCALAR >
969 template <
typename GUM_SCALAR >
975 template <
typename GUM_SCALAR >
981 template <
typename GUM_SCALAR >
987 template <
typename GUM_SCALAR >
990 if (r.empty())
return this->
empty_value_ == r.empty_value_;
993 if (r.empty())
return false;
994 else return (*this->
content_) == (*r.content_);
998 template <
typename GUM_SCALAR >
1001 std::stringstream ss;
1003 if (table->nbrDim() == 0) {
1005 ss <<
"[" << this->
get(I) <<
"]";
1008 const Size colwidth = 6;
1009 const Size numberwidth = 9;
1010 const Size nbrLigMax = 6;
1012 ss << std::left << std::fixed << std::endl;
1013 ss.precision(numberwidth - 5);
1015 const auto& var = table->variable(0);
1017 const Size nbparents = table->nbrDim() - 1;
1018 const Size nbcol = var.domainSize();
1019 const std::string maskparent(colwidth,
'-');
1020 const std::string masknumber(numberwidth,
'-');
1023 ss << std::setw(nbparents * (colwidth + 1) - 1) <<
" "
1025 ss <<
" " << std::setw(nbcol * (numberwidth + 1) - 3)
1026 << var.name().substr(0, nbcol * (numberwidth + 1) - 3) <<
"|";
1029 if (nbparents > 0) {
1030 for (
Idx i = 1; i <= nbparents; i++)
1031 ss << std::setw(colwidth) << table->variable(i).name().substr(0, colwidth) <<
"|";
1034 for (
Idx i = 0; i < nbcol; i++)
1035 ss << std::setw(numberwidth) << var.label(i).substr(0, numberwidth) <<
"|";
1039 if (nbparents > 0) {
1040 for (
Idx i = 1; i <= nbparents; i++)
1041 ss << maskparent <<
"|";
1044 for (
Idx i = 0; i < nbcol; i++)
1045 ss << masknumber <<
"|";
1049 const auto drawligne = [&]() {
1050 if (nbparents > 0) {
1051 for (
Idx i = 1; i <= nbparents; i++)
1052 ss << std::setw(colwidth) << table->variable(i).label(I.
val(i)).substr(0, colwidth)
1057 ss <<
" " << std::setw(numberwidth - 1) << table->get(I) <<
"|";
1062 if (
const Size nbrLig = table->domainSize() / var.domainSize(); nbrLig < nbrLigMax * 2 + 1) {
1069 if (cpt > nbrLigMax)
break;
1072 ss <<
"[..." << nbrLig - nbrLigMax * 2 <<
" more line(s) ...]" << std::endl;
1074 for (
Idx revi = 1; revi < nbrLigMax; revi++)
1084 template <
typename GUM_SCALAR >
1097 template <
typename GUM_SCALAR >
1098 Tensor< GUM_SCALAR >
1102 "val2 (" << val2 <<
") must be greater than val1 (" << val1 <<
").")
1111 for (
Idx i = i1; i <= i2; i++) {
1118 template <
typename GUM_SCALAR >
1134 template <
typename GUM_SCALAR >
1137 if (i == 0) {
return evEq(v, val); }
1143 for (
Idx i2 = 0; i2 < i; i2++) {
1150 template <
typename GUM_SCALAR >
1152 return this->
content()->realSize() *
sizeof(GUM_SCALAR);
1155 template <
typename GUM_SCALAR >
1158 Tensor< GUM_SCALAR > pot;
1160 pot.beginMultipleChanges();
1162 pot.endMultipleChanges(GUM_SCALAR(0.0));
1166 pot.set(I, GUM_SCALAR(1.0));
1171 template <
typename GUM_SCALAR >
1173 const std::string& value) {
1177 template <
typename GUM_SCALAR >
1179 Tensor< GUM_SCALAR > pot;
1181 pot.beginMultipleChanges();
1183 pot.endMultipleChanges(GUM_SCALAR(1.0));
Base class for discrete random variable.
virtual Idx index(const std::string &label) const =0
virtual Idx closestIndex(double val) const =0
for numerical variables, returns the closest index for the value
virtual Size domainSize() const =0
Exception : fatal (unknown ?) error.
The class for generic Hash Tables.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
Class for assigning/browsing values to tuples of discrete variables.
void decNotVar(const DiscreteVariable &v)
Operator decrement for vars which are not v.
Instantiation & chgVal(const DiscreteVariable &v, Idx newval)
Assign newval to variable v in the Instantiation.
bool end() const
Returns true if the Instantiation reached the end.
void incVar(const DiscreteVariable &v)
Operator increment for variable v only.
void setFirstNotVar(const DiscreteVariable &v)
Assign the first values to variables different of v.
void add(const DiscreteVariable &v) final
Adds a new variable in the Instantiation.
void incNotVar(const DiscreteVariable &v)
Operator increment for vars which are not v.
void setFirstVar(const DiscreteVariable &v)
Assign the first value in the Instantiation for var v.
void inc()
Operator increment.
Idx val(Idx i) const
Returns the current value of the variable at position i.
void setFirst()
Assign the first values to the tuple of the Instantiation.
void unsetEnd()
Alias for unsetOverflow().
const DiscreteVariable & variable(Idx i) const final
Returns the variable at position i in the tuple.
void setLast()
Assign the last values in the Instantiation.
Exception: at least one argument passed to a function is not what was expected.
Multidimensional matrix stored as an array in memory.
Abstract base class for all multi dimensionnal containers.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const =0
Returns the implementation for this object (may be *this).
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const final
Returns a const ref to the sequence of DiscreteVariable*.
GUM_SCALAR empty_value_
value of the MultiDimDecorator if no dimension.
MultiDimDecorator< GUM_SCALAR > & operator=(const MultiDimDecorator &from) noexcept
copy operator
virtual GUM_SCALAR reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const final
compute lfold for this container
virtual bool empty() const final
Returns true if no var is in *this.
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
MultiDimDecorator(MultiDimImplementation< GUM_SCALAR > *aContent=nullptr, GUM_SCALAR empty_value=(GUM_SCALAR) 0)
Class constructor.
virtual void endMultipleChanges() final
Default implementation of MultiDimContainer::set().
virtual GUM_SCALAR get(const Instantiation &i) const final
Default implementation of MultiDimContainer::get().
virtual void populate(const std::vector< GUM_SCALAR > &v) const final
Automatically fills this MultiDimContainer with the values in v.
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.
virtual bool contains(const DiscreteVariable &var) const final
Returns true if 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.
virtual void beginMultipleChanges() final
Default implementation of MultiDimContainer::set().
virtual void fill(const GUM_SCALAR &d) const final
Default implementation of MultiDimContainer::set().
virtual Size domainSize() const final
Returns the product of the variables domain size.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const final
Returns the implementation for this object (may be *this).
virtual const DiscreteVariable & variable(Idx) const final
Returns a const ref to the ith var.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const final
Default implementation of MultiDimContainer::set().
<agrum/base/multidim/multiDimImplementation.h>
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const =0
Returns a const ref to the sequence of DiscreteVariable*.
virtual bool empty() const =0
Returns true if no var is in *this.
Size size() const noexcept
Returns the number of elements in the set.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
bool empty() const noexcept
Indicates whether the set is the empty set.
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 > operator*(const Tensor< GUM_SCALAR > &p2) const
the function to be used to multiply two Tensors
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
const std::string & name() const
returns the name of the variable
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
double randomProba()
Returns a random double between 0 and 1 included (i.e.
std::vector< GUM_SCALAR > randomDistribution(Size n)
Return a random discrete distribution.
gum is the global namespace for all aGrUM entities
GUM_SCALAR projectProduct(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Product
Set< const DiscreteVariable * > VariableSet
GUM_SCALAR projectMin(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Min
GUM_SCALAR projectMax(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Max
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
GUM_SCALAR projectSum(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a sum
Header of the Tensor class.