aGrUM 3.1.1
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<GUM_Numeric 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<GUM_Numeric GUM_SCALAR>
gum::prm::StructuredInference< GUM_SCALAR >::CData::CData ( const PRMClass< GUM_SCALAR > & c)

Default constructor.

Definition at line 825 of file structuredInference_tpl.h.

825 :
826 c(a_class), _elim_order_(0) {
828
829 // First step we add Attributes and Aggregators
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())));
834 // break omited : We want to execute the next block
835 // for attributes
836 }
837
839 moral_graph.addNodeWithId(node);
840 mods.insert(node, c.get(node).type()->domainSize());
841 break;
842 }
843
844 default : { /* do nothing */
845 }
846 }
847 }
848
849 // Second, we add edges, moralise the graph and build the partial ordering
850 for (const auto node: moral_graph.nodes()) {
851 const auto& parents = c.containerDag().parents(node);
852
853 // Adding edges and marrying parents
854 for (auto tail = parents.begin(); tail != parents.end(); ++tail) {
857 moral_graph.addEdge(*tail, node);
859 ++marry;
860
861 while (marry != parents.end()) {
864 moral_graph.addEdge(*tail, *marry);
865
866 ++marry;
867 }
868 }
869 }
870
871 // Adding nodes to the partial ordering
872 switch (c.get(node).elt_type()) {
874 if (c.isOutputNode(c.get(node))) outputs().insert(node);
875 else aggregators().insert(node);
876
877 // If the aggregators is not an output and have parents which are
878 // not outputs, we must eliminate the parents after adding the
879 // aggregator's CPT
880 for (const auto par: c.containerDag().parents(node)) {
881 const auto& prnt = c.get(par);
882
883 if ((!c.isOutputNode(prnt))
886 inners().erase(prnt.id());
887 aggregators().insert(prnt.id());
888 }
889 }
890
891 break;
892 }
893
895 pool.insert(const_cast< Tensor< GUM_SCALAR >* >(&(c.get(node).cpf())));
896
897 if (c.isOutputNode(c.get(node))) outputs().insert(node);
898 else if (!aggregators().exists(node)) inners().insert(node);
899
900 break;
901 }
902
903 default : { /* Do nothing */
904 }
905 }
906 }
907
908 if (inners().size()) partial_order.insert(inners());
909
910 if (aggregators().size()) partial_order.insert(aggregators());
911
912 if (outputs().size()) partial_order.insert(outputs());
913
916 _elim_order_ = t.eliminationOrder();
917
918 for (size_t i = 0; i < inners().size(); ++i)
919 eliminateNode(&(c.get(_elim_order_[i]).type().variable()), pool, _trash_);
920 }
SetIterator< NodeId > const_iterator
Definition set.h:141
void insert(const Key &k)
Inserts a new element into the set.
Definition set_tpl.h:510
void erase(const Key &k)
Erases an element from the set.
Definition set_tpl.h:553
Size size() const noexcept
Returns the number of elements in the set.
Definition set_tpl.h:607
<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<GUM_Numeric GUM_SCALAR>
gum::prm::StructuredInference< GUM_SCALAR >::CData::~CData ( )

Destructor.

Definition at line 923 of file structuredInference_tpl.h.

923 {
925
926 for (const auto pot: _trash_)
927 delete pot;
928 }

References _trash_.

Member Function Documentation

◆ aggregators()

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

Returns the set of aggregators and their parents.

Definition at line 1049 of file structuredInference_tpl.h.

1049 {
1050 return _aggregators_;
1051 }

References _aggregators_.

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

Here is the caller graph for this function:

◆ elim_order()

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

The elimination order for nodes of this class.

Definition at line 1059 of file structuredInference_tpl.h.

1059 {
1060 return _elim_order_;
1061 }

References _elim_order_.

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

Here is the caller graph for this function:

◆ inners()

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

Returns the set of inner nodes.

Definition at line 1044 of file structuredInference_tpl.h.

1044 {
1045 return _inners_;
1046 }

References _inners_.

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

Here is the caller graph for this function:

◆ outputs()

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

Returns the set of outputs nodes.

Definition at line 1054 of file structuredInference_tpl.h.

1054 {
1055 return _outputs_;
1056 }

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<GUM_Numeric 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<GUM_Numeric 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<GUM_Numeric GUM_SCALAR>
NodeSet gum::prm::StructuredInference< GUM_SCALAR >::CData::_inners_
private

Definition at line 256 of file structuredInference.h.

Referenced by inners().

◆ _outputs_

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

Definition at line 258 of file structuredInference.h.

Referenced by outputs().

◆ _trash_

template<GUM_Numeric 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<GUM_Numeric 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<GUM_Numeric 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<GUM_Numeric 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<GUM_Numeric 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<GUM_Numeric 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<GUM_Numeric 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: