aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::prm::StructuredInference< GUM_SCALAR >::CData Struct Reference

Private structure to represent data about a Class<GUM_SCALAR>. More...

Collaboration diagram for gum::prm::StructuredInference< GUM_SCALAR >::CData:

Public Member Functions

 CData (const PRMClass< GUM_SCALAR > &c)
 Default constructor.
 ~CData ()
 Destructor.
NodeSetinners ()
 Returns the set of inner nodes.
NodeSetaggregators ()
 Returns the set of aggregators and their parents.
NodeSetoutputs ()
 Returns the set of outputs nodes.
std::vector< NodeId > & elim_order ()
 The elimination order for nodes of this class.

Public Attributes

const PRMClass< GUM_SCALAR > & c
 The class about what this data is about.
UndiGraph moral_graph
 The class moral graph. NodeId matches those in c.
NodeProperty< Sizemods
 The class variables modalities.
List< NodeSetpartial_order
 The partial order used of variable elimination.
Set< const PRMInstance< GUM_SCALAR > * > instances
 The Set of Instances reduces at class level.
Set< Tensor< GUM_SCALAR > * > pool
 The tensor pool obtained by C elimination of inner nodes.

Private Attributes

std::vector< NodeId_elim_order_
NodeSet _inners_
NodeSet _aggregators_
NodeSet _outputs_
Set< Tensor< GUM_SCALAR > * > _trash_

Detailed Description

template<typename GUM_SCALAR>
struct gum::prm::StructuredInference< GUM_SCALAR >::CData

Private structure to represent data about a Class<GUM_SCALAR>.

Definition at line 224 of file structuredInference.h.

Constructor & Destructor Documentation

◆ CData()

template<typename GUM_SCALAR>
gum::prm::StructuredInference< GUM_SCALAR >::CData::CData ( const PRMClass< GUM_SCALAR > & c)

Default constructor.

Definition at line 821 of file structuredInference_tpl.h.

