49 template < GUM_Numeric GUM_SCALAR >
52 const Tensor< GUM_SCALAR >& source) {
54 Tensor< GUM_SCALAR >* p = 0;
67 p =
new Tensor< GUM_SCALAR >(
71 p->add(*(bij.
second(var)));
85 return new Tensor< GUM_SCALAR >();
117 template < GUM_Numeric GUM_SCALAR >
118 Tensor< GUM_SCALAR >
multTensor(
const Tensor< GUM_SCALAR >& t1,
119 const Tensor< GUM_SCALAR >& t2) {
123 template < GUM_Numeric GUM_SCALAR >
125 Set< Tensor< GUM_SCALAR >* >& pool,
126 Set< Tensor< GUM_SCALAR >* >& trash) {
127 Tensor< GUM_SCALAR >* pot =
nullptr;
128 Tensor< GUM_SCALAR >* tmp =
nullptr;
134 for (
const auto p: pool)
135 if (p->contains(*var)) pots.
insert(p);
137 if (pots.
size() == 0) {
139 }
else if (pots.
size() == 1) {
140 tmp =
const_cast< Tensor< GUM_SCALAR >*
>(*pots.
begin());
141 pot =
new Tensor< GUM_SCALAR >(tmp->sumOut(var_set));
145 pot =
new Tensor< GUM_SCALAR >(tmp->sumOut(var_set));
149 for (
const auto p: pots) {
150 pool.erase(
const_cast< Tensor< GUM_SCALAR >*
>(p));
152 if (trash.exists(
const_cast< Tensor< GUM_SCALAR >*
>(p))) {
153 trash.erase(
const_cast< Tensor< GUM_SCALAR >*
>(p));
154 delete const_cast< Tensor< GUM_SCALAR >*
>(p);
162 template < GUM_Numeric GUM_SCALAR >
164 Set< Tensor< GUM_SCALAR >* >& pool,
165 Set< Tensor< GUM_SCALAR >* >& trash) {
166 for (
auto var: elim_order) {
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
Set of pairs of elements with fast search for both elements.
Base class for discrete random variable.
Base class for all aGrUM's exceptions.
Exception : fatal (unknown ?) error.
Multidimensional matrix stored as an array in memory.
Decorator of a MultiDimArray, using a bijection over the variables.
A multidim implementation for buckets.
A class to combine efficiently several MultiDim tables.
TABLE * execute(const Set< const TABLE * > &set) const final
Creates and returns the result of the combination of the tables within set.
MultiDimContainer< GUM_ELEMENT > * newFactory() const override=0
Creates an empty clone of this MultiDimContainer.
const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
Multidimensional matrix stored as a sparse array in memory.
Exception : operation not allowed.
iterator begin() const
The usual unsafe begin iterator to parse the set.
void insert(const Key &k)
Inserts a new element into the set.
Size size() const noexcept
Returns the number of elements in the set.
#define GUM_ERROR(type, msg)
namespace for all probabilistic relational models entities
Tensor< GUM_SCALAR > multTensor(const Tensor< GUM_SCALAR > &t1, const Tensor< GUM_SCALAR > &t2)
void eliminateNode(const DiscreteVariable *var, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.
void eliminateNodes(const std::vector< const DiscreteVariable * > &elim_order, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
Tensor< GUM_SCALAR > * copyTensor(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const Tensor< GUM_SCALAR > &source)
Returns a copy of a Tensor after applying a bijection over the variables in source.
gum is the global namespace for all aGrUM entities
Set< const DiscreteVariable * > VariableSet