55 template <
typename GUM_SCALAR >
62 for (
const auto pot:
_obs_)
66 delete const_cast< Tensor< GUM_SCALAR >*
>(pot);
69 template <
typename GUM_SCALAR >
72 Tensor< GUM_SCALAR >* bn_obs =
new Tensor< GUM_SCALAR >();
74 std::stringstream var_name;
75 var_name << chain.first->name() <<
"." << chain.second->safeName();
76 bn_obs->add(
_inf_->BN().variableFromName(var_name.str()));
78 const Tensor< GUM_SCALAR >* prm_obs = this->
evidence(chain.first)[chain.second->id()];
81 for (i.setFirst(), j.
setFirst(); !i.end(); i.inc(), j.
inc()) {
82 bn_obs->set(i, prm_obs->get(j));
88 template <
typename GUM_SCALAR >
91 std::stringstream var_name;
92 var_name << chain.first->name() <<
"." << chain.second->safeName();
95 for (
auto iter =
_obs_.beginSafe(); iter !=
_obs_.endSafe();
97 if ((**iter).contains(var)) {
98 _inf_->eraseEvidence(var_name.str());
99 const Tensor< GUM_SCALAR >* e = *iter;
107 template <
typename GUM_SCALAR >
115 template <
typename GUM_SCALAR >
123 template <
typename GUM_SCALAR >
129 template <
typename GUM_SCALAR >
139 template <
typename GUM_SCALAR >
147 template <
typename GUM_SCALAR >
150 Tensor< GUM_SCALAR >& m) {
153 std::stringstream sBuff;
155 if (!
_obs_.empty()) {
156 for (
auto e:
_obs_) {
158 _inf_->addEvidence(*e);
163 sBuff << chain.first->name() <<
"." << chain.second->safeName();
164 m =
_inf_->posterior(
_inf_->BN().idFromName(sBuff.str()));
167 template <
typename GUM_SCALAR >
170 Tensor< GUM_SCALAR >& j) {
174 template <
typename GUM_SCALAR >
176 return "grounded inference";
Base class for discrete random variable.
Exception : fatal (unknown ?) error.
Class for assigning/browsing values to tuples of discrete variables.
void inc()
Operator increment.
void setFirst()
Assign the first values to the tuple of the Instantiation.
Exception: at least one argument passed to a function is not what was expected.
<agrum/BN/inference/marginalTargetedInference.h>
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
<agrum/PRM/groundedInference.h>
virtual std::string name() const
Returns the bayesnet inference engine used by this class.
virtual void posterior_(const typename PRMInference< GUM_SCALAR >::Chain &chain, Tensor< GUM_SCALAR > &m)
Generic method to compute the marginal of given element.
virtual void evidenceRemoved_(const typename PRMInference< GUM_SCALAR >::Chain &chain)
This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference...
MarginalTargetedInference< GUM_SCALAR > * _inf_
The bayesnet inference engine used by this class.
List< const Tensor< GUM_SCALAR > * > _obs_
void setBNInference(MarginalTargetedInference< GUM_SCALAR > *bn_inf)
Defines the bayesnet inference engine used by this class.
virtual void evidenceAdded_(const typename PRMInference< GUM_SCALAR >::Chain &chain)
This method is called whenever an evidence is added, but AFTER any processing made by PRMInference.
virtual ~GroundedInference()
Destructor.
GroundedInference & operator=(const GroundedInference &source)
Copy operator.
virtual void joint_(const std::vector< typename PRMInference< GUM_SCALAR >::Chain > &queries, Tensor< GUM_SCALAR > &j)
Generic method to compute the marginal of given element.
MarginalTargetedInference< GUM_SCALAR > & getBNInference()
Returns the bayesnet inference engine used by this class.
GroundedInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > * > Chain
Code alias.
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
#define GUM_ERROR(type, msg)
Headers of GroundedInference.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities