35 template <
typename GUM_SCALAR >
37 for (
const auto& elt : __evidences) {
38 for (
const auto& elt2 : *elt.second)
47 template <
typename GUM_SCALAR >
57 for (
const auto& elt2 : *elt.second) {
59 e->
add(*(elt2.second->variablesSequence().front()));
63 e->
set(i, elt2.second->get(i));
65 __evidences[elt.first]->insert(elt2.first, e);
70 template <
typename GUM_SCALAR >
80 for (
const auto& elt2 : *elt.second) {
82 e->
add(*(elt2.second->variablesSequence().front()));
86 e->
set(i, elt2.second->get(i));
89 __evidences[elt.first]->insert(elt2.first, e);
96 template <
typename GUM_SCALAR >
99 if (__evidences.exists(i)) {
100 return *(__evidences[i]);
103 return *(__evidences[i]);
107 template <
typename GUM_SCALAR >
111 if (chain.first->exists(chain.second->id())) {
112 if ((p.
nbrDim() != 1) || (!p.
contains(chain.second->type().variable())))
114 "illegal evidence for the given PRMAttribute.");
117 e->
add(chain.second->type().variable());
125 if (emap.
exists(chain.second->id())) {
126 delete emap[chain.second->id()];
127 emap[chain.second->id()] = e;
129 emap.
insert(chain.second->id(), e);
132 _evidenceAdded(chain);
135 "the given PRMAttribute does not belong to this " 136 "Instance<GUM_SCALAR>.");
140 template <
typename GUM_SCALAR >
148 template <
typename GUM_SCALAR >
154 template <
typename GUM_SCALAR >
158 return *(__evidences[&i]);
164 template <
typename GUM_SCALAR >
169 return *(__evidences[&i]);
175 template <
typename GUM_SCALAR >
179 return *(__evidences[i]);
185 template <
typename GUM_SCALAR >
190 return *(__evidences[i]);
196 template <
typename GUM_SCALAR >
199 return __evidences.exists(&i);
202 template <
typename GUM_SCALAR >
205 return __evidences.exists(i);
208 template <
typename GUM_SCALAR >
210 return (hasEvidence(chain.first))
211 ? evidence(chain.first).exists(chain.second->id())
215 template <
typename GUM_SCALAR >
217 return (__evidences.size() != (
Size)0);
220 template <
typename GUM_SCALAR >
223 if (__EMap(chain.first).exists(chain.second->id())) {
224 _evidenceRemoved(chain);
225 delete __EMap(chain.first)[chain.second->id()];
226 __EMap(chain.first).erase(chain.second->id());
233 template <
typename GUM_SCALAR >
241 if (hasEvidence(chain)) {
242 m.
add(chain.second->type().variable());
244 *(evidence(chain.first)[chain.second->id()]);
247 for (i.setFirst(), j.
setFirst(); !i.end(); i.inc(), j.
inc())
250 if (chain.second != &(chain.first->get(chain.second->safeName()))) {
252 chain.first, &(chain.first->get(chain.second->safeName())));
253 m.
add(good_chain.second->type().variable());
254 _marginal(good_chain, m);
256 m.
add(chain.second->type().variable());
262 template <
typename GUM_SCALAR >
270 for (
auto chain = chains.begin(); chain != chains.end(); ++chain) {
271 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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.