aGrUM  0.14.1
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 212 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 848 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().

849  :
850  c(a_class),
851  __elim_order(0) {
852  GUM_CONSTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
853 
854  // First step we add Attributes and Aggregators
855  for (const auto node : c.containerDag().nodes()) {
856  switch (c.get(node).elt_type()) {
858  pool.insert(
859  &(const_cast< Potential< GUM_SCALAR >& >(c.get(node).cpf())));
860  // break omited : We want to execute the next block
861  // for attributes
862  }
863 
866  mods.insert(node, c.get(node).type()->domainSize());
867  break;
868  }
869 
870  default: { /* do nothing */
871  }
872  }
873  }
874 
875  // Second, we add edges, moralise the graph and build the partial ordering
876  for (const auto node : moral_graph.nodes()) {
877  const auto& parents = c.containerDag().parents(node);
878 
879  // Adding edges and marrying parents
880  for (auto tail = parents.begin(); tail != parents.end(); ++tail) {
883  moral_graph.addEdge(*tail, node);
884  NodeSet::const_iterator marry = tail;
885  ++marry;
886 
887  while (marry != parents.end()) {
890  moral_graph.addEdge(*tail, *marry);
891 
892  ++marry;
893  }
894  }
895  }
896 
897  // Adding nodes to the partial ordering
898  switch (c.get(node).elt_type()) {
900  if (c.isOutputNode(c.get(node)))
901  outputs().insert(node);
902  else
903  aggregators().insert(node);
904 
905  // If the aggregators is not an output and have parents which are
906  // not outputs, we must eliminate the parents after adding the
907  // aggregator's CPT
908  for (const auto par : c.containerDag().parents(node)) {
909  const auto& prnt = c.get(par);
910 
911  if ((!c.isOutputNode(prnt))
914  inners().erase(prnt.id());
915  aggregators().insert(prnt.id());
916  }
917  }
918 
919  break;
920  }
921 
923  pool.insert(
924  const_cast< Potential< GUM_SCALAR >* >(&(c.get(node).cpf())));
925 
926  if (c.isOutputNode(c.get(node)))
927  outputs().insert(node);
928  else if (!aggregators().exists(node))
929  inners().insert(node);
930 
931  break;
932  }
933 
934  default: { /* Do nothing */
935  }
936  }
937  }
938 
939  if (inners().size()) partial_order.insert(inners());
940 
941  if (aggregators().size()) partial_order.insert(aggregators());
942 
943  if (outputs().size()) partial_order.insert(outputs());
944 
945  GUM_ASSERT(partial_order.size());
946  PartialOrderedTriangulation t(&moral_graph, &mods, &partial_order);
947  __elim_order = t.eliminationOrder();
948 
949  for (size_t i = 0; i < inners().size(); ++i)
950  eliminateNode(&(c.get(__elim_order[i]).type().variable()), pool, __trash);
951  }
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:32
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:653
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:175
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:698
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:610
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 954 of file structuredInference_tpl.h.

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

954  {
955  GUM_DESTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
956 
957  for (const auto pot : __trash)
958  delete pot;
959  }
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 232 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 236 of file structuredInference.h.

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

236 { 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 230 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 234 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 241 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 240 of file structuredInference.h.

◆ __outputs

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

Definition at line 242 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 222 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 216 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 220 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: