aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::prm::SVED< GUM_SCALAR > Class Template Reference

This class is an implementation of the Structured Value Elimination algorithm on PRM<GUM_SCALAR>. More...

#include <agrum/PRM/SVED.h>

Inheritance diagram for gum::prm::SVED< GUM_SCALAR >:
Collaboration diagram for gum::prm::SVED< GUM_SCALAR >:

Public Types

using EMap = NodeProperty< const Tensor< GUM_SCALAR >* >
 Code alias.
using EMapIterator = typename NodeProperty< const Tensor< GUM_SCALAR >* >::iterator_safe
 Code alias.
using EMapConstIterator
 Code alias.

Public Member Functions

Constructors & destructor.
 SVED (const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &model)
 Default Constructor.
 ~SVED () override
 Destructor.
Getters & setters.
std::string name () const override
 Returns the name of the current inference algorithm.
Query methods.
void posterior (const Chain &chain, Tensor< GUM_SCALAR > &m)
 Compute the posterior of the formal attribute pointed by chain and stores it in m.
void joint (const std::vector< Chain > &chains, Tensor< GUM_SCALAR > &j)
 Compute the joint probability of the formals attributes pointed by chains and stores it in m.
Evidence handling.
EMapevidence (const PRMInstance< GUM_SCALAR > &i)
 Returns EMap of evidences over i.
EMapevidence (const PRMInstance< GUM_SCALAR > *i)
 Returns EMap of evidences over i.
const EMapevidence (const PRMInstance< GUM_SCALAR > &i) const
 Returns EMap of evidences over i.
const EMapevidence (const PRMInstance< GUM_SCALAR > *i) const
 Returns EMap of evidences over i.
bool hasEvidence (const PRMInstance< GUM_SCALAR > &i) const
 Returns true if i has evidence.
bool hasEvidence (const PRMInstance< GUM_SCALAR > *i) const
 Returns EMap of evidences over i.
bool hasEvidence (const Chain &chain) const
 Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
bool hasEvidence () const
 Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
void addEvidence (const Chain &chain, const Tensor< GUM_SCALAR > &p)
 Add an evidence to the given instance's elt.
void removeEvidence (const Chain &chain)
 Remove evidence on the given instance's elt.
void clearEvidence ()
 Remove all evidences.

Protected Attributes

Protected members.
PRM< GUM_SCALAR > const * prm_
 The PRM<GUM_SCALAR> on which inference is done.
PRMSystem< GUM_SCALAR > const * sys_
 The Model on which inference is done.

Private Types

using BucketSet = Set< Tensor< GUM_SCALAR >* >
 Code alias.
using BucketSetIterator = typename Set< Tensor< GUM_SCALAR >* >::iterator_safe
using ArraySetIterator = typename Set< MultiDimArray< GUM_SCALAR >* >::iterator_safe

Private Member Functions

Inference sub methods.
void _eliminateNodes_ (const PRMInstance< GUM_SCALAR > *query, NodeId id, BucketSet &pool, BucketSet &trash)
 Returns true if second can be eliminated before first.
void _eliminateNodesDownward_ (const PRMInstance< GUM_SCALAR > *from, const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore)
 Returns true if second can be eliminated before first.
void _eliminateNodesUpward_ (const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore)
 Returns true if second can be eliminated before first.
void _eliminateNodesWithEvidence_ (const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
 Returns true if second can be eliminated before first.
void _insertLiftedNodes_ (const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
 Returns true if second can be eliminated before first.
bool _checkElimOrder_ (const PRMInstance< GUM_SCALAR > *first, const PRMInstance< GUM_SCALAR > *second)
 Returns true if second can be eliminated before first.
void _initElimOrder_ ()
 Returns true if second can be eliminated before first.
void _insertEvidence_ (const PRMInstance< GUM_SCALAR > *i, BucketSet &pool)
 Returns true if second can be eliminated before first.
std::vector< NodeId > & _getElimOrder_ (const PRMClass< GUM_SCALAR > &c)
 Returns true if second can be eliminated before first.
Tensor< GUM_SCALAR > * _getAggTensor_ (const PRMInstance< GUM_SCALAR > *i, const PRMAggregate< GUM_SCALAR > *agg)
 Returns true if second can be eliminated before first.
void _initLiftedNodes_ (const PRMInstance< GUM_SCALAR > *i, BucketSet &trash)
 Returns true if second can be eliminated before first.
void _initReqSets_ (const PRMInstance< GUM_SCALAR > *i)
 Returns true if second can be eliminated before first.
Set< NodeId > & _getAttrSet_ (const PRMInstance< GUM_SCALAR > *i)
 Returns true if second can be eliminated before first.
Set< NodeId > & _getSCSet_ (const PRMInstance< GUM_SCALAR > *i)
 Returns true if second can be eliminated before first.
void _reduceElimList_ (const PRMInstance< GUM_SCALAR > *i, List< const PRMInstance< GUM_SCALAR > * > &elim_list, List< const PRMInstance< GUM_SCALAR > * > &reduced_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore, BucketSet &pool, BucketSet &trash)
 Returns true if second can be eliminated before first.
std::string _trim_ (std::string_view s)
 Returns true if second can be eliminated before first.

Private Attributes

HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > * > _elim_orders_
HashTable< const Set< NodeId > *, BucketSet * > _lifted_pools_
 The Set<NodeId> returned by StructuredBayesBall<GUM_SCALAR> is unique for each family of instances with the same requisite set (thus the same lifted tensors).
Sequence< std::string > * _class_elim_order_
StructuredBayesBall< GUM_SCALAR > _bb_
HashTable< const Set< NodeId > *, std::pair< Set< NodeId > *, Set< NodeId > * > > _req_set_
 First pair -> requisite Attributes Second pair -> requisite SlotChains.

Query methods.

using Chain = typename PRMInference< GUM_SCALAR >::Chain
 Code alias.
void evidenceAdded_ (const Chain &chain) override
 See PRMInference::evidenceAdded_().
void evidenceRemoved_ (const Chain &chain) override
 See PRMInference::evidenceRemoved_().
void posterior_ (const Chain &chain, Tensor< GUM_SCALAR > &m) override
 See PRMInference::posterior_().
void joint_ (const std::vector< Chain > &queries, Tensor< GUM_SCALAR > &j) override
 See PRMInference::joint_().

Private evidence handling methods and members.

using EvidenceIterator
 Code alias.
using EvidenceConstIterator
 Code alias.
HashTable< const PRMInstance< GUM_SCALAR > *, EMap * > _evidences_
 Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes.
EMap_EMap_ (const PRMInstance< GUM_SCALAR > *i)
 Private getter over evidences, if necessary creates an EMap for i.

Detailed Description

template<GUM_Numeric GUM_SCALAR>
class gum::prm::SVED< GUM_SCALAR >

This class is an implementation of the Structured Value Elimination algorithm on PRM<GUM_SCALAR>.

Definition at line 74 of file SVED.h.

Member Typedef Documentation

◆ ArraySetIterator

template<GUM_Numeric GUM_SCALAR>
using gum::prm::SVED< GUM_SCALAR >::ArraySetIterator = typename Set< MultiDimArray< GUM_SCALAR >* >::iterator_safe
private

Definition at line 125 of file SVED.h.

◆ BucketSet

template<GUM_Numeric GUM_SCALAR>
using gum::prm::SVED< GUM_SCALAR >::BucketSet = Set< Tensor< GUM_SCALAR >* >
private

Code alias.

Definition at line 123 of file SVED.h.

◆ BucketSetIterator

template<GUM_Numeric GUM_SCALAR>
using gum::prm::SVED< GUM_SCALAR >::BucketSetIterator = typename Set< Tensor< GUM_SCALAR >* >::iterator_safe
private

Definition at line 124 of file SVED.h.

◆ Chain

template<GUM_Numeric GUM_SCALAR>
using gum::prm::SVED< GUM_SCALAR >::Chain = typename PRMInference< GUM_SCALAR >::Chain
protected

Code alias.

Definition at line 105 of file SVED.h.

◆ EMap

template<GUM_Numeric GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EMap = NodeProperty< const Tensor< GUM_SCALAR >* >
inherited

Code alias.

Definition at line 74 of file PRMInference.h.

◆ EMapConstIterator

template<GUM_Numeric GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EMapConstIterator
inherited
Initial value:
typename NodeProperty< const Tensor< GUM_SCALAR >* >::const_iterator_safe
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.

Code alias.

Definition at line 80 of file PRMInference.h.

◆ EMapIterator

template<GUM_Numeric GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EMapIterator = typename NodeProperty< const Tensor< GUM_SCALAR >* >::iterator_safe
inherited

Code alias.

Definition at line 77 of file PRMInference.h.

◆ EvidenceConstIterator

template<GUM_Numeric GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EvidenceConstIterator
privateinherited
Initial value:
typename HashTable< const PRMInstance< GUM_SCALAR >*, EMap* >::const_iterator_safe
The class for generic Hash Tables.
Definition hashTable.h:640
NodeProperty< const Tensor< GUM_SCALAR > * > EMap
Code alias.

Code alias.

Definition at line 241 of file PRMInference.h.

◆ EvidenceIterator

template<GUM_Numeric GUM_SCALAR>
using gum::prm::PRMInference< GUM_SCALAR >::EvidenceIterator
privateinherited
Initial value:

Code alias.

Definition at line 238 of file PRMInference.h.

Constructor & Destructor Documentation

◆ SVED()

template<GUM_Numeric GUM_SCALAR>
gum::prm::SVED< GUM_SCALAR >::SVED ( const PRM< GUM_SCALAR > & prm,
const PRMSystem< GUM_SCALAR > & model )

Default Constructor.

Definition at line 485 of file SVED_tpl.h.

485 :
488 }
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
This class is an implementation of the Structured Value Elimination algorithm on PRM<GUM_SCALAR>.
Definition SVED.h:74
Sequence< std::string > * _class_elim_order_
Definition SVED.h:136
SVED(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &model)
Default Constructor.
Definition SVED_tpl.h:485
StructuredBayesBall< GUM_SCALAR > _bb_
Definition SVED.h:138

References gum::prm::PRMInference< GUM_SCALAR >::PRMInference(), SVED(), _bb_, and _class_elim_order_.

Referenced by SVED(), and ~SVED().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~SVED()

template<GUM_Numeric GUM_SCALAR>
gum::prm::SVED< GUM_SCALAR >::~SVED ( )
override

Destructor.

Definition at line 56 of file SVED_tpl.h.

56 {
58
59 for (const auto& elt: _elim_orders_)
60 delete elt.second;
61
62 if (_class_elim_order_ != nullptr) delete _class_elim_order_;
63 }
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > * > _elim_orders_
Definition SVED.h:127

References SVED(), _class_elim_order_, and _elim_orders_.

Here is the call graph for this function:

Member Function Documentation

◆ _checkElimOrder_()

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::SVED< GUM_SCALAR >::_checkElimOrder_ ( const PRMInstance< GUM_SCALAR > * first,
const PRMInstance< GUM_SCALAR > * second )
private

Returns true if second can be eliminated before first.

Definition at line 510 of file SVED_tpl.h.

511 {
512 if (_class_elim_order_ == 0) { _initElimOrder_(); }
513
514 auto first_name = _trim_(first->type().name());
515 auto second_name = _trim_(second->type().name());
517 }
void _initElimOrder_()
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:362
std::string name() const override
Returns the name of the current inference algorithm.
Definition SVED_tpl.h:578
std::string _trim_(std::string_view s)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:502

References _class_elim_order_, _initElimOrder_(), _trim_(), and gum::prm::PRMInstance< GUM_SCALAR >::type().

Referenced by _eliminateNodes_(), _eliminateNodesDownward_(), _eliminateNodesUpward_(), and _reduceElimList_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _eliminateNodes_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_eliminateNodes_ ( const PRMInstance< GUM_SCALAR > * query,
NodeId id,
BucketSet & pool,
BucketSet & trash )
private

Returns true if second can be eliminated before first.

Definition at line 66 of file SVED_tpl.h.

69 {
71 ignore.insert(query);
72 // Extracting required attributes and slotchains
75 // Downward elimination
77
78 for (const auto attr: attr_set) {
79 if (query->hasRefAttr(attr)) {
80 for (auto iter = query->getRefAttr(attr).begin(); iter != query->getRefAttr(attr).end();
81 ++iter)
82 if ((!ignore.exists(iter->first)) && (_bb_.exists(iter->first)))
84 }
85 }
86
87 // Eliminating all nodes in query instance, except query
89 const auto moralg = bn.moralGraph();
90 DefaultTriangulation t(&moralg, &(bn.modalities()));
92
94
95 for (const auto attr: attr_set)
96 pool.insert(&(const_cast< Tensor< GUM_SCALAR >& >(query->get(attr).cpf())));
97
98 for (size_t idx = 0; idx < t.eliminationOrder().size(); ++idx) {
99 if (t.eliminationOrder()[idx] != node) {
100 auto var_id = t.eliminationOrder()[idx];
101 const auto& var = bn.variable(var_id);
102 elim_order.push_back(&var);
103 }
104 }
105
107 // Eliminating instance in elim_list
110
111 while (!elim_list.empty()) {
112 if (_checkElimOrder_(query, elim_list.front())) {
113 if ((!ignore.exists(elim_list.front())) && (_bb_.exists(elim_list.front())))
115 } else if (_bb_.exists(elim_list.front())) {
116 tmp_list.insert(elim_list.front());
117 }
118
119 elim_list.popFront();
120 }
121
122 // Upward elimination
123 for (const auto chain: sc_set)
124 for (const auto parent: query->getInstances(chain))
125 if ((!ignore.exists(parent)) && (_bb_.exists(*parent)))
127 }
bool hasEvidence() const
Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.
void _insertEvidence_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:491
void _eliminateNodesUpward_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:194
void _reduceElimList_(const PRMInstance< GUM_SCALAR > *i, List< const PRMInstance< GUM_SCALAR > * > &elim_list, List< const PRMInstance< GUM_SCALAR > * > &reduced_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:558
Set< NodeId > & _getSCSet_(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:547
bool _checkElimOrder_(const PRMInstance< GUM_SCALAR > *first, const PRMInstance< GUM_SCALAR > *second)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:510
Set< NodeId > & _getAttrSet_(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:537
void _eliminateNodesDownward_(const PRMInstance< GUM_SCALAR > *from, const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash, List< const PRMInstance< GUM_SCALAR > * > &elim_list, Set< const PRMInstance< GUM_SCALAR > * > &ignore)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:130
void eliminateNodes(const std::vector< const DiscreteVariable * > &elim_order, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)

References _bb_, _checkElimOrder_(), _eliminateNodesDownward_(), _eliminateNodesUpward_(), _getAttrSet_(), _getSCSet_(), _insertEvidence_(), _reduceElimList_(), gum::prm::eliminateNodes(), gum::StaticTriangulation::eliminationOrder(), gum::List< Val >::empty(), gum::Set< Key >::exists(), gum::List< Val >::front(), gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::prm::PRMInstance< GUM_SCALAR >::getInstances(), gum::prm::PRMInstance< GUM_SCALAR >::getRefAttr(), gum::prm::PRMInference< GUM_SCALAR >::hasEvidence(), gum::prm::PRMInstance< GUM_SCALAR >::hasRefAttr(), gum::List< Val >::insert(), gum::Set< Key >::insert(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), gum::DAGmodel::moralGraph(), gum::List< Val >::popFront(), and gum::prm::InstanceBayesNet< GUM_SCALAR >::variable().

Referenced by posterior_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _eliminateNodesDownward_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_eliminateNodesDownward_ ( const PRMInstance< GUM_SCALAR > * from,
const PRMInstance< GUM_SCALAR > * i,
BucketSet & pool,
BucketSet & trash,
List< const PRMInstance< GUM_SCALAR > * > & elim_list,
Set< const PRMInstance< GUM_SCALAR > * > & ignore )
private

Returns true if second can be eliminated before first.

Definition at line 130 of file SVED_tpl.h.

136 {
137 ignore.insert(i);
138 // Extracting required attributes and slotchains
141 // Calling elimination over child instance
143
144 for (const auto attr: attr_set) {
145 if (i->hasRefAttr(attr)) {
146 for (auto iter = i->getRefAttr(attr).begin(); iter != i->getRefAttr(attr).end(); ++iter)
147 if ((!ignore.exists(iter->first)) && (_bb_.exists(iter->first)))
149 }
150 }
151
152 // Eliminating all nodes in current instance
153 if (this->hasEvidence(i)) {
155 } else {
157
158 for (const auto agg: i->type().aggregates())
159 if (_bb_.requisiteNodes(i).exists(agg->id())) pool.insert(_getAggTensor_(i, agg));
160
161 if (auto p_eo = _elim_orders_.tryGet(&(i->type()))) {
164
165 for (auto node: *(*p_eo)) {
166 const auto& var = bn.variable(node);
167 elim_order.push_back(&var);
168 }
169
171 }
172 }
173
174 // Calling elimination over child's parents
175 while (!my_list.empty()) {
176 if (_checkElimOrder_(i, my_list.front())) {
177 if ((!ignore.exists(my_list.front())) && (_bb_.exists(my_list.front())))
179 } else if (_bb_.exists(my_list.front())) {
180 elim_list.insert(my_list.front());
181 }
182
183 my_list.popFront();
184 }
185
186 // Adding parents instance to elim_list
187 for (const auto chain: sc_set)
188 for (const auto parent: i->getInstances(chain))
189 if ((!ignore.exists(parent)) && _bb_.exists(parent) && (parent != from))
190 elim_list.insert(parent);
191 }
void _eliminateNodesWithEvidence_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:257
Tensor< GUM_SCALAR > * _getAggTensor_(const PRMInstance< GUM_SCALAR > *i, const PRMAggregate< GUM_SCALAR > *agg)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:521
void _insertLiftedNodes_(const PRMInstance< GUM_SCALAR > *i, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:280

References _bb_, _checkElimOrder_(), _elim_orders_, _eliminateNodesDownward_(), _eliminateNodesWithEvidence_(), _getAggTensor_(), _getAttrSet_(), _getSCSet_(), _insertLiftedNodes_(), gum::prm::eliminateNodes(), gum::List< Val >::empty(), gum::List< Val >::front(), gum::prm::PRMInstance< GUM_SCALAR >::getInstances(), gum::prm::PRMInstance< GUM_SCALAR >::getRefAttr(), gum::prm::PRMInference< GUM_SCALAR >::hasEvidence(), gum::prm::PRMInstance< GUM_SCALAR >::hasRefAttr(), gum::List< Val >::insert(), gum::Set< Key >::insert(), gum::List< Val >::popFront(), gum::prm::PRMInstance< GUM_SCALAR >::type(), and gum::prm::InstanceBayesNet< GUM_SCALAR >::variable().

Referenced by _eliminateNodes_(), _eliminateNodesDownward_(), _eliminateNodesUpward_(), and _reduceElimList_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _eliminateNodesUpward_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_eliminateNodesUpward_ ( const PRMInstance< GUM_SCALAR > * i,
BucketSet & pool,
BucketSet & trash,
List< const PRMInstance< GUM_SCALAR > * > & elim_list,
Set< const PRMInstance< GUM_SCALAR > * > & ignore )
private

Returns true if second can be eliminated before first.

Definition at line 194 of file SVED_tpl.h.

199 {
200 ignore.insert(i);
201 // Extracting required attributes and slotchains
204
205 // Downward elimination
206 for (const auto attr: attr_set) {
207 if (i->hasRefAttr(attr)) {
208 for (auto iter = i->getRefAttr(attr).begin(); iter != i->getRefAttr(attr).end(); ++iter)
209 if ((!ignore.exists(iter->first)) && (_bb_.exists(iter->first)))
211 }
212 }
213
214 // Eliminating all nodes in i instance
215 if (this->hasEvidence(i)) {
217 } else {
219
220 for (const auto agg: i->type().aggregates())
221 if (_bb_.requisiteNodes(i).exists(agg->id())) pool.insert(_getAggTensor_(i, agg));
222
223 if (auto p_eo = _elim_orders_.tryGet(&(i->type()))) {
226
227 for (auto node: *(*p_eo)) {
228 const auto& var = bn.variable(node);
229 elim_order.push_back(&var);
230 }
232 }
233 }
234
235 // Eliminating instance in elim_list
237
238 while (!elim_list.empty()) {
239 if (_checkElimOrder_(i, elim_list.front())) {
240 if ((!ignore.exists(elim_list.front())) && (_bb_.exists(elim_list.front())))
242 } else if (_bb_.exists(elim_list.front())) {
243 ignore.insert(elim_list.front());
244 }
245
246 elim_list.popFront();
247 }
248
249 // Upward elimination
250 for (const auto chain: sc_set)
251 for (const auto parent: i->getInstances(chain))
252 if ((!ignore.exists(parent)) && (_bb_.exists(parent)))
254 }

References _bb_, _checkElimOrder_(), _elim_orders_, _eliminateNodesDownward_(), _eliminateNodesUpward_(), _eliminateNodesWithEvidence_(), _getAggTensor_(), _getAttrSet_(), _getSCSet_(), _insertLiftedNodes_(), gum::prm::eliminateNodes(), gum::prm::PRMInstance< GUM_SCALAR >::getInstances(), gum::prm::PRMInstance< GUM_SCALAR >::getRefAttr(), gum::prm::PRMInference< GUM_SCALAR >::hasEvidence(), gum::prm::PRMInstance< GUM_SCALAR >::hasRefAttr(), gum::Set< Key >::insert(), gum::prm::PRMInstance< GUM_SCALAR >::type(), and gum::prm::InstanceBayesNet< GUM_SCALAR >::variable().

Referenced by _eliminateNodes_(), and _eliminateNodesUpward_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _eliminateNodesWithEvidence_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_eliminateNodesWithEvidence_ ( const PRMInstance< GUM_SCALAR > * i,
BucketSet & pool,
BucketSet & trash )
private

Returns true if second can be eliminated before first.

Definition at line 257 of file SVED_tpl.h.

259 {
260 // Adding required evidences
261 for (const auto& elt: this->evidence(i))
262 if (_bb_.requisiteNodes(i).exists(elt.first))
263 pool.insert(const_cast< Tensor< GUM_SCALAR >* >(elt.second));
264
265 // Adding tensors and eliminating the remaining nodes
266 for (const auto& a: *i)
267 if (_bb_.requisiteNodes(i).exists(a.first))
268 pool.insert(&(const_cast< Tensor< GUM_SCALAR >& >(a.second->cpf())));
269
271 const auto moralg = bn.moralGraph();
272 DefaultTriangulation t(&moralg, &(bn.modalities()));
273 const std::vector< NodeId >& full_elim_order = t.eliminationOrder();
274
275 for (auto var = full_elim_order.begin(); var != full_elim_order.end(); ++var)
276 eliminateNode(&(i->get(*var).type().variable()), pool, trash);
277 }
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
void eliminateNode(const DiscreteVariable *var, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.

References _bb_, gum::prm::eliminateNode(), gum::StaticTriangulation::eliminationOrder(), gum::prm::PRMInference< GUM_SCALAR >::evidence(), gum::prm::PRMInstance< GUM_SCALAR >::get(), gum::Set< Key >::insert(), gum::prm::InstanceBayesNet< GUM_SCALAR >::modalities(), and gum::DAGmodel::moralGraph().

Referenced by _eliminateNodesDownward_(), and _eliminateNodesUpward_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _EMap_()

template<GUM_Numeric GUM_SCALAR>
PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::_EMap_ ( const PRMInstance< GUM_SCALAR > * i)
privateinherited

Private getter over evidences, if necessary creates an EMap for i.

Definition at line 117 of file PRMInference_tpl.h.

117 {
118 if (auto p = _evidences_.tryGet(i)) {
119 return **p;
120 } else {
122 _evidences_.insert(i, emap);
123 return *emap;
124 }
125 }
This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>.
HashTable< const PRMInstance< GUM_SCALAR > *, EMap * > _evidences_
Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes.

References _evidences_.

Referenced by removeEvidence().

Here is the caller graph for this function:

◆ _getAggTensor_()

template<GUM_Numeric GUM_SCALAR>
Tensor< GUM_SCALAR > * gum::prm::SVED< GUM_SCALAR >::_getAggTensor_ ( const PRMInstance< GUM_SCALAR > * i,
const PRMAggregate< GUM_SCALAR > * agg )
private

Returns true if second can be eliminated before first.

Definition at line 521 of file SVED_tpl.h.

522 {
523 return &(const_cast< Tensor< GUM_SCALAR >& >(i->get(agg->safeName()).cpf()));
524 }

References gum::prm::PRMInstance< GUM_SCALAR >::get(), and gum::prm::PRMClassElement< GUM_SCALAR >::safeName().

Referenced by _eliminateNodesDownward_(), and _eliminateNodesUpward_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _getAttrSet_()

template<GUM_Numeric GUM_SCALAR>
Set< NodeId > & gum::prm::SVED< GUM_SCALAR >::_getAttrSet_ ( const PRMInstance< GUM_SCALAR > * i)
private

Returns true if second can be eliminated before first.

Definition at line 537 of file SVED_tpl.h.

537 {
538 auto p = _req_set_.tryGet(&(_bb_.requisiteNodes(i)));
539 if (!p) {
541 p = _req_set_.tryGet(&(_bb_.requisiteNodes(i)));
542 }
543 return *(p->first);
544 }
HashTable< const Set< NodeId > *, std::pair< Set< NodeId > *, Set< NodeId > * > > _req_set_
First pair -> requisite Attributes Second pair -> requisite SlotChains.
Definition SVED.h:142
void _initReqSets_(const PRMInstance< GUM_SCALAR > *i)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:455

References _bb_, _initReqSets_(), and _req_set_.

Referenced by _eliminateNodes_(), _eliminateNodesDownward_(), and _eliminateNodesUpward_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _getElimOrder_()

template<GUM_Numeric GUM_SCALAR>
std::vector< NodeId > & gum::prm::SVED< GUM_SCALAR >::_getElimOrder_ ( const PRMClass< GUM_SCALAR > & c)
private

Returns true if second can be eliminated before first.

Definition at line 497 of file SVED_tpl.h.

497 {
498 return *(_elim_orders_[&c]);
499 }

References _elim_orders_.

◆ _getSCSet_()

template<GUM_Numeric GUM_SCALAR>
Set< NodeId > & gum::prm::SVED< GUM_SCALAR >::_getSCSet_ ( const PRMInstance< GUM_SCALAR > * i)
private

Returns true if second can be eliminated before first.

Definition at line 547 of file SVED_tpl.h.

547 {
548 auto p = _req_set_.tryGet(&(_bb_.requisiteNodes(i)));
549 if (!p) {
551 p = _req_set_.tryGet(&(_bb_.requisiteNodes(i)));
552 }
553 return *(p->second);
554 }

References _bb_, _initReqSets_(), and _req_set_.

Referenced by _eliminateNodes_(), _eliminateNodesDownward_(), and _eliminateNodesUpward_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _initElimOrder_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_initElimOrder_ ( )
private

Returns true if second can be eliminated before first.

Definition at line 362 of file SVED_tpl.h.

362 {
366
367 for (const auto node: cdg.internalDag().nodes()) {
368 if (cdg.internalDag().parents(node).empty()) { l.push_back(node); }
369 }
370
372
373 while (!l.empty()) {
374 visited_node.insert(l.front());
375
376 if (!class_elim_order.exists(cdg.get(l.front()).first)) {
377 class_elim_order.insert(cdg.get(l.front()).first);
378 }
379
380 for (const auto child: cdg.internalDag().children(l.front())) {
381 if (!visited_node.contains(child)) { l.push_back(child); }
382 }
383
384 l.pop_front();
385 }
386
388 for (auto c: class_elim_order) {
389 std::string name = c->name();
390 if (auto pos = name.find_first_of("<"); pos != std::string::npos) {
391 name = name.substr(0, pos);
392 }
393 try {
394 _class_elim_order_->insert(name);
395 } catch (DuplicateElement const&) {}
396 }
397 }
PRM< GUM_SCALAR > const * prm_
The PRM<GUM_SCALAR> on which inference is done.

References _class_elim_order_, gum::ArcGraphPart::children(), gum::Set< Key >::contains(), gum::Set< Key >::empty(), gum::SequenceImplementation< Key, Gen >::exists(), gum::prm::ClassDependencyGraph< GUM_SCALAR >::get(), gum::SequenceImplementation< Key, Gen >::insert(), gum::Set< Key >::insert(), gum::prm::ClassDependencyGraph< GUM_SCALAR >::internalDag(), name(), gum::NodeGraphPart::nodes(), gum::ArcGraphPart::parents(), and gum::prm::PRMInference< GUM_SCALAR >::prm_.

Referenced by _checkElimOrder_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _initLiftedNodes_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_ ( const PRMInstance< GUM_SCALAR > * i,
BucketSet & trash )
private

Returns true if second can be eliminated before first.

Definition at line 300 of file SVED_tpl.h.

301 {
302 PRMClass< GUM_SCALAR >& c = const_cast< PRMClass< GUM_SCALAR >& >(i->type());
304 _lifted_pools_.insert(&(_bb_.requisiteNodes(i)), lifted_pool);
305
306 for (const auto node: _bb_.requisiteNodes(i))
308 lifted_pool->insert(const_cast< Tensor< GUM_SCALAR >* >(&(c.get(node).cpf())));
309
311
312 for (const auto& elt: *i) {
313 if (_bb_.requisiteNodes(*i).exists(elt.first)) {
315 if (c.isOutputNode(c.get(elt.first))) outers.insert(elt.first);
316 else if (!outers.exists(elt.first)) inners.insert(elt.first);
317 } else if (PRMClassElement< GUM_SCALAR >::isAggregate(c.get(elt.first))) {
318 outers.insert(elt.first);
319
320 // We need to put in the output_elim_order aggregator's parents
321 // which are
322 // innner nodes
323 for (const auto par: c.containerDag().parents(elt.first))
325 && i->type().isInnerNode(i->type().get(par))
326 && _bb_.requisiteNodes(i).exists(par)) {
327 inners.erase(par);
328 outers.insert(par);
329 }
330 }
331 } else {
332 ignore.insert(elt.first);
333 }
334 }
335
336 // Now we proceed with the elimination of inner attributes
339
340 if (inners.size()) partial_ordering.pushBack(inners);
341
342 if (outers.size()) partial_ordering.pushBack(outers);
343
344 if (ignore.size()) partial_ordering.pushBack(ignore);
345
346 GUM_ASSERT(inners.size() || outers.size());
347 const auto moralg = bn.moralGraph();
349
350 for (size_t idx = 0; idx < inners.size(); ++idx)
351 eliminateNode(&(c.get(t.eliminationOrder()[idx]).type().variable()), *lifted_pool, trash);
352
353 // If there is not only inner and input Attributes
354 if (outers.size()) {
355 _elim_orders_.insert(&c,
356 new std::vector< NodeId >(t.eliminationOrder().begin() + inners.size(),
357 t.eliminationOrder().end()));
358 }
359 }
Set< Tensor< GUM_SCALAR > * > BucketSet
Code alias.
Definition SVED.h:123
HashTable< const Set< NodeId > *, BucketSet * > _lifted_pools_
The Set<NodeId> returned by StructuredBayesBall<GUM_SCALAR> is unique for each family of instances wi...
Definition SVED.h:134

References _bb_, _elim_orders_, _lifted_pools_, gum::prm::PRMClassElementContainer< GUM_SCALAR >::containerDag(), gum::prm::eliminateNode(), gum::StaticTriangulation::eliminationOrder(), gum::Set< Key >::erase(), gum::Set< Key >::exists(), gum::prm::PRMClass< GUM_SCALAR >::get(), gum::Set< Key >::insert(), gum::prm::PRMClassElement< GUM_SCALAR >::isAggregate(), gum::prm::PRMClassElement< GUM_SCALAR >::isAttribute(), gum::prm::PRMClass< GUM_SCALAR >::isOutputNode(), gum::prm::ClassBayesNet< GUM_SCALAR >::modalities(), gum::DAGmodel::moralGraph(), gum::ArcGraphPart::parents(), gum::List< Val >::pushBack(), gum::Set< Key >::size(), and gum::prm::PRMInstance< GUM_SCALAR >::type().

Referenced by _insertLiftedNodes_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _initReqSets_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_initReqSets_ ( const PRMInstance< GUM_SCALAR > * i)
private

Returns true if second can be eliminated before first.

Definition at line 455 of file SVED_tpl.h.

455 {
458
459 for (const auto node: _bb_.requisiteNodes(i)) {
460 switch (i->type().get(node).elt_type()) {
463 attr_set->insert(node);
464 break;
465 }
466
468 sc_set->insert(node);
469 break;
470 }
471
472 default : {
474 "There should not be elements other"
475 " than PRMAttribute<GUM_SCALAR> and SlotChain.");
476 }
477 }
478 }
479
480 _req_set_.insert(&(_bb_.requisiteNodes(i)),
482 }
#define GUM_ERROR(type, msg)
Definition exceptions.h:76

References _bb_, _req_set_, GUM_ERROR, gum::Set< Key >::insert(), gum::prm::PRMClassElement< GUM_SCALAR >::prm_aggregate, gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, gum::prm::PRMClassElement< GUM_SCALAR >::prm_slotchain, and gum::prm::PRMInstance< GUM_SCALAR >::type().

Referenced by _getAttrSet_(), and _getSCSet_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _insertEvidence_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_insertEvidence_ ( const PRMInstance< GUM_SCALAR > * i,
BucketSet & pool )
private

Returns true if second can be eliminated before first.

Definition at line 491 of file SVED_tpl.h.

491 {
492 for (const auto& elt: this->evidence(i))
493 pool.insert(const_cast< Tensor< GUM_SCALAR >* >(elt.second));
494 }

References gum::prm::PRMInference< GUM_SCALAR >::evidence(), and gum::Set< Key >::insert().

Referenced by _eliminateNodes_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _insertLiftedNodes_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_insertLiftedNodes_ ( const PRMInstance< GUM_SCALAR > * i,
BucketSet & pool,
BucketSet & trash )
private

Returns true if second can be eliminated before first.

Definition at line 280 of file SVED_tpl.h.

282 {
283 BucketSet* lifted_pool = nullptr;
284
285 auto p_lp = _lifted_pools_.tryGet(&(_bb_.requisiteNodes(i)));
286 if (!p_lp) {
288 p_lp = _lifted_pools_.tryGet(&(_bb_.requisiteNodes(i)));
289 }
290 lifted_pool = *p_lp;
291
292 for (const auto lifted_pot: *lifted_pool) {
294 pool.insert(pot);
295 trash.insert(pot);
296 }
297 }
void _initLiftedNodes_(const PRMInstance< GUM_SCALAR > *i, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:300
Tensor< GUM_SCALAR > * copyTensor(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const Tensor< GUM_SCALAR > &source)
Returns a copy of a Tensor after applying a bijection over the variables in source.

References _bb_, _initLiftedNodes_(), _lifted_pools_, gum::prm::PRMInstance< GUM_SCALAR >::bijection(), gum::prm::copyTensor(), and gum::Set< Key >::insert().

Referenced by _eliminateNodesDownward_(), and _eliminateNodesUpward_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _reduceElimList_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::_reduceElimList_ ( const PRMInstance< GUM_SCALAR > * i,
List< const PRMInstance< GUM_SCALAR > * > & elim_list,
List< const PRMInstance< GUM_SCALAR > * > & reduced_list,
Set< const PRMInstance< GUM_SCALAR > * > & ignore,
BucketSet & pool,
BucketSet & trash )
private

Returns true if second can be eliminated before first.

Definition at line 558 of file SVED_tpl.h.

563 {
564 while (!elim_list.empty()) {
565 if (_checkElimOrder_(i, elim_list.front())) {
566 if ((!ignore.exists(elim_list.front())) && (_bb_.exists(elim_list.front()))) {
568 }
569 } else if (_bb_.exists(elim_list.front())) {
570 reduced_list.insert(elim_list.front());
571 }
572
573 elim_list.popFront();
574 }
575 }

References _bb_, _checkElimOrder_(), and _eliminateNodesDownward_().

Referenced by _eliminateNodes_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _trim_()

template<GUM_Numeric GUM_SCALAR>
std::string gum::prm::SVED< GUM_SCALAR >::_trim_ ( std::string_view s)
private

Returns true if second can be eliminated before first.

Definition at line 502 of file SVED_tpl.h.

502 {
503 if (auto pos = s.find_first_of("<"); pos != std::string::npos) {
504 return std::string{s.substr(0, pos)};
505 }
506 return std::string{s};
507 }

Referenced by _checkElimOrder_().

Here is the caller graph for this function:

◆ addEvidence()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMInference< GUM_SCALAR >::addEvidence ( const Chain & chain,
const Tensor< GUM_SCALAR > & p )
inherited

Add an evidence to the given instance's elt.

Parameters
chainThe variable being observed.
pThe Tensor added (by copy) as evidence.
Exceptions
NotFoundRaised if elt does not belong to i.
OperationNotAllowedRaised if p is inconsistent with elt.

Definition at line 128 of file PRMInference_tpl.h.

129 {
130 if (chain.first->exists(chain.second->id())) {
131 if ((p.nbrDim() != 1) || (!p.contains(chain.second->type().variable())))
132 GUM_ERROR(OperationNotAllowed, "illegal evidence for the given PRMAttribute.")
133
135 e->add(chain.second->type().variable());
136 Instantiation i(*e);
137
138 for (i.setFirst(); !i.end(); i.inc())
139 e->set(i, p.get(i));
140
142
143 if (emap.exists(chain.second->id())) {
144 delete emap[chain.second->id()];
145 emap[chain.second->id()] = e;
146 } else {
147 emap.insert(chain.second->id(), e);
148 }
149
151 } else {
153 "the given PRMAttribute does not belong to this "
154 "Instance<GUM_SCALAR>.");
155 }
156 }
EMap & _EMap_(const PRMInstance< GUM_SCALAR > *i)
Private getter over evidences, if necessary creates an EMap for i.
virtual void evidenceAdded_(const Chain &chain)=0
This method is called whenever an evidence is added, but AFTER any processing made by PRMInference.

References gum::Instantiation::end(), GUM_ERROR, gum::Instantiation::inc(), and gum::Instantiation::setFirst().

Here is the call graph for this function:

◆ clearEvidence()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMInference< GUM_SCALAR >::clearEvidence ( )
inherited

Remove all evidences.

Definition at line 57 of file PRMInference_tpl.h.

57 {
58 for (const auto& elt: _evidences_) {
59 for (const auto& elt2: *elt.second)
60 delete elt2.second;
61
62 delete elt.second;
63 }
64
65 _evidences_.clear();
66 }

References _evidences_.

Referenced by ~PRMInference(), and operator=().

Here is the caller graph for this function:

◆ evidence() [1/4]

template<GUM_Numeric GUM_SCALAR>
PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > & i)
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 173 of file PRMInference_tpl.h.

173 {
174 if (!_evidences_.exists(&i)) GUM_ERROR(NotFound, "this instance has no evidence.")
175 return *(_evidences_[&i]);
176 }

References _evidences_, and GUM_ERROR.

Referenced by gum::prm::SVE< GUM_SCALAR >::_eliminateNodesWithEvidence_(), gum::prm::SVED< GUM_SCALAR >::_eliminateNodesWithEvidence_(), gum::prm::SVE< GUM_SCALAR >::_insertEvidence_(), gum::prm::SVED< GUM_SCALAR >::_insertEvidence_(), gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_(), evidence(), gum::prm::GroundedInference< GUM_SCALAR >::evidenceAdded_(), hasEvidence(), posterior(), and gum::prm::StructuredInference< GUM_SCALAR >::posterior_().

Here is the caller graph for this function:

◆ evidence() [2/4]

template<GUM_Numeric GUM_SCALAR>
const PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > & i) const
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 180 of file PRMInference_tpl.h.

180 {
181 if (!_evidences_.exists(&i)) GUM_ERROR(NotFound, "this instance has no evidence.")
182 return *(_evidences_[&i]);
183 }

References _evidences_, and GUM_ERROR.

◆ evidence() [3/4]

template<GUM_Numeric GUM_SCALAR>
PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > * i)
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 187 of file PRMInference_tpl.h.

187 {
188 if (!_evidences_.exists(i)) GUM_ERROR(NotFound, "this instance has no evidence.")
189 return *(_evidences_[i]);
190 }

References PRMInference(), _evidences_, evidence(), and GUM_ERROR.

Here is the call graph for this function:

◆ evidence() [4/4]

template<GUM_Numeric GUM_SCALAR>
const PRMInference< GUM_SCALAR >::EMap & gum::prm::PRMInference< GUM_SCALAR >::evidence ( const PRMInstance< GUM_SCALAR > * i) const
inherited

Returns EMap of evidences over i.

Exceptions
NotFoundif i has no evidence.

Definition at line 194 of file PRMInference_tpl.h.

194 {
195 if (!_evidences_.exists(i)) GUM_ERROR(NotFound, "this instance has no evidence.")
196 return *(_evidences_[i]);
197 }

References _evidences_, and GUM_ERROR.

◆ evidenceAdded_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::evidenceAdded_ ( const Chain & chain)
overrideprotectedvirtual

See PRMInference::evidenceAdded_().

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 527 of file SVED_tpl.h.

527 {
528 // Do nothing
529 }

◆ evidenceRemoved_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::evidenceRemoved_ ( const Chain & chain)
overrideprotectedvirtual

See PRMInference::evidenceRemoved_().

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 532 of file SVED_tpl.h.

532 {
533 // Do nothing
534 }

◆ hasEvidence() [1/4]

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( ) const
inherited

Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.

Definition at line 215 of file PRMInference_tpl.h.

215 {
216 return (_evidences_.size() != (Size)0);
217 }

References _evidences_.

◆ hasEvidence() [2/4]

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( const Chain & chain) const
inherited

Returns true if i has evidence on PRMAttribute<GUM_SCALAR> a.

Definition at line 210 of file PRMInference_tpl.h.

210 {
211 return (hasEvidence(chain.first)) ? evidence(chain.first).exists(chain.second->id()) : false;
212 }
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.

References evidence(), and hasEvidence().

Here is the call graph for this function:

◆ hasEvidence() [3/4]

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( const PRMInstance< GUM_SCALAR > & i) const
inherited

◆ hasEvidence() [4/4]

template<GUM_Numeric GUM_SCALAR>
bool gum::prm::PRMInference< GUM_SCALAR >::hasEvidence ( const PRMInstance< GUM_SCALAR > * i) const
inherited

