56 template < GUM_Numeric GUM_SCALAR >
73 template < GUM_Numeric GUM_SCALAR >
82 template < GUM_Numeric GUM_SCALAR >
102 template < GUM_Numeric GUM_SCALAR >
114 template < GUM_Numeric GUM_SCALAR >
118 template < GUM_Numeric GUM_SCALAR >
122 template < GUM_Numeric GUM_SCALAR >
125 Tensor< GUM_SCALAR >& m) {
131 if (!this->
hasEvidence() && (chain.second->cpf().nbrDim() == 1)) {
135 m.set(i, chain.second->cpf().get(i));
152 for (
const auto pot: data.
pool)
153 if (pot->contains(
_query_.second->type().variable())) pots.
insert(pot);
155 if (pots.
size() == 1) {
156 Tensor< GUM_SCALAR >* pot =
const_cast< Tensor< GUM_SCALAR >*
>(*(pots.
begin()));
157 GUM_ASSERT(pot->contains(
_query_.second->type().variable()));
158 GUM_ASSERT(pot->variablesSequence().size() == 1);
161 for (i.setFirst(), j.
setFirst(); !i.end(); i.inc(), j.
inc())
162 m.set(j, pot->get(i));
165 Tensor< GUM_SCALAR >* tmp = Comb.
execute(pots);
168 for (i.setFirst(), j.
setFirst(); !i.end(); i.inc(), j.
inc())
169 m.set(i, tmp->get(j));
174 Tensor< GUM_SCALAR >* pot = *(data.
pool.
begin());
175 GUM_ASSERT(pot->contains(
_query_.second->type().variable()));
176 GUM_ASSERT(pot->variablesSequence().size() == 1);
179 for (i.setFirst(), j.
setFirst(); !i.end(); i.inc(), j.
inc())
180 m.set(j, pot->get(i));
193 template < GUM_Numeric GUM_SCALAR >
196 Tensor< GUM_SCALAR >& j) {
200 template < GUM_Numeric GUM_SCALAR >
203 s << std::format(
"Triangulation time: {}\n",
triang_time);
204 s << std::format(
"Pattern mining time: {}\n",
mining_time);
205 s << std::format(
"Pattern elimination time: {}\n",
pattern_time);
206 s << std::format(
"Inner node elimination time: {}\n",
inner_time);
207 s << std::format(
"Observed node elimination time: {}\n",
obs_time);
208 s << std::format(
"Full inference time: {}\n",
full_time);
209 s << std::format(
"#patterns: {}\n",
_gspan_->patterns().size());
211 using Iter = std::vector< gspan::Pattern* >::const_iterator;
213 for (Iter p =
_gspan_->patterns().begin(); p !=
_gspan_->patterns().end(); ++p) {
214 if (
_gspan_->matches(**p).size()) {
215 s << std::format(
"Pattern n°{} match count: {}\n", count++,
_gspan_->matches(**p).size());
216 s << std::format(
"Pattern n°{} instance count: {}\n", count++, (**p).size());
223 template < GUM_Numeric GUM_SCALAR >
234 using Iter = std::vector< gspan::Pattern* >::const_iterator;
236 for (Iter p =
_gspan_->patterns().begin(); p !=
_gspan_->patterns().end(); ++p)
252 for (
size_t i = 0; i < data.
outputs().size(); ++i)
256 template < GUM_Numeric GUM_SCALAR >
265 for (
size_t i = 0; i < data.
inners().size(); ++i)
272 for (
const auto elt: **iter)
277 else _elim_map_.insert(*iter,
new Set< Tensor< GUM_SCALAR >* >(pool));
282 for (; iter != data.
matches.end(); ++iter) {
288 for (; iter != data.
matches.end(); ++iter) {
295 for (
const auto pat: fake_patterns) {
296 for (
const auto elt: *pat)
305 for (
const auto m: data.
matches)
313 template < GUM_Numeric GUM_SCALAR >
320 std::pair< Idx, std::string >& v) {
321 if ((*inst).hasRefAttr((*inst).get(v.second).id())) {
322 std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >& refs
325 for (
auto r = refs.begin(); r != refs.end(); ++r) {
326 if (!match.exists(r->first)) {
334 for (
const auto m: data.
matches) {
335 if (this->
hasEvidence(std::make_pair((*m)[v.first], &((*m)[v.first]->get(v.second))))) {
336 GUM_ASSERT(inst->
type().name() == (*m)[v.first]->type().name());
337 GUM_ASSERT(inst->
get(v.second).safeName() == (*m)[v.first]->get(v.second).safeName());
347 template < GUM_Numeric GUM_SCALAR >
350 Set< Tensor< GUM_SCALAR >* >& pool,
352 std::pair< Idx, std::string > v;
353 Tensor< GUM_SCALAR >* pot = 0;
355 for (
const auto inst: match) {
356 for (
const auto& elt: *inst) {
358 v = std::make_pair(match.pos(inst), elt.second->safeName());
359 data.
map.insert(
id, v);
361 data.
mod.insert(
id, elt.second->type()->domainSize());
362 data.
vars.insert(
id, &(elt.second->type().variable()));
363 pool.insert(
const_cast< Tensor< GUM_SCALAR >*
>(&(elt.second->cpf())));
364 pot = &(
const_cast< Tensor< GUM_SCALAR >&
>(inst->get(v.second).cpf()));
366 for (
const auto var: pot->variablesSequence()) {
367 if (data.
vars.existsSecond(var)) {
377 && (inst->type().containerDag().children(elt.second->id()).size() == 0)
384 for (
const auto mat: data.
matches) {
388 = match.atPos(pos)->get(
_query_.second->safeName()).type().variable();
403 template < GUM_Numeric GUM_SCALAR >
406 std::pair< Idx, std::string > attr) {
407 for (
const auto mat: data.
matches)
408 if (mat->atPos(attr.first)->hasRefAttr(mat->atPos(attr.first)->get(attr.second).id()))
414 template < GUM_Numeric GUM_SCALAR >
417 Set< Tensor< GUM_SCALAR >* >& pool) {
420 for (
const auto node: data.
barren) {
421 for (
const auto pot: pool)
422 if (pot->contains(*data.
vars.second(node))) {
436 Tensor< GUM_SCALAR >* my_pot =
nullptr;
439 while (candidates.
size()) {
440 node = candidates.
back();
441 candidates.
erase(node);
444 for (
const auto pot: pool) {
445 if (pot->contains(*data.
vars.second(node))) {
466 template < GUM_Numeric GUM_SCALAR >
470 const Set< Tensor< GUM_SCALAR >* >& pool,
472 const std::vector< NodeId >& elim_order) {
474 std::pair< Idx, std::string > target;
477 for (
size_t idx = data.
inners().
size(); idx < end; ++idx) {
478 target = data.
map[data.
vars.first(data.
vars.second(elim_order[idx]))];
479 eliminateNode(&(match[target.first]->get(target.second).type().variable()),
487 template < GUM_Numeric GUM_SCALAR >
490 const Set< Tensor< GUM_SCALAR >* >& pool,
492 const std::vector< NodeId >& elim_order) {
494 std::pair< Idx, std::string > target;
497 for (
size_t idx = data.
inners().
size(); idx < end; ++idx) {
498 target = data.
map[data.
vars.first(data.
vars.second(elim_order[idx]))];
499 eliminateNode(&(match[target.first]->get(target.second).type().variable()),
507 template < GUM_Numeric GUM_SCALAR >
510 const Set< Tensor< GUM_SCALAR >* >& pool,
514 for (
const auto iter = data.
matches.begin(); iter != data.
matches.end(); ++iter) {
515 GUM_ASSERT((**iter).size() == match.size());
517 for (
Size idx = 0; idx < match.size(); ++idx) {
518 GUM_ASSERT((**iter).atPos(idx)->type() == match.atPos(idx)->type());
524 std::pair< Idx, std::string > target;
528 for (
Size idx = 0; idx < match.size(); ++idx) {
530 const auto& chains = source[idx]->type().slotChains();
532 for (
const auto sc: chains) {
534 GUM_ASSERT(!(sc->isMultiple()));
539 ->getInstance(sc->id())
540 .get(sc->lastElt().safeName())
544 ->getInstance(sc->id())
545 .get(sc->lastElt().safeName())
550 if (bij.
first(&(match[idx]
551 ->getInstance(sc->id())
552 .get(sc->lastElt().safeName())
556 ->getInstance(sc->id())
557 .get(sc->lastElt().safeName())
571 for (
const auto p: pool) {
572 for (
const auto v: p->variablesSequence()) {
573 if (data.
vars.existsSecond(v)) {
574 auto varId = data.
vars.first(v);
575 if (
auto p_map = data.
map.tryGet(varId)) {
578 bij.
insert(v, &(match[target.first]->get(target.second).type().variable()));
587 for (
const auto pot: *my_pool)
598 template < GUM_Numeric GUM_SCALAR >
602 Tensor< GUM_SCALAR >* pot =
nullptr;
605 for (
const auto& elt: *this->
sys_) {
628 partial_order[0].
insert(agg);
636 if (partial_order[0].empty()) partial_order.
erase(0);
638 if (partial_order.
size() > 1) {
641 if (partial_order[1].empty()) partial_order.
erase(1);
646 partial_order.
insert(query_set);
649 for (
auto attr = inst->
begin(); attr != inst->
end(); ++attr)
650 pool.
insert(&(
const_cast< Tensor< GUM_SCALAR >&
>((*(attr.val())).cpf())));
654 for (
const auto& elt: this->
evidence(inst))
655 pool.
insert(
const_cast< Tensor< GUM_SCALAR >*
>(elt.second));
660 if (partial_order.
size() > 1)
661 for (
size_t idx = 0; idx < partial_order[0].
size(); ++idx)
666 for (
const auto& elt: *inst)
667 pool.
insert(&
const_cast< Tensor< GUM_SCALAR >&
>(elt.second->cpf()));
670 for (
const auto& elt: this->
evidence(inst))
671 pool.
insert(
const_cast< Tensor< GUM_SCALAR >*
>(elt.second));
675 for (
size_t idx = 0; idx < partial_order[0].
size(); ++idx)
685 for (
const auto srcPot: data->
pool) {
691 for (
const auto agg: data->
c.aggregates())
692 pool.
insert(&(
const_cast< Tensor< GUM_SCALAR >&
>(inst->
get(agg->id()).cpf())));
699 for (
size_t idx = data->
inners().
size(); idx < size; ++idx)
705 for (
const auto pot: pool)
712 template < GUM_Numeric GUM_SCALAR >
719 for (
const auto pot: data.
pool) {
722 for (
Size var_1 = 0; var_1 < vars.
size(); ++var_1) {
728 data.
mods.insert(id_1, vars.
atPos(var_1)->domainSize());
732 for (
Size var_2 = var_1 + 1; var_2 < vars.
size(); ++var_2) {
738 data.
mods.insert(id_2, vars.
atPos(var_2)->domainSize());
752 for (
const auto pot: *elt.second) {
756 for (
Size var_1 = 0; var_1 < vars.
size(); ++var_1) {
762 data.
mods.insert(id_1, vars.
atPos(var_1)->domainSize());
766 for (
Size var_2 = var_1 + 1; var_2 < vars.
size(); ++var_2) {
772 data.
mods.insert(id_2, vars.
atPos(var_2)->domainSize());
785 template < GUM_Numeric GUM_SCALAR >
792 template < GUM_Numeric GUM_SCALAR >
799 for (
int i = 0; i < 4; ++i)
803 template < GUM_Numeric GUM_SCALAR >
806 pattern(source.pattern), matches(source.matches),
graph(source.
graph), mod(source.mod),
807 node2attr(source.node2attr), vars(source.vars), _partial_order_(source._partial_order_),
812 template < GUM_Numeric GUM_SCALAR >
824 template < GUM_Numeric GUM_SCALAR >
830 for (
const auto node:
c.containerDag().nodes()) {
831 switch (
c.get(node).elt_type()) {
833 pool.insert(&(
const_cast< Tensor< GUM_SCALAR >&
>(
c.get(node).cpf())));
840 mods.insert(node,
c.get(node).type()->domainSize());
851 const auto& parents =
c.containerDag().parents(node);
854 for (
auto tail = parents.begin(); tail != parents.end(); ++tail) {
861 while (marry != parents.end()) {
872 switch (
c.get(node).elt_type()) {
880 for (
const auto par:
c.containerDag().parents(node)) {
881 const auto& prnt =
c.get(par);
883 if ((!
c.isOutputNode(prnt))
895 pool.insert(
const_cast< Tensor< GUM_SCALAR >*
>(&(
c.get(node).cpf())));
922 template < GUM_Numeric GUM_SCALAR >
930 template < GUM_Numeric GUM_SCALAR >
939 template < GUM_Numeric GUM_SCALAR >
944 template < GUM_Numeric GUM_SCALAR >
951 template < GUM_Numeric GUM_SCALAR >
958 template < GUM_Numeric GUM_SCALAR >
965 template < GUM_Numeric GUM_SCALAR >
970 template < GUM_Numeric GUM_SCALAR >
975 template < GUM_Numeric GUM_SCALAR >
977 return "StructuredInference";
980 template < GUM_Numeric GUM_SCALAR >
985 template < GUM_Numeric GUM_SCALAR >
990 template < GUM_Numeric GUM_SCALAR >
994 Set< Tensor< GUM_SCALAR >* >& pool) {
998 GUM_ASSERT(!data.
mod.exists(
id));
1002 GUM_ASSERT(!data.
map.exists(
id));
1003 data.
vars.eraseFirst(
id);
1004 GUM_ASSERT(!data.
vars.existsFirst(
id));
1007 pool.erase(data.
pots[
id]);
1008 GUM_ASSERT(!pool.exists(data.
pots[
id]));
1009 data.
pots.erase(
id);
1010 GUM_ASSERT(!data.
pots.exists(
id));
1013 template < GUM_Numeric GUM_SCALAR >
1018 template < GUM_Numeric GUM_SCALAR >
1023 template < GUM_Numeric GUM_SCALAR >
1028 template < GUM_Numeric GUM_SCALAR >
1033 template < GUM_Numeric GUM_SCALAR >
1038 template < GUM_Numeric GUM_SCALAR >
1043 template < GUM_Numeric GUM_SCALAR >
1048 template < GUM_Numeric GUM_SCALAR >
1053 template < GUM_Numeric GUM_SCALAR >
1058 template < GUM_Numeric GUM_SCALAR >
void insert(const T1 &first, const T2 &second)
const T1 & first(const T2 &second) const
Returns the first value of a pair given its second value.
void eraseFirst(const T1 &first)
bool existsFirst(const T1 &first) const
Set of pairs of elements with fast search for both elements.
Base class for discrete random variable.
Exception : a similar element already exists.
const NodeSet & neighbours(NodeId id) const
returns the set of node neighbours to a given node
Base class for all aGrUM's exceptions.
Exception : fatal (unknown ?) error.
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.
Generic doubly linked lists.
Size size() const noexcept
Returns the number of elements in the list.
Val & push_back(Args &&... args)
An alias for pushBack used for STL compliance.
Val & insert(const Val &val)
Inserts a new element at the end of the chained list (alias of pushBack).
void erase(Size i)
Erases the ith element of the List (the first one is in position 0).
A class to combine efficiently several MultiDim tables.
TABLE * execute(const Set< const TABLE * > &set) const final
Creates and returns the result of the combination of the tables within set.
bool exists(const NodeId id) const
alias for existsNode
virtual NodeId addNode()
insert a new node and return its id
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
const Key & atPos(Idx i) const
Returns the object at the pos i.
void insert(const Key &k)
Size size() const noexcept
The generic class for storing (ordered) sequences of objects.
SetIterator< Sequence< PRMInstance< GUM_SCALAR > * > * > const_iterator
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
iterator begin() const
The usual unsafe begin iterator to parse the set.
void insert(const Key &k)
Inserts a new element into the set.
void erase(const Key &k)
Erases an element from the set.
Size size() const noexcept
Returns the number of elements in the set.
const std::vector< NodeId > & eliminationOrder() override
returns an elimination ordering compatible with the triangulated graph
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
void eraseNode(NodeId id) override
remove a node and its adjacent edges from the graph
This class discovers pattern in a PRM<GUM_SCALAR>'s PRMSystem<GUM_SCALAR> to speed up structured infe...
Set< Sequence< PRMInstance< GUM_SCALAR > * > * > MatchedInstances
Code alias.
PRMAttribute is a member of a Class in a PRM.
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
std::pair< const PRMInstance< GUM_SCALAR > *, const PRMAttribute< GUM_SCALAR > * > Chain
Code alias.
PRMInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system)
Default constructor.
EMap & evidence(const PRMInstance< GUM_SCALAR > &i)
Returns EMap of evidences over i.
PRMSystem< GUM_SCALAR > const * sys_
The Model on which inference is done.
PRM< GUM_SCALAR > const * prm_
The PRM<GUM_SCALAR> on which inference is done.
bool hasEvidence(const PRMInstance< GUM_SCALAR > &i) const
Returns true if i has evidence.
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
const iterator & end()
Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in...
Size size() const
Returns the number of attributes in this PRMInstance<GUM_SCALAR>.
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
const Bijection< const DiscreteVariable *, const DiscreteVariable * > & bijection() const
Returns a mapping between DiscreteVariable used in this and the ones used in this PRMInstance<GUM_SCA...
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & getRefAttr(NodeId id)
Returns a vector of pairs of refering attributes of id.
iterator begin()
Returns an iterator at the begining of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInst...
const std::string & name() const
Returns the name of this object.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>.
void searchPatterns()
Search for patterns without doing any computations.
Set< Tensor< GUM_SCALAR > * > * _eliminateObservedNodes_(typename StructuredInference::PData &data, const Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match, const std::vector< NodeId > &elim_order)
Add in data.queries() any queried variable in one of data.pattern matches.
HashTable< const PRMClass< GUM_SCALAR > *, CData * > _cdata_map_
Mapping between a Class<GUM_SCALAR> and data about instances reduced using only Class<GUM_SCALAR> lev...
void _reducePattern_(const gspan::Pattern *p)
Proceed with the elimination of all inner variables (observed or not) of all usable matches of Patter...
void _removeNode_(typename StructuredInference::PData &data, NodeId id, Set< Tensor< GUM_SCALAR > * > &pool)
std::string name() const override
Tells this algorithm to use pattern mining or not.
void posterior_(const typename PRMInference< GUM_SCALAR >::Chain &chain, Tensor< GUM_SCALAR > &m) override
See PRMInference::posterior_().
std::string _dot_
Unreduce the match containing the query.
void evidenceAdded_(const typename PRMInference< GUM_SCALAR >::Chain &chain) override
See PRMInference::evidenceAdded_().
void _buildReduceGraph_(RGData &data)
This calls reducePattern() over each pattern and then build the reduced graph which is used for infer...
void _removeBarrenNodes_(typename StructuredInference::PData &data, Set< Tensor< GUM_SCALAR > * > &pool)
HashTable< const Sequence< PRMInstance< GUM_SCALAR > * > *, Set< Tensor< GUM_SCALAR > * > * > _elim_map_
Mapping between a Pattern's match and its tensor pool after inner variables were eliminated.
HashTable< const PRMClass< GUM_SCALAR > *, std::vector< NodeId > * > _outputs_
std::string _str_(const PRMInstance< GUM_SCALAR > *i, const PRMAttribute< GUM_SCALAR > *a) const
PRMInference< GUM_SCALAR >::Chain _query_
The query.
void evidenceRemoved_(const typename PRMInference< GUM_SCALAR >::Chain &chain) override
See PRMInference::evidenceRemoved_().
GSpan< GUM_SCALAR > & gspan()
Returns the instance of gspan used to search patterns.
void _buildPatternGraph_(PData &data, Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match)
Build the DAG corresponding to Pattern data.pattern, initialize pool with all the Tensors of all vari...
PData * _pdata_
The pattern data of the pattern which one of its matches contains the query.
Set< Tensor< GUM_SCALAR > * > * _translatePotSet_(typename StructuredInference::PData &data, const Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match)
Translate a given Tensor Set into one w.r.t. variables in match.
void _insertNodeInElimLists_(typename StructuredInference::PData &data, const Sequence< PRMInstance< GUM_SCALAR > * > &match, PRMInstance< GUM_SCALAR > *inst, PRMAttribute< GUM_SCALAR > *attr, NodeId id, std::pair< Idx, std::string > &v)
StructuredInference & operator=(const StructuredInference &source)
Copy operator.
void _addEdgesInReducedGraph_(RGData &data)
Add the nodes in the reduced graph.
~StructuredInference() override
Destructor.
void setPatternMining(bool b)
Tells this algorithm to use pattern mining or not.
bool _mining_
Flag which tells to use pattern mining or not.
GSpan< GUM_SCALAR > * _gspan_
Pointer over th GSpan<GUM_SCALAR> instance used by this class.
bool _found_query_
Flag with an explicit name.
bool _allInstanceNoRefAttr_(typename StructuredInference::PData &data, std::pair< Idx, std::string > attr)
Set< const PRMInstance< GUM_SCALAR > * > _reducedInstances_
This keeps track of reduced instances.
StructuredInference(const PRM< GUM_SCALAR > &prm, const PRMSystem< GUM_SCALAR > &system, gspan::SearchStrategy< GUM_SCALAR > *strategy=0)
Default constructor.
Set< Tensor< GUM_SCALAR > * > * _eliminateObservedNodesInSource_(typename StructuredInference::PData &data, const Set< Tensor< GUM_SCALAR > * > &pool, const Sequence< PRMInstance< GUM_SCALAR > * > &match, const std::vector< NodeId > &elim_order)
Set< Tensor< GUM_SCALAR > * > _trash_
Keeping track of create tensors to delete them after inference.
void _reduceAloneInstances_(RGData &data)
Add the reduced tensors of instances not in any used patterns.
void joint_(const std::vector< typename PRMInference< GUM_SCALAR >::Chain > &queries, Tensor< GUM_SCALAR > &j) override
See PRMInference::joint_().
std::pair< Idx, std::string > _query_data_
This contains all the information we want for a node in a DFSTree.
This is an abstract class used to tune search strategies in the gspan algorithm.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Size NodeId
Type for node ids.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
namespace for all probabilistic relational models entities
Tensor< GUM_SCALAR > multTensor(const Tensor< GUM_SCALAR > &t1, const Tensor< GUM_SCALAR > &t2)
void eliminateNode(const DiscreteVariable *var, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.
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.
gum is the global namespace for all aGrUM entities
Private structure to represent data about a Class<GUM_SCALAR>.
NodeSet & aggregators()
Returns the set of aggregators and their parents.
std::vector< NodeId > _elim_order_
Set< Tensor< GUM_SCALAR > * > _trash_
List< NodeSet > partial_order
The partial order used of variable elimination.
Set< const PRMInstance< GUM_SCALAR > * > instances
The Set of Instances reduces at class level.
NodeSet & outputs()
Returns the set of outputs nodes.
UndiGraph moral_graph
The class moral graph. NodeId matches those in c.
CData(const PRMClass< GUM_SCALAR > &c)
Default constructor.
std::vector< NodeId > & elim_order()
The elimination order for nodes of this class.
Set< Tensor< GUM_SCALAR > * > pool
The tensor pool obtained by C elimination of inner nodes.
NodeSet & inners()
Returns the set of inner nodes.
const PRMClass< GUM_SCALAR > & c
The class about what this data is about.
NodeProperty< Size > mods
The class variables modalities.
Private structure to represent data about a pattern.
List< NodeSet > _partial_order_
We'll use a PartialOrderedTriangulation with three sets: output, nodes and obs with children outside ...
NodeSet & obs()
Returns the set of inner and observed nodes given all the matches of pattern.
NodeSet & queries()
Returns the set of queried nodes given all the matches of pattern.
const List< NodeSet > * partial_order()
Set< NodeId > barren
Set of barren nodes.
Bijection< NodeId, std::string > node2attr
A bijection to easily keep track between graph and attributes, its of the form instance_name DOT attr...
NodeProperty< std::pair< Idx, std::string > > map
To ease translating tensors from one match to another.
UndiGraph graph
A yet to be triangulated undigraph.
NodeSet & outputs()
Returns the set of outputs nodes given all the matches of pattern.
const gspan::Pattern & pattern
The pattern for which this represents data about it.
NodeSet & inners()
Returns the set of inner nodes.
NodeProperty< Tensor< GUM_SCALAR > * > pots
To handle barren nodes.
Bijection< NodeId, const DiscreteVariable * > vars
Bijection between graph's nodes and their corresponding DiscreteVariable, for inference purpose.
List< NodeSet > * _real_order_
A copy of partial_order without empty sets.
PData(const gspan::Pattern &p, typename GSpan< GUM_SCALAR >::MatchedInstances &m)
Default constructor.
NodeProperty< Size > mod
The pattern's variables modalities.
GSpan< GUM_SCALAR >::MatchedInstances & matches
A reference over the usable matches of pattern.
Private structure to represent data about a reduced graph.
List< NodeSet > partial_order
Partial order used for triangulation, first is outputs nodes, second query nodes.
Set< Tensor< GUM_SCALAR > * > pool
The pool of tensors matching the reduced graph.
RGData()
Default constructor.
Bijection< const DiscreteVariable *, NodeId > var2node
Mapping between DiscreteVariable and NodeId.
NodeSet & queries()
Returns the set of query nodes (which will not be eliminated).
UndiGraph reducedGraph
The reduced graph.
NodeSet & outputs()
Returns the set of outputs nodes (which will be eliminated).
NodeProperty< Size > mods
Mapping between NodeId and modalities.
Headers of StructuredInference.