47 template < GUM_Numeric GUM_SCALAR >
50 probPot.fillWith(GUM_SCALAR(1));
51 utilPot.fillWith(GUM_SCALAR(0));
54 template < GUM_Numeric GUM_SCALAR >
59 template < GUM_Numeric GUM_SCALAR >
61 const Tensor< GUM_SCALAR >& util) :
66 template < GUM_Numeric GUM_SCALAR >
72 template < GUM_Numeric GUM_SCALAR >
79 template < GUM_Numeric GUM_SCALAR >
88 template < GUM_Numeric GUM_SCALAR >
92 if (&src ==
this)
return *
this;
98 template < GUM_Numeric GUM_SCALAR >
102 if (&src ==
this)
return *
this;
103 probPot = std::forward< Tensor< GUM_SCALAR > >(src.probPot);
104 utilPot = std::forward< Tensor< GUM_SCALAR > >(src.utilPot);
108 template < GUM_Numeric GUM_SCALAR >
111 return ((p.
probPot == this->probPot)
115 template < GUM_Numeric GUM_SCALAR >
117 for (
const auto& v:
probPot.variablesSequence()) {
118 if (v->name() == name)
return v;
120 for (
const auto& v:
utilPot.variablesSequence()) {
121 if (v->name() == name)
return v;
127 template < GUM_Numeric GUM_SCALAR >
132 template < GUM_Numeric GUM_SCALAR >
137 template < GUM_Numeric GUM_SCALAR >
143 template < GUM_Numeric GUM_SCALAR >
150 template < GUM_Numeric GUM_SCALAR >
156 template < GUM_Numeric GUM_SCALAR >
162 template < GUM_Numeric GUM_SCALAR >
165 const Tensor< GUM_SCALAR >& p2) {
166 Tensor< GUM_SCALAR > res(p1);
169 if (p2[I] != 0) res.set(I, res[I] / p2[I]);
174 template < GUM_Numeric GUM_SCALAR >
181 template < GUM_Numeric GUM_SCALAR >
185 const auto pr = dp.
probPot.sumIn(onto);
189 template < GUM_Numeric GUM_SCALAR >
192 const std::vector< std::string >& ontonames) {
194 for (
const auto& varname: ontonames) {
200 template < GUM_Numeric GUM_SCALAR >
203 const GUM_SCALAR s =
probPot.sum();
204 const double m = tmp.sum() / s;
205 const double m2 = (tmp *
utilPot).sum() / s;
206 double var = m2 - m * m;
207 if (var < 0.0) var = 0.0;
208 return std::pair< GUM_SCALAR, GUM_SCALAR >(m, var);
211 template < GUM_Numeric GUM_SCALAR >
213 return "prob : " +
probPot.toString() +
" util:" +
utilPot.toString();
216 template < GUM_Numeric GUM_SCALAR >
<agrum/ID/inference/decisionTensor.h>
bool operator==(const DecisionTensor< GUM_SCALAR > &p) const
static DecisionTensor< GUM_SCALAR > marginalization(const DecisionTensor< GUM_SCALAR > &dp, const gum::VariableSet &onto)
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)
virtual std::string toString() const
DecisionTensor< GUM_SCALAR > & operator=(const DecisionTensor< GUM_SCALAR > &src)
void insertUtility(const gum::Tensor< GUM_SCALAR > &util)
DecisionTensor< GUM_SCALAR > operator^(const gum::VariableSet &onto) const
const DiscreteVariable * variable(std::string_view name) const
DecisionTensor< GUM_SCALAR > operator*(const DecisionTensor< GUM_SCALAR > &dp1) const
Tensor< GUM_SCALAR > utilPot
DecisionTensor< GUM_SCALAR > operator*=(const DecisionTensor< GUM_SCALAR > &dp1)
Tensor< GUM_SCALAR > probPot
static DecisionTensor< GUM_SCALAR > combination(const DecisionTensor< GUM_SCALAR > &dp1, const DecisionTensor< GUM_SCALAR > &dp2)
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...
This file contains abstract class definitions influence diagrams inference classes.
#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