Returns EMap of evidences over i.

Definition at line 205 of file PRMInference_tpl.h.

205 {
206 return _evidences_.exists(i);
207 }

References _evidences_.

◆ joint()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMInference< GUM_SCALAR >::joint ( const std::vector< Chain > & chains,
Tensor< GUM_SCALAR > & j )
inherited

Compute the joint probability of the formals attributes pointed by chains and stores it in m.

Parameters
chainsA Set of strings of the form instance.attribute.
jAn empty CPF which will be filed by the joint probability over chains.
Exceptions
NotFoundRaised if some chain in chains does not point to a formal attribute.
OperationNotAllowedRaise if m is not empty.

Definition at line 257 of file PRMInference_tpl.h.

259 {
260 if (j.nbrDim() > 0) { GUM_ERROR(OperationNotAllowed, "the given Tensor is not empty.") }
261
262 for (auto chain = chains.begin(); chain != chains.end(); ++chain) {
263 j.add(chain->second->type().variable());
264 }
265
266 joint_(chains, j);
267 }
virtual void joint_(const std::vector< Chain > &queries, Tensor< GUM_SCALAR > &j)=0
Generic method to compute the posterior of given element.

References GUM_ERROR, and joint_().

Here is the call graph for this function:

◆ joint_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::joint_ ( const std::vector< Chain > & queries,
Tensor< GUM_SCALAR > & j )
overrideprotectedvirtual

