aGrUM  0.13.2
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

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

Default constructor.

Definition at line 846 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().

847  :
848  c(a_class),
849  __elim_order(0) {
850  GUM_CONSTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
851 
852  // First step we add Attributes and Aggregators
853  for (const auto node : c.containerDag().nodes()) {
854  switch (c.get(node).elt_type()) {
856  pool.insert(
857  &(const_cast< Potential< GUM_SCALAR >& >(c.get(node).cpf())));
858  // break omited : We want to execute the next block
859  // for attributes
860  }
861 
864  mods.insert(node, c.get(node).type()->domainSize());
865  break;
866  }
867 
868  default: { /* do nothing */
869  }
870  }
871  }
872 
873  // Second, we add edges, moralise the graph and build the partial ordering
874  for (const auto node : moral_graph.nodes()) {
875  const auto& parents = c.containerDag().parents(node);
876 
877  // Adding edges and marrying parents
878  for (auto tail = parents.begin(); tail != parents.end(); ++tail) {
881  moral_graph.addEdge(*tail, node);
882  NodeSet::const_iterator marry = tail;
883  ++marry;
884 
885  while (marry != parents.end()) {
888  moral_graph.addEdge(*tail, *marry);
889 
890  ++marry;
891  }
892  }
893  }
894 
895  // Adding nodes to the partial ordering
896  switch (c.get(node).elt_type()) {
898  if (c.isOutputNode(c.get(node)))
899  outputs().insert(node);
900  else
901  aggregators().insert(node);
902 
903  // If the aggregators is not an output and have parents which are
904  // not outputs, we must eliminate the parents after adding the
905  // aggregator's CPT
906  for (const auto par : c.containerDag().parents(node)) {
907  const auto& prnt = c.get(par);
908 
909  if ((!c.isOutputNode(prnt))
912  inners().erase(prnt.id());
913  aggregators().insert(prnt.id());
914  }
915  }
916 
917  break;
918  }
919 
921  pool.insert(
922  const_cast< Potential< GUM_SCALAR >* >(&(c.get(node).cpf())));
923 
924  if (c.isOutputNode(c.get(node)))
925  outputs().insert(node);
926  else if (!aggregators().exists(node))
927  inners().insert(node);
928 
929  break;
930  }
931 
932  default: { /* Do nothing */
933  }
934  }
935  }
936 
937  if (inners().size()) partial_order.insert(inners());
938 
939  if (aggregators().size()) partial_order.insert(aggregators());
940 
941  if (outputs().size()) partial_order.insert(outputs());
942 
943  GUM_ASSERT(partial_order.size());
944  PartialOrderedTriangulation t(&moral_graph, &mods, &partial_order);
945  __elim_order = t.eliminationOrder();
946 
947  for (size_t i = 0; i < inners().size(); ++i)
948  eliminateNode(&(c.get(__elim_order[i]).type().variable()), pool, __trash);
949  }
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:656
NodeSet & outputs()
Returns the set of outputs nodes.
static INLINE bool isAttribute(const PRMClassElement &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.
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.
static INLINE bool isAggregate(const PRMClassElement &elt)
Return true if obj is of type PRMAggregate.
NodeSet & aggregators()
Returns the set of aggregators and their parents.
SetIterator< NodeId > const_iterator
Definition: set.h:175
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:701
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:

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

Destructor.

Definition at line 952 of file structuredInference_tpl.h.

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

952  {
953  GUM_DESTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
954 
955  for (const auto pot : __trash)
956  delete pot;
957  }
Set< Potential< GUM_SCALAR > * > __trash

Member Function Documentation

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:

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:

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:

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

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

Definition at line 241 of file structuredInference.h.

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

Definition at line 240 of file structuredInference.h.

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

Definition at line 242 of file structuredInference.h.

template<typename GUM_SCALAR>
Set< Potential< GUM_SCALAR >* > gum::prm::StructuredInference< GUM_SCALAR >::CData::__trash
private
template<typename GUM_SCALAR>
const PRMClass< GUM_SCALAR >& gum::prm::StructuredInference< GUM_SCALAR >::CData::c
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().

template<typename GUM_SCALAR>
NodeProperty< Size > gum::prm::StructuredInference< GUM_SCALAR >::CData::mods
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().

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().

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: