32 template <
typename GUM_SCALAR >
36 for (
const auto& elt : __reqMap)
37 delete elt.second.first;
40 template <
typename GUM_SCALAR >
42 for (
const auto& elt : __reqMap)
43 delete elt.second.first;
49 template <
typename GUM_SCALAR >
54 std::make_pair(i, &(i->
get(n)));
56 if (__inf->hasEvidence(chain)) {
62 if ((e->
get(inst) == (GUM_SCALAR)1.0))
64 else if (e->
get(inst) != (GUM_SCALAR)0.0)
72 }
catch (
NotFound&) {
return false; }
75 template <
typename GUM_SCALAR >
82 __fromChild(i, n, marks);
85 for (
const auto& elt : marks)
89 template <
typename GUM_SCALAR >
96 if (!marks[i]->exists(n)) {
97 marks[i]->
insert(n, std::pair< bool, bool >(
false,
false));
101 switch (i->
type().get(n).elt_type()) {
103 if (!__getMark(marks, i, n).first) {
104 __getMark(marks, i, n).first =
true;
108 inst, inst->get(__getSC(i, n).lastElt().safeName()).id(), marks);
111 if (!__getMark(marks, i, n).second) {
112 __getMark(marks, i, n).second =
true;
114 for (
const auto chi : i->
type().containerDag().children(n))
115 __fromParent(i, chi, marks);
123 if (!__getMark(marks, i, n).first) {
124 __getMark(marks, i, n).first =
true;
126 if (!__isHardEvidence(i, n))
127 for (
const auto par : i->
type().containerDag().parents(n))
128 __fromChild(i, par, marks);
131 if (!__getMark(marks, i, n).second) {
132 __getMark(marks, i, n).second =
true;
135 for (
const auto chi : i->
type().containerDag().children(n))
136 __fromParent(i, chi, marks);
142 for (
auto iter = refs.begin(); iter != refs.end(); ++iter)
144 iter->first, iter->first->type().get(iter->second).id(), marks);
163 template <
typename GUM_SCALAR >
170 if (!marks[i]->exists(n)) {
171 marks[i]->
insert(n, std::pair< bool, bool >(
false,
false));
175 if ((__isHardEvidence(i, n)) && (!__getMark(marks, i, n).first)) {
176 __getMark(marks, i, n).first =
true;
178 for (
const auto par : i->
type().containerDag().parents(n))
179 __fromChild(i, par, marks);
180 }
else if (!__getMark(marks, i, n).second) {
181 __getMark(marks, i, n).second =
true;
184 for (
const auto chi : i->
type().containerDag().children(n))
185 __fromParent(i, chi, marks);
193 iter->first, iter->first->type().get(iter->second).id(), marks);
200 template <
typename GUM_SCALAR >
205 for (
const auto& elt : marks) {
208 for (
const auto& elt2 : *elt.second)
209 if (elt2.second.first) req_set->
insert(elt2.first);
211 req_map.
insert(elt.first, req_set);
217 for (
const auto& elt : req_map)
218 if (elt.second->size() == 0) to_remove.
insert(elt.first);
220 for (
const auto remo : to_remove) {
221 delete req_map[remo];
226 for (
const auto& elt : req_map) {
227 std::string key = __buildHashKey(elt.first, *elt.second);
229 if (__reqMap.exists(key)) {
232 std::pair< std::string,
Set< NodeId >* >(key, __reqMap[key].first));
233 __reqMap[key].second += 1;
235 req_map[elt.first] = 0;
239 elt.first, std::pair< std::string,
Set< NodeId >* >(key, elt.second));
244 template <
typename GUM_SCALAR >
247 std::stringstream sBuff;
248 sBuff << i->
type().name();
250 for (
const auto node : i->
type().containerDag().nodes())
251 if (req_nodes.
exists(node)) sBuff <<
"-" << node;
256 template <
typename GUM_SCALAR >
263 template <
typename GUM_SCALAR >
271 template <
typename GUM_SCALAR >
277 template <
typename GUM_SCALAR >
283 template <
typename GUM_SCALAR >
289 template <
typename GUM_SCALAR >
295 template <
typename GUM_SCALAR >
301 template <
typename GUM_SCALAR >
303 const std::string&
key)
const {
307 template <
typename GUM_SCALAR >
312 template <
typename GUM_SCALAR >
318 template <
typename GUM_SCALAR >
324 template <
typename GUM_SCALAR >
330 template <
typename GUM_SCALAR >
336 template <
typename GUM_SCALAR >
343 template <
typename GUM_SCALAR >
346 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.
gum is the global namespace for all aGrUM entities
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...
Headers of StructuredBayesBall.
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.