See PRMInference::joint_().

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 450 of file SVED_tpl.h.

450 {
451 GUM_ERROR(FatalError, "Not implemented.")
452 }

References GUM_ERROR.

◆ name()

template<GUM_Numeric GUM_SCALAR>
std::string gum::prm::SVED< GUM_SCALAR >::name ( ) const
overridevirtual

Returns the name of the current inference algorithm.

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 578 of file SVED_tpl.h.

578 {
579 return "SVED";
580 }

Referenced by _initElimOrder_().

Here is the caller graph for this function:

◆ posterior()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMInference< GUM_SCALAR >::posterior ( const Chain & chain,
Tensor< GUM_SCALAR > & m )
inherited

Compute the posterior of the formal attribute pointed by chain and stores it in m.

Parameters
chainA string of the form instance.attribute.
mAn empty CPF which will be filed by the posterior of chain.
Exceptions
NotFoundRaised if chain is invalid.
TypeErrorRaised if chain does not point to an PRMAttribute<GUM_SCALAR>.
OperationNotAllowedRaise if m is not empty.

Definition at line 231 of file PRMInference_tpl.h.

233 {
234 if (m.nbrDim() > 0) { GUM_ERROR(OperationNotAllowed, "the given Tensor is not empty.") }
235
236 if (hasEvidence(chain)) {
237 m.add(chain.second->type().variable());
238 const Tensor< GUM_SCALAR >& e = *(evidence(chain.first)[chain.second->id()]);
239 Instantiation i(m), j(e);
240
241 for (i.setFirst(), j.setFirst(); !i.end(); i.inc(), j.inc())
242 m.set(i, e.get(j));
243 } else {
244 if (chain.second != &(chain.first->get(chain.second->safeName()))) {
246 = std::make_pair(chain.first, &(chain.first->get(chain.second->safeName())));
247 m.add(good_chain.second->type().variable());
249 } else {
250 m.add(chain.second->type().variable());
252 }
253 }
254 }
virtual void posterior_(const Chain &chain, Tensor< GUM_SCALAR > &m)=0
Generic method to compute the posterior of given element.

