49#ifndef AGRUM_DECISIONTENSOR_H
50#define AGRUM_DECISIONTENSOR_H
60 template <
typename GUM_SCALAR >
68 probPot.fillWith(GUM_SCALAR(1));
69 utilPot.fillWith(GUM_SCALAR(0));
77 DecisionTensor(
const Tensor< GUM_SCALAR >& prob,
const Tensor< GUM_SCALAR >& util) :
97 if (&src ==
this)
return *
this;
111 if (&src ==
this)
return *
this;
112 probPot = std::forward< Tensor< GUM_SCALAR > >(src.probPot);
113 utilPot = std::forward< Tensor< GUM_SCALAR > >(src.utilPot);
119 return ((p.
probPot == this->probPot)
126 for (
const auto& v:
probPot.variablesSequence()) {
127 if (v->name() == name)
return v;
129 for (
const auto& v:
utilPot.variablesSequence()) {
130 if (v->name() == name)
return v;
158 const Tensor< GUM_SCALAR >& p2) {
159 Tensor< GUM_SCALAR > res(p1);
162 if (p2[I] != 0) res.set(I, res[I] / p2[I]);
174 const auto pr = dp.
probPot.sumIn(onto);
180 const std::vector< std::string >& ontonames) {
182 for (
const auto& varname: ontonames) {
188 std::pair< GUM_SCALAR, GUM_SCALAR >
meanVar() {
190 const GUM_SCALAR s =
probPot.sum();
191 const double m = tmp.sum() / s;
192 const double m2 = (tmp *
utilPot).sum() / s;
193 double var = m2 - m * m;
194 if (var < 0.0) var = 0.0;
195 return std::pair< GUM_SCALAR, GUM_SCALAR >(m, var);
199 return "prob : " +
probPot.toString() +
" util:" +
utilPot.toString();
203 template <
typename GUM_SCALAR >
<agrum/ID/inference/decisionTensor.h>
bool operator==(const DecisionTensor< GUM_SCALAR > &p) const
void insertProba(const gum::Tensor< GUM_SCALAR > &proba)
std::pair< GUM_SCALAR, GUM_SCALAR > meanVar()
static Tensor< GUM_SCALAR > divideEvenZero(const Tensor< GUM_SCALAR > &p1, const Tensor< GUM_SCALAR > &p2)
DecisionTensor(const Tensor< GUM_SCALAR > &prob, const Tensor< GUM_SCALAR > &util)
DecisionTensor< GUM_SCALAR > & operator=(DecisionTensor< GUM_SCALAR > &&src)
static DecisionTensor< GUM_SCALAR > combination(const DecisionTensor< GUM_SCALAR > &dp1, const DecisionTensor< GUM_SCALAR > &dp2)
DecisionTensor(const DecisionTensor< GUM_SCALAR > &dp)
DecisionTensor< GUM_SCALAR > & operator=(const DecisionTensor< GUM_SCALAR > &src)
DecisionTensor(DecisionTensor< GUM_SCALAR > &&dp)
DecisionTensor< GUM_SCALAR > operator^(const std::vector< std::string > &ontonames) const
void insertUtility(const gum::Tensor< GUM_SCALAR > &util)
DecisionTensor< GUM_SCALAR > operator^(const gum::VariableSet &onto) const
DecisionTensor< GUM_SCALAR > operator*(const DecisionTensor< GUM_SCALAR > &dp1) const
Tensor< GUM_SCALAR > utilPot
static DecisionTensor< GUM_SCALAR > marginalization(const DecisionTensor< GUM_SCALAR > &dp, const gum::VariableSet &onto)
const DiscreteVariable * variable(const std::string &name) const
DecisionTensor< GUM_SCALAR > operator*=(const DecisionTensor< GUM_SCALAR > &dp1)
static DecisionTensor< GUM_SCALAR > marginalization(const DecisionTensor< GUM_SCALAR > &dp, const std::vector< std::string > &ontonames)
Tensor< GUM_SCALAR > probPot
virtual std::string toString() const
bool operator!=(const DecisionTensor< GUM_SCALAR > &p) const
Base class for discrete random variable.
Class for assigning/browsing values to tuples of discrete variables.
bool end() const
Returns true if the Instantiation reached the end.
void inc()
Operator increment.
void setFirst()
Assign the first values to the tuple of the Instantiation.
Exception : the element we looked for cannot be found.
void insert(const Key &k)
Inserts a new element into the set.
aGrUM's Tensor is a multi-dimensional array with tensor operators.
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...
#define GUM_ERROR(type, msg)
gum is the global namespace for all aGrUM entities
Set< const DiscreteVariable * > VariableSet
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Header of the Tensor class.