56 template < GUM_Numeric GUM_SCALAR >
63 for (
const auto pot:
_obs_)
67 delete const_cast< Tensor< GUM_SCALAR >*
>(pot);
70 template < GUM_Numeric GUM_SCALAR >
73 Tensor< GUM_SCALAR >* bn_obs =
new Tensor< GUM_SCALAR >();
75 auto var_name = std::format(
"{}.{}", chain.first->name(), chain.second->safeName());
76 bn_obs->add(
_inf_->BN().variableFromName(var_name));
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 < GUM_Numeric 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 < GUM_Numeric GUM_SCALAR >
114 template < GUM_Numeric GUM_SCALAR >
122 template < GUM_Numeric GUM_SCALAR >
128 template < GUM_Numeric GUM_SCALAR >
137 template < GUM_Numeric GUM_SCALAR >
145 template < GUM_Numeric GUM_SCALAR >
148 Tensor< GUM_SCALAR >& m) {
151 std::stringstream sBuff;
153 if (!
_obs_.empty()) {
154 for (
auto e:
_obs_) {
156 _inf_->addEvidence(*e);
161 sBuff << chain.first->name() <<
"." << chain.second->safeName();
162 m =
_inf_->posterior(
_inf_->BN().idFromName(sBuff.str()));
165 template < GUM_Numeric GUM_SCALAR >
168 Tensor< GUM_SCALAR >& j) {
172 template < GUM_Numeric GUM_SCALAR >
174 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>
void setBNInference(MarginalTargetedInference< GUM_SCALAR > *bn_inf)
Defines the bayesnet inference engine used by this class.
void joint_(const std::vector< typename PRMInference< GUM_SCALAR >::Chain > &queries, Tensor< GUM_SCALAR > &j) override
Generic method to compute the marginal of given element.
void evidenceAdded_(const typename PRMInference< GUM_SCALAR >::Chain &chain) override
This method is called whenever an evidence is added, but AFTER any processing made by PRMInference.
~GroundedInference() override
Destructor.
std::string name() const override
Returns the bayesnet inference engine used by this class.
void evidenceRemoved_(const typename PRMInference< GUM_SCALAR >::Chain &chain) override
This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference...
void posterior_(const typename PRMInference< GUM_SCALAR >::Chain &chain, Tensor< GUM_SCALAR > &m) override
Generic method to compute the marginal of given element.
GroundedInference & operator=(const GroundedInference &source)
Copy operator.
MarginalTargetedInference< GUM_SCALAR > * _inf_
The bayesnet inference engine used by this class.
List< const Tensor< GUM_SCALAR > * > _obs_
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.
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
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