55 template <
typename GUM_SCALAR >
60 delete elt.second.first;
63 template <
typename GUM_SCALAR >
66 delete elt.second.first;
72 template <
typename GUM_SCALAR >
78 if (
_inf_->hasEvidence(chain)) {
79 const Tensor< GUM_SCALAR >* e =
_inf_->evidence(i)[n];
84 if ((e->get(inst) == (GUM_SCALAR)1.0)) ++count;
85 else if (e->get(inst) != (GUM_SCALAR)0.0)
return false;
92 }
catch (
NotFound const&) {
return false; }
95 template <
typename GUM_SCALAR >
105 for (
const auto& elt: marks)
109 template <
typename GUM_SCALAR >
115 if (!marks[i]->
exists(n)) { marks[i]->
insert(n, std::pair< bool, bool >(
false,
false)); }
118 switch (i->
type().get(n).elt_type()) {
130 for (
const auto chi: i->
type().containerDag().children(n))
143 for (
const auto par: i->
type().containerDag().parents(n))
151 for (
const auto chi: i->
type().containerDag().children(n))
158 for (
auto iter = refs.begin(); iter != refs.end(); ++iter)
159 _fromParent_(iter->first, iter->first->type().get(iter->second).id(), marks);
178 template <
typename GUM_SCALAR >
184 if (!marks[i]->
exists(n)) { marks[i]->
insert(n, std::pair< bool, bool >(
false,
false)); }
190 for (
const auto par: i->
type().containerDag().parents(n))
192 }
else if (!
_getMark_(marks, i, n).second) {
196 for (
const auto chi: i->
type().containerDag().children(n))
202 _fromParent_(iter->first, iter->first->type().get(iter->second).id(), marks);
209 template <
typename GUM_SCALAR >
214 for (
const auto& elt: marks) {
217 for (
const auto& elt2: *elt.second)
218 if (elt2.second.first) req_set->
insert(elt2.first);
220 req_map.
insert(elt.first, req_set);
226 for (
const auto& elt: req_map)
227 if (elt.second->size() == 0) to_remove.
insert(elt.first);
229 for (
const auto remo: to_remove) {
230 delete req_map[remo];
235 for (
const auto& elt: req_map) {
243 req_map[elt.first] = 0;
251 template <
typename GUM_SCALAR >
255 std::stringstream sBuff;
256 sBuff << i->
type().name();
258 for (
const auto node: i->
type().containerDag().nodes())
259 if (req_nodes.
exists(node)) sBuff <<
"-" << node;
264 template <
typename GUM_SCALAR >
270 template <
typename GUM_SCALAR >
272 const StructuredBayesBall< GUM_SCALAR >& source) : _inf_(0) {
277 template <
typename GUM_SCALAR >
279 const StructuredBayesBall< GUM_SCALAR >& source) {
283 template <
typename GUM_SCALAR >
284 INLINE
const std::string&
289 template <
typename GUM_SCALAR >
290 INLINE
const std::string&
295 template <
typename GUM_SCALAR >
301 template <
typename GUM_SCALAR >
307 template <
typename GUM_SCALAR >
312 template <
typename GUM_SCALAR >
317 template <
typename GUM_SCALAR >
323 template <
typename GUM_SCALAR >
329 template <
typename GUM_SCALAR >
335 template <
typename GUM_SCALAR >
341 template <
typename GUM_SCALAR >
347 template <
typename GUM_SCALAR >
348 INLINE std::pair< bool, bool >&
352 return (*(marks[i]))[n];
Exception : fatal (unknown ?) error.
The class for generic Hash Tables.
void erase(const Key &key)
Removes a given element from the hash table.
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.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > * > Chain
Code alias.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & getRefAttr(NodeId id)
Returns a vector of pairs of refering attributes of id.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
const Set< PRMInstance< GUM_SCALAR > * > & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
<agrum/PRM/structuredBayesBall.h>
float liftRatio() const
Returns the ratio between the total number of instances and the number of instances with the same con...
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...
const PRMInference< GUM_SCALAR > * _inf_
The PRM at which model belongs.
const Set< NodeId > & requisiteNodes(const PRMInstance< GUM_SCALAR > *i) const
Returns the set of requisite nodes w.r.t. d-separation for i.
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.
HashTable< NodeId, std::pair< bool, bool > > MarkMap
Code alias.
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...
StructuredBayesBall & operator=(const StructuredBayesBall &source)
Copy operator.
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....
StructuredBayesBall(const PRMInference< GUM_SCALAR > &inference)
Default Constructor.
void _fillMaps_(InstanceMap &marks)
Fill keyMap and reqMap.
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...
void _fromParent_(const PRMInstance< GUM_SCALAR > *i, NodeId n, InstanceMap &marks)
When the ball is receive on i->get(n) from a parent.
void _fromChild_(const PRMInstance< GUM_SCALAR > *i, NodeId n, InstanceMap &marks)
When the ball is received on i->get(n) from a child.
bool exists(const PRMInstance< GUM_SCALAR > *i) const
Returns true if i has requisite nodes.
void _compute_(const PRMInstance< GUM_SCALAR > *i, NodeId n)
The real compute method.
std::string _buildHashKey_(const PRMInstance< GUM_SCALAR > *i, Set< NodeId > &req_nodes)
Builds the HashKey for the given instance and requisite nodes set.
HashTable< const PRMInstance< GUM_SCALAR > *, MarkMap * > InstanceMap
const PRMSlotChain< GUM_SCALAR > & _getSC_(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Code alias.
~StructuredBayesBall()
Destructor.
std::pair< bool, bool > & _getMark_(InstanceMap &marks, const PRMInstance< GUM_SCALAR > *i, NodeId n)
Code alias.
bool _isHardEvidence_(const PRMInstance< GUM_SCALAR > *i, NodeId n)
Returns true if there is a hard evidence on i->get(n).
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities
Headers of StructuredBayesBall.