aGrUM  0.16.0
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 215 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 851 of file structuredInference_tpl.h.

References gum::prm::StructuredInference< GUM_SCALAR >::CData::__elim_order, gum::prm::StructuredInference< GUM_SCALAR >::CData::__trash, gum::UndiGraph::addEdge(), gum::NodeGraphPart::addNodeWithId(), gum::prm::StructuredInference< GUM_SCALAR >::CData::aggregators(), gum::prm::StructuredInference< GUM_SCALAR >::CData::c, gum::prm::eliminateNode(), gum::Set< Key, Alloc >::erase(), gum::prm::StructuredInference< GUM_SCALAR >::CData::inners(), gum::Set< Key, Alloc >::insert(), gum::prm::PRMClassElement< GUM_SCALAR >::isAggregate(), gum::prm::StructuredInference< GUM_SCALAR >::CData::mods, gum::prm::StructuredInference< GUM_SCALAR >::CData::moral_graph, gum::NodeGraphPart::nodes(), gum::prm::StructuredInference< GUM_SCALAR >::CData::outputs(), gum::prm::StructuredInference< GUM_SCALAR >::CData::partial_order, gum::prm::StructuredInference< GUM_SCALAR >::CData::pool, and gum::Set< Key, Alloc >::size().

852  :
853  c(a_class),
854  __elim_order(0) {
855  GUM_CONSTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
856 
857  // First step we add Attributes and Aggregators
858  for (const auto node : c.containerDag().nodes()) {
859  switch (c.get(node).elt_type()) {
861  pool.insert(
862  &(const_cast< Potential< GUM_SCALAR >& >(c.get(node).cpf())));
863  // break omited : We want to execute the next block
864  // for attributes
865  }
866 
869  mods.insert(node, c.get(node).type()->domainSize());
870  break;
871  }
872 
873  default: { /* do nothing */
874  }
875  }
876  }
877 
878  // Second, we add edges, moralise the graph and build the partial ordering
879  for (const auto node : moral_graph.nodes()) {
880  const auto& parents = c.containerDag().parents(node);
881 
882  // Adding edges and marrying parents
883  for (auto tail = parents.begin(); tail != parents.end(); ++tail) {
886  moral_graph.addEdge(*tail, node);
887  NodeSet::const_iterator marry = tail;
888  ++marry;
889 
890  while (marry != parents.end()) {
893  moral_graph.addEdge(*tail, *marry);
894 
895  ++marry;
896  }
897  }
898  }
899 
900  // Adding nodes to the partial ordering
901  switch (c.get(node).elt_type()) {
903  if (c.isOutputNode(c.get(node)))
904  outputs().insert(node);
905  else
906  aggregators().insert(node);
907 
908  // If the aggregators is not an output and have parents which are
909  // not outputs, we must eliminate the parents after adding the
910  // aggregator's CPT
911  for (const auto par : c.containerDag().parents(node)) {
912  const auto& prnt = c.get(par);
913 
914  if ((!c.isOutputNode(prnt))
917  inners().erase(prnt.id());
918  aggregators().insert(prnt.id());
919  }
920  }
921 
922  break;
923  }
924 
926  pool.insert(
927  const_cast< Potential< GUM_SCALAR >* >(&(c.get(node).cpf())));
928 
929  if (c.isOutputNode(c.get(node)))
930  outputs().insert(node);
931  else if (!aggregators().exists(node))
932  inners().insert(node);
933 
934  break;
935  }
936 
937  default: { /* Do nothing */
938  }
939  }
940  }
941 
942  if (inners().size()) partial_order.insert(inners());
943 
944  if (aggregators().size()) partial_order.insert(aggregators());
945 
946  if (outputs().size()) partial_order.insert(outputs());
947 
948  GUM_ASSERT(partial_order.size());
949  PartialOrderedTriangulation t(&moral_graph, &mods, &partial_order);
950  __elim_order = t.eliminationOrder();
951 
952  for (size_t i = 0; i < inners().size(); ++i)
953  eliminateNode(&(c.get(__elim_order[i]).type().variable()), pool, __trash);
954  }
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.
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:35
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:656
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 > *> 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:178
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
static INLINE bool isAggregate(const PRMClassElement< GUM_SCALAR > &elt)
Return true if obj is of type PRMAggregate.
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
const PRMClass< GUM_SCALAR > & c
The class about what this data is about.
Set< Potential< GUM_SCALAR > *> __trash
+ Here is the call graph for this function:

◆ ~CData()

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

Destructor.

Definition at line 957 of file structuredInference_tpl.h.

References gum::prm::StructuredInference< GUM_SCALAR >::CData::__trash.

957  {
958  GUM_DESTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
959 
960  for (const auto pot : __trash)
961  delete pot;
962  }
Set< Potential< GUM_SCALAR > *> __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 235 of file structuredInference.h.

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

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

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

239 { return __elim_order; }
+ 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 233 of file structuredInference.h.

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

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

References gum::prm::StructuredInference< GUM_SCALAR >::__outputs.

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

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

◆ __elim_order

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

◆ __inners

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

Definition at line 243 of file structuredInference.h.

◆ __outputs

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

Definition at line 245 of file structuredInference.h.

◆ __trash

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

◆ c

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

◆ 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 225 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

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

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

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

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

◆ pool

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

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