32 template <
typename GUM_SCALAR >
34 for (
const auto& elt : __evidences) {
35 for (
const auto& elt2 : *elt.second)
44 template <
typename GUM_SCALAR >
54 for (
const auto& elt2 : *elt.second) {
56 e->
add(*(elt2.second->variablesSequence().front()));
60 e->
set(i, elt2.second->get(i));
62 __evidences[elt.first]->insert(elt2.first, e);
67 template <
typename GUM_SCALAR >
77 for (
const auto& elt2 : *elt.second) {
79 e->
add(*(elt2.second->variablesSequence().front()));
83 e->
set(i, elt2.second->get(i));
86 __evidences[elt.first]->insert(elt2.first, e);
93 template <
typename GUM_SCALAR >
96 if (__evidences.exists(i)) {
97 return *(__evidences[i]);
100 return *(__evidences[i]);
104 template <
typename GUM_SCALAR >
108 if (chain.first->exists(chain.second->id())) {
109 if ((p.
nbrDim() != 1) || (!p.
contains(chain.second->type().variable())))
111 "illegal evidence for the given PRMAttribute.");
114 e->
add(chain.second->type().variable());
122 if (emap.
exists(chain.second->id())) {
123 delete emap[chain.second->id()];
124 emap[chain.second->id()] = e;
126 emap.
insert(chain.second->id(), e);
129 _evidenceAdded(chain);
132 "the given PRMAttribute does not belong to this " 133 "Instance<GUM_SCALAR>.");
137 template <
typename GUM_SCALAR >
145 template <
typename GUM_SCALAR >
151 template <
typename GUM_SCALAR >
155 return *(__evidences[&i]);
161 template <
typename GUM_SCALAR >
166 return *(__evidences[&i]);
172 template <
typename GUM_SCALAR >
176 return *(__evidences[i]);
182 template <
typename GUM_SCALAR >
187 return *(__evidences[i]);
193 template <
typename GUM_SCALAR >
196 return __evidences.exists(&i);
199 template <
typename GUM_SCALAR >
202 return __evidences.exists(i);
205 template <
typename GUM_SCALAR >
207 return (hasEvidence(chain.first))
208 ? evidence(chain.first).exists(chain.second->id())
212 template <
typename GUM_SCALAR >
214 return (__evidences.size() != (
Size)0);
217 template <
typename GUM_SCALAR >
220 if (__EMap(chain.first).exists(chain.second->id())) {
221 _evidenceRemoved(chain);
222 delete __EMap(chain.first)[chain.second->id()];
223 __EMap(chain.first).erase(chain.second->id());
230 template <
typename GUM_SCALAR >
238 if (hasEvidence(chain)) {
239 m.
add(chain.second->type().variable());
241 *(evidence(chain.first)[chain.second->id()]);
244 for (i.setFirst(), j.
setFirst(); !i.end(); i.inc(), j.
inc())
247 if (chain.second != &(chain.first->get(chain.second->safeName()))) {
249 chain.first, &(chain.first->get(chain.second->safeName())));
250 m.
add(good_chain.second->type().variable());
251 _marginal(good_chain, m);
253 m.
add(chain.second->type().variable());
259 template <
typename GUM_SCALAR >
267 for (
auto chain = chains.begin(); chain != chains.end(); ++chain) {
268 j.
add(chain->second->type().variable());
aGrUM's Potential is a multi-dimensional array with tensor operators.
virtual Idx nbrDim() const final
Returns the number of vars in the multidimensional container.
virtual GUM_SCALAR get(const Instantiation &i) const final
Default implementation of MultiDimContainer::get().
HashTable< const PRMInstance< GUM_SCALAR > *, EMap *> __evidences
Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes.
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
gum is the global namespace for all aGrUM entities
PRM< GUM_SCALAR > const * _prm
The PRM<GUM_SCALAR> on which inference is done.
The class for generic Hash Tables.
void inc()
Operator increment.
void clearEvidence()
Remove all evidences.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
PRMSystem< GUM_SCALAR > const * _sys
The Model on which inference is done.
std::pair< const PRMInstance< double > *, const PRMAttribute< double > * > Chain
Code alias.
Class for assigning/browsing values to tuples of discrete variables.
virtual void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const final
Default implementation of MultiDimContainer::set().
void setFirst()
Assign the first values to the tuple of the Instantiation.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
virtual bool contains(const DiscreteVariable &var) const final
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
bool end() const
Returns true if the Instantiation reached the end.