References gum::prm::PRMInstance< GUM_SCALAR >::end(), evidence(), GUM_ERROR, hasEvidence(), gum::Instantiation::inc(), and gum::Instantiation::setFirst().

Here is the call graph for this function:

◆ posterior_()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::SVED< GUM_SCALAR >::posterior_ ( const Chain & chain,
Tensor< GUM_SCALAR > & m )
overrideprotectedvirtual

See PRMInference::posterior_().

Implements gum::prm::PRMInference< GUM_SCALAR >.

Definition at line 400 of file SVED_tpl.h.

400 {
401 const PRMInstance< GUM_SCALAR >* i = chain.first;
402 const PRMAttribute< GUM_SCALAR >* elt = chain.second;
404 _bb_.compute(i, elt->id());
405 _eliminateNodes_(i, elt->id(), pool, trash);
406
408 for (auto pot: pool) {
409 if (pot->contains(*(m.variablesSequence().atPos(0)))) result.push_back(pot);
410 }
411
412 while (result.size() > 1) {
413 const auto& p1 = *(result.back());
414 result.pop_back();
415 const auto& p2 = *(result.back());
416 result.pop_back();
417 auto mult = new Tensor< GUM_SCALAR >(p1 * p2);
418 result.push_back(mult);
419 trash.insert(mult);
420 }
421
422 m = *(result.back());
423 m.normalize();
424
425 GUM_ASSERT(m.nbrDim() == (Size)1);
426
427 // cleaning up the mess
428 for (const auto pot: trash)
429 delete pot;
430
431 for (const auto& elt: _lifted_pools_)
432 delete elt.second;
433
434 _lifted_pools_.clear();
435
436 for (const auto& elt: _req_set_) {
437 delete elt.second.first;
438 delete elt.second.second;
439 }
440
441 _req_set_.clear();
442
443 for (const auto& elt: _elim_orders_)
444 delete elt.second;
445
446 _elim_orders_.clear();
447 }
void _eliminateNodes_(const PRMInstance< GUM_SCALAR > *query, NodeId id, BucketSet &pool, BucketSet &trash)
Returns true if second can be eliminated before first.
Definition SVED_tpl.h:66

