55 template <
typename GUM_SCALAR >
58 for (
const auto& elt2: *elt.second)
67 template <
typename GUM_SCALAR >
75 for (
const auto& elt2: *elt.second) {
76 Tensor< GUM_SCALAR >* e =
new Tensor< GUM_SCALAR >();
77 e->add(*(elt2.second->variablesSequence().front()));
81 e->set(i, elt2.second->get(i));
88 template <
typename GUM_SCALAR >
98 for (
const auto& elt2: *elt.second) {
99 Tensor< GUM_SCALAR >* e =
new Tensor< GUM_SCALAR >();
100 e->add(*(elt2.second->variablesSequence().front()));
104 e->set(i, elt2.second->get(i));
114 template <
typename GUM_SCALAR >
125 template <
typename GUM_SCALAR >
127 const Tensor< GUM_SCALAR >& p) {
128 if (chain.first->exists(chain.second->id())) {
129 if ((p.nbrDim() != 1) || (!p.contains(chain.second->type().variable())))
132 Tensor< GUM_SCALAR >* e =
new Tensor< GUM_SCALAR >();
133 e->add(chain.second->type().variable());
141 if (emap.
exists(chain.second->id())) {
142 delete emap[chain.second->id()];
143 emap[chain.second->id()] = e;
145 emap.
insert(chain.second->id(), e);
148 evidenceAdded_(chain);
151 "the given PRMAttribute does not belong to this "
152 "Instance<GUM_SCALAR>.");
156 template <
typename GUM_SCALAR >
163 template <
typename GUM_SCALAR >
169 template <
typename GUM_SCALAR >
177 template <
typename GUM_SCALAR >
185 template <
typename GUM_SCALAR >
193 template <
typename GUM_SCALAR >
201 template <
typename GUM_SCALAR >
206 template <
typename GUM_SCALAR >
211 template <
typename GUM_SCALAR >
213 return (
hasEvidence(chain.first)) ?
evidence(chain.first).exists(chain.second->id()) :
false;
216 template <
typename GUM_SCALAR >
221 template <
typename GUM_SCALAR >
224 if (
_EMap_(chain.first).exists(chain.second->id())) {
226 delete _EMap_(chain.first)[chain.second->id()];
227 _EMap_(chain.first).erase(chain.second->id());
234 template <
typename GUM_SCALAR >
237 Tensor< GUM_SCALAR >& m) {
241 m.add(chain.second->type().variable());
242 const Tensor< GUM_SCALAR >& e = *(
evidence(chain.first)[chain.second->id()]);
248 if (chain.second != &(chain.first->get(chain.second->safeName()))) {
250 = std::make_pair(chain.first, &(chain.first->get(chain.second->safeName())));
251 m.add(good_chain.second->type().variable());
254 m.add(chain.second->type().variable());
255 posterior_(chain, m);
260 template <
typename GUM_SCALAR >
263 Tensor< GUM_SCALAR >& j) {
266 for (
auto chain = chains.begin(); chain != chains.end(); ++chain) {
267 j.add(chain->second->type().variable());
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
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.
Exception : operation not allowed.
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > * > Chain
Code alias.
void addEvidence(const Chain &chain, const Tensor< GUM_SCALAR > &p)
Add an evidence to the given instance's elt.
virtual ~PRMInference()
Destructor.
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
virtual void joint_(const std::vector< Chain > &queries, Tensor< GUM_SCALAR > &j)=0
Generic method to compute the posterior of given element.
void posterior(const Chain &chain, Tensor< GUM_SCALAR > &m)
Compute the posterior of the formal attribute pointed by chain and stores it in m.
HashTable< const PRMInstance< GUM_SCALAR > *, EMap * > _evidences_
Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes.
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
EMap & _EMap_(const PRMInstance< GUM_SCALAR > *i)
Private getter over evidences, if necessary creates an EMap for i.
void joint(const std::vector< Chain > &chains, Tensor< GUM_SCALAR > &j)
Compute the joint probability of the formals attributes pointed by chains and stores it in m.
void removeEvidence(const Chain &chain)
Remove evidence on the given instance's elt.
PRMSystem< GUM_SCALAR > const * sys_
The Model on which inference is done.
PRMInference & operator=(const PRMInference &source)
Copy operator.
NodeProperty< const Tensor< GUM_SCALAR > * > EMap
Code alias.
PRM< GUM_SCALAR > const * prm_
The PRM<GUM_SCALAR> on which inference is done.
virtual void posterior_(const Chain &chain, Tensor< double > &m)=0
bool hasEvidence() const
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
virtual void evidenceRemoved_(const Chain &chain)=0
This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference...
bool hasEvidence(const PRMInstance< GUM_SCALAR > &i) const
Returns true if i has evidence.
void clearEvidence()
Remove all evidences.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
const iterator & end()
Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in...
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)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities