35 template <
typename GUM_SCALAR >
39 for (
const auto& elt : __reqMap)
40 delete elt.second.first;
43 template <
typename GUM_SCALAR >
45 for (
const auto& elt : __reqMap)
46 delete elt.second.first;
52 template <
typename GUM_SCALAR >
57 std::make_pair(i, &(i->
get(n)));
59 if (__inf->hasEvidence(chain)) {
65 if ((e->
get(inst) == (GUM_SCALAR)1.0))
67 else if (e->
get(inst) != (GUM_SCALAR)0.0)
75 }
catch (
NotFound&) {
return false; }
78 template <
typename GUM_SCALAR >
85 __fromChild(i, n, marks);
88 for (
const auto& elt : marks)
92 template <
typename GUM_SCALAR >
99 if (!marks[i]->exists(n)) {
100 marks[i]->
insert(n, std::pair< bool, bool >(
false,
false));
104 switch (i->
type().get(n).elt_type()) {
106 if (!__getMark(marks, i, n).first) {
107 __getMark(marks, i, n).first =
true;
111 inst, inst->get(__getSC(i, n).lastElt().safeName()).id(), marks);
114 if (!__getMark(marks, i, n).second) {
115 __getMark(marks, i, n).second =
true;
117 for (
const auto chi : i->
type().containerDag().children(n))
118 __fromParent(i, chi, marks);
126 if (!__getMark(marks, i, n).first) {
127 __getMark(marks, i, n).first =
true;
129 if (!__isHardEvidence(i, n))
130 for (
const auto par : i->
type().containerDag().parents(n))
131 __fromChild(i, par, marks);
134 if (!__getMark(marks, i, n).second) {
135 __getMark(marks, i, n).second =
true;
138 for (
const auto chi : i->
type().containerDag().children(n))
139 __fromParent(i, chi, marks);
145 for (
auto iter = refs.begin(); iter != refs.end(); ++iter)
147 iter->first, iter->first->type().get(iter->second).id(), marks);
166 template <
typename GUM_SCALAR >
173 if (!marks[i]->exists(n)) {
174 marks[i]->
insert(n, std::pair< bool, bool >(
false,
false));
178 if ((__isHardEvidence(i, n)) && (!__getMark(marks, i, n).first)) {
179 __getMark(marks, i, n).first =
true;
181 for (
const auto par : i->
type().containerDag().parents(n))
182 __fromChild(i, par, marks);
183 }
else if (!__getMark(marks, i, n).second) {
184 __getMark(marks, i, n).second =
true;
187 for (
const auto chi : i->
type().containerDag().children(n))
188 __fromParent(i, chi, marks);
196 iter->first, iter->first->type().get(iter->second).id(), marks);
203 template <
typename GUM_SCALAR >
208 for (
const auto& elt : marks) {
211 for (
const auto& elt2 : *elt.second)
212 if (elt2.second.first) req_set->
insert(elt2.first);
214 req_map.
insert(elt.first, req_set);
220 for (
const auto& elt : req_map)
221 if (elt.second->size() == 0) to_remove.
insert(elt.first);
223 for (
const auto remo : to_remove) {
224 delete req_map[remo];
229 for (
const auto& elt : req_map) {
230 std::string key = __buildHashKey(elt.first, *elt.second);
232 if (__reqMap.exists(key)) {
235 std::pair< std::string,
Set< NodeId >* >(key, __reqMap[key].first));
236 __reqMap[key].second += 1;
238 req_map[elt.first] = 0;
242 elt.first, std::pair< std::string,
Set< NodeId >* >(key, elt.second));
247 template <
typename GUM_SCALAR >
250 std::stringstream sBuff;
251 sBuff << i->
type().name();
253 for (
const auto node : i->
type().containerDag().nodes())
254 if (req_nodes.
exists(node)) sBuff <<
"-" << node;
259 template <
typename GUM_SCALAR >
266 template <
typename GUM_SCALAR >
274 template <
typename GUM_SCALAR >
280 template <
typename GUM_SCALAR >
286 template <
typename GUM_SCALAR >
292 template <
typename GUM_SCALAR >
298 template <
typename GUM_SCALAR >
304 template <
typename GUM_SCALAR >
306 const std::string&
key)
const {
310 template <
typename GUM_SCALAR >
315 template <
typename GUM_SCALAR >
321 template <
typename GUM_SCALAR >
327 template <
typename GUM_SCALAR >
333 template <
typename GUM_SCALAR >
339 template <
typename GUM_SCALAR >
346 template <
typename GUM_SCALAR >
349 return (*(marks[i]))[n];
aGrUM's Potential is a multi-dimensional array with tensor operators.
<agrum/PRM/structuredBayesBall.h>
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
virtual GUM_SCALAR get(const Instantiation &i) const final
Default implementation of MultiDimContainer::get().
const Set< NodeId > & requisiteNodes(const PRMInstance< GUM_SCALAR > *i) const
Returns the set of requisite nodes w.r.t. d-separation for i.
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
Abstract class representing an element of PRM class.
std::pair< bool, bool > & __getMark(InstanceMap &marks, const PRMInstance< GUM_SCALAR > *i, NodeId n)
Code alias.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
void compute(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Compute the set or requisite nodes for each required instance given the current set of observations...
bool __isHardEvidence(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Returns true if there is a hard evidence on i->get(n).
~StructuredBayesBall()
Destructor.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
HashTable< const PRMInstance< GUM_SCALAR > *, std::pair< std::string, Set< NodeId > *> > __keyMap
Associate an PRMInstance<GUM_SCALAR> with a unique key w.r.t. d-separation and the set of requisite n...
The class for generic Hash Tables.
HashTable< std::string, std::pair< Set< NodeId > *, Size > > __reqMap
Associate a Key with the set of requisite nodes associated with it. The Size value is the number of i...
void __fillMaps(InstanceMap &marks)
Fill __keyMap and __reqMap.
bool exists(const PRMInstance< GUM_SCALAR > *i) const
Returns true if i has requisite nodes.
std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & getRefAttr(NodeId id)
Returns a vector of pairs of refering attributes of id.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
void inc()
Operator increment.
void __fromChild(const PRMInstance< GUM_SCALAR > *i, NodeId n, InstanceMap &marks)
When the ball is received on i->get(n) from a child.
Size occurrence(const std::string &key) const
Returns the number of occurrence of the given key, which is the number of PRMInstance<GUM_SCALAR> sha...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
StructuredBayesBall & operator=(const StructuredBayesBall &source)
Copy operator.
std::string __buildHashKey(const PRMInstance< GUM_SCALAR > *i, Set< NodeId > &req_nodes)
Builds the HashKey for the given instance and requisite nodes set.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
const std::string & key(const PRMInstance< GUM_SCALAR > *i) const
Returns a unique key w.r.t. d-separation for i.
void __clean()
Cleans this before a new computation.
const PRMSlotChain< GUM_SCALAR > & __getSC(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Code alias.
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > *> Chain
Code alias.
Class for assigning/browsing values to tuples of discrete variables.
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
StructuredBayesBall(const PRMInference< GUM_SCALAR > &inference)
Default Constructor.
void setFirst()
Assign the first values to the tuple of the Instantiation.
const PRMInference< GUM_SCALAR > * __inf
The PRM at which __model belongs.
void __compute(const PRMInstance< GUM_SCALAR > *i, NodeId n)
The real compute method.
float liftRatio() const
Returns the ratio between the total number of instances and the number of instances with the same con...
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.
void __fromParent(const PRMInstance< GUM_SCALAR > *i, NodeId n, InstanceMap &marks)
When the ball is receive on i->get(n) from a parent.
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
#define GUM_ERROR(type, msg)
const Set< PRMInstance< GUM_SCALAR > *> & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
bool end() const
Returns true if the Instantiation reached the end.