References _bb_, _elim_orders_, _eliminateNodes_(), _lifted_pools_, _req_set_, gum::prm::PRMClassElement< GUM_SCALAR >::id(), and gum::Set< Key >::insert().

Here is the call graph for this function:

◆ removeEvidence()

template<GUM_Numeric GUM_SCALAR>
void gum::prm::PRMInference< GUM_SCALAR >::removeEvidence ( const Chain & chain)
inherited

Remove evidence on the given instance's elt.

Parameters
chainThe variable being observed.
Exceptions
NotFoundRaised if the given names are not found.
TypeErrorRaised if the elt is not an PRMAttribute<GUM_SCALAR>.

Definition at line 220 of file PRMInference_tpl.h.

220 {
221 if (hasEvidence(chain.first)) {
222 if (_EMap_(chain.first).exists(chain.second->id())) {
224 delete _EMap_(chain.first)[chain.second->id()];
225 _EMap_(chain.first).erase(chain.second->id());
226 }
227 }
228 }
void erase(const Key &key)
Removes a given element from the hash table.
virtual void evidenceRemoved_(const Chain &chain)=0
This method is called whenever an evidence is removed, but BEFORE any processing made by PRMInference...

References _EMap_(), evidenceRemoved_(), and hasEvidence().

Here is the call graph for this function:

Member Data Documentation

◆ _bb_

◆ _class_elim_order_

template<GUM_Numeric GUM_SCALAR>
Sequence< std::string >* gum::prm::SVED< GUM_SCALAR >::_class_elim_order_
private

Definition at line 136 of file SVED.h.

Referenced by SVED(), ~SVED(), _checkElimOrder_(), and _initElimOrder_().

◆ _elim_orders_

template<GUM_Numeric GUM_SCALAR>
HashTable< const PRMClass< GUM_SCALAR >*, std::vector< NodeId >* > gum::prm::SVED< GUM_SCALAR >::_elim_orders_
private

◆ _evidences_

template<GUM_Numeric GUM_SCALAR>
HashTable< const PRMInstance< GUM_SCALAR >*, EMap* > gum::prm::PRMInference< GUM_SCALAR >::_evidences_
privateinherited

Mapping of evidence over PRMInstance<GUM_SCALAR>'s nodes.

Definition at line 245 of file PRMInference.h.

Referenced by PRMInference(), _EMap_(), clearEvidence(), evidence(), evidence(), evidence(), evidence(), hasEvidence(), hasEvidence(), and hasEvidence().

◆ _lifted_pools_

template<GUM_Numeric GUM_SCALAR>
HashTable< const Set< NodeId >*, BucketSet* > gum::prm::SVED< GUM_SCALAR >::_lifted_pools_
private

The Set<NodeId> returned by StructuredBayesBall<GUM_SCALAR> is unique for each family of instances with the same requisite set (thus the same lifted tensors).

Definition at line 134 of file SVED.h.

Referenced by _initLiftedNodes_(), _insertLiftedNodes_(), and posterior_().

◆ _req_set_

template<GUM_Numeric GUM_SCALAR>
HashTable< const Set< NodeId >*, std::pair< Set< NodeId >*, Set< NodeId >* > > gum::prm::SVED< GUM_SCALAR >::_req_set_
private

First pair -> requisite Attributes Second pair -> requisite SlotChains.

Definition at line 142 of file SVED.h.

Referenced by _getAttrSet_(), _getSCSet_(), _initReqSets_(), and posterior_().

◆ prm_

◆ sys_


The documentation for this class was generated from the following files: