29 #ifndef AGRUM_DECISIONPOTENTIAL_H 30 #define AGRUM_DECISIONPOTENTIAL_H 32 #include <agrum/tools/core/set.h> 33 #include <agrum/tools/variables/discreteVariable.h> 34 #include <agrum/tools/multidim/instantiation.h> 35 #include <agrum/tools/multidim/potential.h> 43 template <
typename GUM_SCALAR >
50 GUM_CONSTRUCTOR(DecisionPotential);
51 probPot.fillWith(GUM_SCALAR(1));
52 utilPot.fillWith(GUM_SCALAR(0));
58 const Potential< GUM_SCALAR >& util) :
61 GUM_CONSTRUCTOR(DecisionPotential);
66 GUM_CONS_CPY(DecisionPotential);
70 gum::Potential< GUM_SCALAR > p;
71 p.fillWith(GUM_SCALAR(1));
73 p.fillWith(GUM_SCALAR(0));
79 GUM_OP_CPY(DecisionPotential);
80 if (&src ==
this)
return *
this;
81 probPot = src.probPot;
82 utilPot = src.utilPot;
89 GUM_CONS_MOV(DecisionPotential);
94 GUM_OP_MOV(DecisionPotential);
95 if (&src ==
this)
return *
this;
96 probPot = std::forward< Potential< GUM_SCALAR > >(src.probPot);
97 utilPot = std::forward< Potential< GUM_SCALAR > >(src.utilPot);
103 return ((p.probPot ==
this->probPot)
104 && (p.probPot * p.utilPot ==
this->probPot *
this->utilPot));
112 for (
const auto& v: probPot.variablesSequence()) {
113 if (v->name() == name)
return v;
115 for (
const auto& v: utilPot.variablesSequence()) {
116 if (v->name() == name)
return v;
120 "'" << name <<
"' can not be found in DecisionPotential.")
143 operator^(
const Set<
const DiscreteVariable* >& onto)
const {
144 return DecisionPotential< GUM_SCALAR >::marginalization(*
this, onto);
148 operator^(
const std::vector< std::string >& ontonames)
const {
149 return DecisionPotential< GUM_SCALAR >::marginalization(*
this, ontonames);
156 Potential< GUM_SCALAR > res(p1);
157 Instantiation I(res);
158 for (I.setFirst(); !I.end(); I.inc()) {
159 if (res[I] != 0) res.set(I, res[I] / p2[I]);
168 dp1.utilPot + dp2.utilPot);
173 const Set<
const DiscreteVariable* >& onto) {
174 const auto pr = dp.probPot.margSumIn(onto);
175 return DecisionPotential(
177 divideEvenZero((dp.probPot * dp.utilPot).margSumIn(onto), pr));
182 const std::vector< std::string >& ontonames) {
183 Set<
const DiscreteVariable* > onto;
184 for (
const auto& varname: ontonames) {
185 onto.insert(dp.variable(varname));
187 return marginalization(dp, onto);
191 auto tmp = probPot * utilPot;
192 GUM_SCALAR s = probPot.sum();
193 double m = tmp.sum() / s;
194 double m2 = (tmp * utilPot).sum() / s;
195 return std::pair< GUM_SCALAR, GUM_SCALAR >(m, m2 - m * m);
199 return "prob : " + probPot.toString() +
" util:" + utilPot.toString();
203 template <
typename GUM_SCALAR >
206 out << array.toString();
DecisionPotential< GUM_SCALAR > operator*(const DecisionPotential< GUM_SCALAR > &dp1) const
bool operator!=(const DecisionPotential< GUM_SCALAR > &p) const
static DecisionPotential< GUM_SCALAR > combination(const DecisionPotential< GUM_SCALAR > &dp1, const DecisionPotential< GUM_SCALAR > &dp2)
Potential< GUM_SCALAR > probPot
const DiscreteVariable * variable(const std::string &name) const
INLINE void emplace(Args &&... args)
DecisionPotential< GUM_SCALAR > operator*=(const DecisionPotential< GUM_SCALAR > &dp1)
DecisionPotential(const Potential< GUM_SCALAR > &prob, const Potential< GUM_SCALAR > &util)
Potential< GUM_SCALAR > utilPot
DecisionPotential(DecisionPotential< GUM_SCALAR > &&dp)
DecisionPotential< GUM_SCALAR > & operator=(DecisionPotential< GUM_SCALAR > &&src)
<agrum/ID/inference/decisionPotential.h>
void insertUtility(const gum::Potential< GUM_SCALAR > &util)
virtual std::string toString() const
bool operator==(const DecisionPotential< GUM_SCALAR > &p) const
void insertProba(const gum::Potential< GUM_SCALAR > &proba)
DecisionPotential< GUM_SCALAR > & operator=(const DecisionPotential< GUM_SCALAR > &src)
std::pair< GUM_SCALAR, GUM_SCALAR > meanVar()
std::ostream & operator<<(std::ostream &out, const DecisionPotential< GUM_SCALAR > &array)
static DecisionPotential< GUM_SCALAR > marginalization(const DecisionPotential< GUM_SCALAR > &dp, const std::vector< std::string > &ontonames)
DecisionPotential< GUM_SCALAR > operator^(const std::vector< std::string > &ontonames) const
static Potential< GUM_SCALAR > divideEvenZero(const Potential< GUM_SCALAR > &p1, const Potential< GUM_SCALAR > &p2)
DecisionPotential(const DecisionPotential< GUM_SCALAR > &dp)