821 :
822 c(a_class), _elim_order_(0) {
824
825 // First step we add Attributes and Aggregators
826 for (const auto node: c.containerDag().nodes()) {
827 switch (c.get(node).elt_type()) {
829 pool.insert(&(const_cast< Tensor< GUM_SCALAR >& >(c.get(node).cpf())));
830 // break omited : We want to execute the next block
831 // for attributes
832 }
833
835 moral_graph.addNodeWithId(node);
836 mods.insert(node, c.get(node).type()->domainSize());
837 break;
838 }
839
840 default : { /* do nothing */
841 }
842 }
843 }
844
845 // Second, we add edges, moralise the graph and build the partial ordering
846 for (const auto node: moral_graph.nodes()) {
847 const auto& parents = c.containerDag().parents(node);
848
849 // Adding edges and marrying parents
850 for (auto tail = parents.begin(); tail != parents.end(); ++tail) {
853 moral_graph.addEdge(*tail, node);
855 ++marry;
856
857 while (marry != parents.end()) {
860 moral_graph.addEdge(*tail, *marry);
861
862 ++marry;
863 }
864 }
865 }
866
867 // Adding nodes to the partial ordering
868 switch (c.get(node).elt_type()) {
870 if (c.isOutputNode(c.get(node))) outputs().insert(node);
871 else aggregators().insert(node);
872
873 // If the aggregators is not an output and have parents which are
874 // not outputs, we must eliminate the parents after adding the
875 // aggregator's CPT
876 for (const auto par: c.containerDag().parents(node)) {
877 const auto& prnt = c.get(par);
878
879 if ((!c.isOutputNode(prnt))
882 inners().erase(prnt.id());
883 aggregators().insert(prnt.id());
884 }
885 }
886
887 break;
888 }
889
891 pool.insert(const_cast< Tensor< GUM_SCALAR >* >(&(c.get(node).cpf())));
892
893 if (c.isOutputNode(c.get(node))) outputs().insert(node);
894 else if (!aggregators().exists(node)) inners().insert(node);
895
896 break;
897 }
898
899 default : { /* Do nothing */
900 }
901 }
902 }
903
904 if (inners().size()) partial_order.insert(inners());
905
906 if (aggregators().size()) partial_order.insert(aggregators());
907
908 if (outputs().size()) partial_order.insert(outputs());
909
912 _elim_order_ = t.eliminationOrder();
913
914 for (size_t i = 0; i < inners().size(); ++i)
915 eliminateNode(&(c.get(_elim_order_[i]).type().variable()), pool, _trash_);
916 }
SetIterator< NodeId > const_iterator
Definition set.h:143
Size size() const noexcept
Returns the number of elements in the set.
Definition set_tpl.h:636
void insert(const Key &k)
Inserts a new element into the set.
Definition set_tpl.h:539
void erase(const Key &k)
Erases an element from the set.
Definition set_tpl.h:582
<agrum/PRM/structuredInference.h>
void eliminateNode(const DiscreteVariable *var, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.
NodeSet & aggregators()
Returns the set of aggregators and their parents.
Set< Tensor< GUM_SCALAR > * > _trash_
List< NodeSet > partial_order
The partial order used of variable elimination.
NodeSet & outputs()
Returns the set of outputs nodes.
UndiGraph moral_graph
The class moral graph. NodeId matches those in c.
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.

References _elim_order_, _trash_, aggregators(), c, gum::prm::eliminateNode(), gum::StaticTriangulation::eliminationOrder(), gum::Set< Key >::erase(), inners(), gum::Set< Key >::insert(), gum::prm::PRMClassElement< GUM_SCALAR >::isAggregate(), gum::prm::PRMClassElement< GUM_SCALAR >::isAttribute(), mods, moral_graph, outputs(), partial_order, pool, gum::prm::PRMClassElement< GUM_SCALAR >::prm_aggregate, gum::prm::PRMClassElement< GUM_SCALAR >::prm_attribute, and gum::Set< Key >::size().

Here is the call graph for this function:

◆ ~CData()

template<typename GUM_SCALAR>
gum::prm::StructuredInference< GUM_SCALAR >::CData::~CData ( )

Destructor.

Definition at line 919 of file structuredInference_tpl.h.

919 {
921
922 for (const auto pot: _trash_)
923 delete pot;
924 }

References _trash_.

Member Function Documentation

◆ aggregators()

template<typename GUM_SCALAR>
NodeSet & gum::prm::StructuredInference< GUM_SCALAR >::CData::aggregators ( )
inline

Returns the set of aggregators and their parents.

Definition at line 246 of file structuredInference.h.

References _aggregators_.

Referenced by CData(), and gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

Here is the caller graph for this function:

◆ elim_order()

template<typename GUM_SCALAR>
std::vector< NodeId > & gum::prm::StructuredInference< GUM_SCALAR >::CData::elim_order ( )
inline

The elimination order for nodes of this class.

Definition at line 252 of file structuredInference.h.

252{ return _elim_order_; }

References _elim_order_.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

Here is the caller graph for this function:

◆ inners()

template<typename GUM_SCALAR>
NodeSet & gum::prm::StructuredInference< GUM_SCALAR >::CData::inners ( )
inline

Returns the set of inner nodes.

Definition at line 243 of file structuredInference.h.

References _inners_.

Referenced by CData(), and gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

Here is the caller graph for this function:

◆ outputs()

template<typename GUM_SCALAR>
NodeSet & gum::prm::StructuredInference< GUM_SCALAR >::CData::outputs ( )
inline

Returns the set of outputs nodes.

Definition at line 249 of file structuredInference.h.

References _outputs_.

Referenced by CData(), and gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

Here is the caller graph for this function:

Member Data Documentation

◆ _aggregators_

template<typename GUM_SCALAR>
NodeSet gum::prm::StructuredInference< GUM_SCALAR >::CData::_aggregators_
private

Definition at line 257 of file structuredInference.h.

Referenced by aggregators().

◆ _elim_order_

template<typename GUM_SCALAR>
std::vector< NodeId > gum::prm::StructuredInference< GUM_SCALAR >::CData::_elim_order_
private

Definition at line 255 of file structuredInference.h.

Referenced by CData(), and elim_order().

◆ _inners_

template<typename GUM_SCALAR>
NodeSet gum::prm::StructuredInference< GUM_SCALAR >::CData::_inners_
private

Definition at line 256 of file structuredInference.h.

Referenced by inners().

◆ _outputs_

template<typename GUM_SCALAR>
NodeSet gum::prm::StructuredInference< GUM_SCALAR >::CData::_outputs_
private

Definition at line 258 of file structuredInference.h.

Referenced by outputs().

◆ _trash_

template<typename GUM_SCALAR>
Set< Tensor< GUM_SCALAR >* > gum::prm::StructuredInference< GUM_SCALAR >::CData::_trash_
private

Definition at line 259 of file structuredInference.h.

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

◆ c

template<typename GUM_SCALAR>
const PRMClass< GUM_SCALAR >& gum::prm::StructuredInference< GUM_SCALAR >::CData::c

The class about what this data is about.

Definition at line 226 of file structuredInference.h.

Referenced by CData(), and gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

◆ instances

template<typename GUM_SCALAR>
Set< const PRMInstance< GUM_SCALAR >* > gum::prm::StructuredInference< GUM_SCALAR >::CData::instances

The Set of Instances reduces at class level.

Definition at line 234 of file structuredInference.h.

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

◆ mods

template<typename GUM_SCALAR>
NodeProperty< Size > gum::prm::StructuredInference< GUM_SCALAR >::CData::mods

The class variables modalities.

Definition at line 230 of file structuredInference.h.

Referenced by CData(), and gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

◆ moral_graph

template<typename GUM_SCALAR>
UndiGraph gum::prm::StructuredInference< GUM_SCALAR >::CData::moral_graph

The class moral graph. NodeId matches those in c.

Definition at line 228 of file structuredInference.h.

Referenced by CData(), and gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().

◆ partial_order

template<typename GUM_SCALAR>
List< NodeSet > gum::prm::StructuredInference< GUM_SCALAR >::CData::partial_order

The partial order used of variable elimination.

Definition at line 232 of file structuredInference.h.

Referenced by CData().

◆ pool

template<typename GUM_SCALAR>
Set< Tensor< GUM_SCALAR >* > gum::prm::StructuredInference< GUM_SCALAR >::CData::pool

The tensor pool obtained by C elimination of inner nodes.

Definition at line 236 of file structuredInference.h.

Referenced by CData(), and gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_().


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