aGrUM  0.20.3
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 Attributes

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

Public Member Functions

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

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 209 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 803 of file structuredInference_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

803  :
804  c(a_class), _elim_order_(0) {
805  GUM_CONSTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
806 
807  // First step we add Attributes and Aggregators
808  for (const auto node: c.containerDag().nodes()) {
809  switch (c.get(node).elt_type()) {
811  pool.insert(&(const_cast< Potential< GUM_SCALAR >& >(c.get(node).cpf())));
812  // break omited : We want to execute the next block
813  // for attributes
814  }
815 
818  mods.insert(node, c.get(node).type()->domainSize());
819  break;
820  }
821 
822  default: { /* do nothing */
823  }
824  }
825  }
826 
827  // Second, we add edges, moralise the graph and build the partial ordering
828  for (const auto node: moral_graph.nodes()) {
829  const auto& parents = c.containerDag().parents(node);
830 
831  // Adding edges and marrying parents
832  for (auto tail = parents.begin(); tail != parents.end(); ++tail) {
835  moral_graph.addEdge(*tail, node);
836  NodeSet::const_iterator marry = tail;
837  ++marry;
838 
839  while (marry != parents.end()) {
842  moral_graph.addEdge(*tail, *marry);
843 
844  ++marry;
845  }
846  }
847  }
848 
849  // Adding nodes to the partial ordering
850  switch (c.get(node).elt_type()) {
852  if (c.isOutputNode(c.get(node)))
853  outputs().insert(node);
854  else
855  aggregators().insert(node);
856 
857  // If the aggregators is not an output and have parents which are
858  // not outputs, we must eliminate the parents after adding the
859  // aggregator's CPT
860  for (const auto par: c.containerDag().parents(node)) {
861  const auto& prnt = c.get(par);
862 
863  if ((!c.isOutputNode(prnt))
866  inners().erase(prnt.id());
867  aggregators().insert(prnt.id());
868  }
869  }
870 
871  break;
872  }
873 
875  pool.insert(const_cast< Potential< GUM_SCALAR >* >(&(c.get(node).cpf())));
876 
877  if (c.isOutputNode(c.get(node)))
878  outputs().insert(node);
879  else if (!aggregators().exists(node))
880  inners().insert(node);
881 
882  break;
883  }
884 
885  default: { /* Do nothing */
886  }
887  }
888  }
889 
890  if (inners().size()) partial_order.insert(inners());
891 
892  if (aggregators().size()) partial_order.insert(aggregators());
893 
894  if (outputs().size()) partial_order.insert(outputs());
895 
896  GUM_ASSERT(partial_order.size());
897  PartialOrderedTriangulation t(&moral_graph, &mods, &partial_order);
898  _elim_order_ = t.eliminationOrder();
899 
900  for (size_t i = 0; i < inners().size(); ++i)
901  eliminateNode(&(c.get(_elim_order_[i]).type().variable()), pool, _trash_);
902  }
List< NodeSet > partial_order
The partial order used of variable elimination.
NodeProperty< Size > mods
The class variables modalities.
virtual void addNodeWithId(const NodeId id)
try to insert a node with the given id
UndiGraph moral_graph
The class moral graph. NodeId matches those in c.
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
NodeSet & outputs()
Returns the set of outputs nodes.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
Set< Potential< GUM_SCALAR > *> _trash_
Set< Potential< GUM_SCALAR > *> pool
The potential pool obtained by C elimination of inner nodes.
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
void eliminateNode(const DiscreteVariable *var, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.
NodeSet & inners()
Returns the set of inner nodes.
NodeSet & aggregators()
Returns the set of aggregators and their parents.
SetIterator< NodeId > const_iterator
Definition: set.h:177
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:694
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:34
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
const PRMClass< GUM_SCALAR > & c
The class about what this data is about.
+ Here is the call graph for this function:

◆ ~CData()

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

Destructor.

Definition at line 905 of file structuredInference_tpl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

905  {
906  GUM_DESTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
907 
908  for (const auto pot: _trash_)
909  delete pot;
910  }
Set< Potential< GUM_SCALAR > *> _trash_
+ Here is the call graph for this function:

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 229 of file structuredInference.h.

◆ 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 233 of file structuredInference.h.

233 { return _elim_order_; }

◆ inners()

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

Returns the set of inner nodes.

Definition at line 227 of file structuredInference.h.

◆ outputs()

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

Returns the set of outputs nodes.

Definition at line 231 of file structuredInference.h.

Member Data Documentation

◆ _aggregators_

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

Definition at line 238 of file structuredInference.h.

◆ _elim_order_

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

Definition at line 236 of file structuredInference.h.

◆ _inners_

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

Definition at line 237 of file structuredInference.h.

◆ _outputs_

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

Definition at line 239 of file structuredInference.h.

◆ _trash_

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

Definition at line 240 of file structuredInference.h.

◆ 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 211 of file structuredInference.h.

◆ 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 219 of file structuredInference.h.

◆ mods

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

The class variables modalities.

Definition at line 215 of file structuredInference.h.

◆ 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 213 of file structuredInference.h.

◆ 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 217 of file structuredInference.h.

◆ pool

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

The potential pool obtained by C elimination of inner nodes.

Definition at line 221 of file structuredInference.h.


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