aGrUM  0.17.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 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 852 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().

853  :
854  c(a_class),
855  __elim_order(0) {
856  GUM_CONSTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
857 
858  // First step we add Attributes and Aggregators
859  for (const auto node: c.containerDag().nodes()) {
860  switch (c.get(node).elt_type()) {
862  pool.insert(
863  &(const_cast< Potential< GUM_SCALAR >& >(c.get(node).cpf())));
864  // break omited : We want to execute the next block
865  // for attributes
866  }
867 
870  mods.insert(node, c.get(node).type()->domainSize());
871  break;
872  }
873 
874  default: { /* do nothing */
875  }
876  }
877  }
878 
879  // Second, we add edges, moralise the graph and build the partial ordering
880  for (const auto node: moral_graph.nodes()) {
881  const auto& parents = c.containerDag().parents(node);
882 
883  // Adding edges and marrying parents
884  for (auto tail = parents.begin(); tail != parents.end(); ++tail) {
887  moral_graph.addEdge(*tail, node);
888  NodeSet::const_iterator marry = tail;
889  ++marry;
890 
891  while (marry != parents.end()) {
894  moral_graph.addEdge(*tail, *marry);
895 
896  ++marry;
897  }
898  }
899  }
900 
901  // Adding nodes to the partial ordering
902  switch (c.get(node).elt_type()) {
904  if (c.isOutputNode(c.get(node)))
905  outputs().insert(node);
906  else
907  aggregators().insert(node);
908 
909  // If the aggregators is not an output and have parents which are
910  // not outputs, we must eliminate the parents after adding the
911  // aggregator's CPT
912  for (const auto par: c.containerDag().parents(node)) {
913  const auto& prnt = c.get(par);
914 
915  if ((!c.isOutputNode(prnt))
918  inners().erase(prnt.id());
919  aggregators().insert(prnt.id());
920  }
921  }
922 
923  break;
924  }
925 
927  pool.insert(
928  const_cast< Potential< GUM_SCALAR >* >(&(c.get(node).cpf())));
929 
930  if (c.isOutputNode(c.get(node)))
931  outputs().insert(node);
932  else if (!aggregators().exists(node))
933  inners().insert(node);
934 
935  break;
936  }
937 
938  default: { /* Do nothing */
939  }
940  }
941  }
942 
943  if (inners().size()) partial_order.insert(inners());
944 
945  if (aggregators().size()) partial_order.insert(aggregators());
946 
947  if (outputs().size()) partial_order.insert(outputs());
948 
949  GUM_ASSERT(partial_order.size());
950  PartialOrderedTriangulation t(&moral_graph, &mods, &partial_order);
951  __elim_order = t.eliminationOrder();
952 
953  for (size_t i = 0; i < inners().size(); ++i)
954  eliminateNode(&(c.get(__elim_order[i]).type().variable()), pool, __trash);
955  }
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:658
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:703
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:615
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 958 of file structuredInference_tpl.h.

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

958  {
959  GUM_DESTRUCTOR(StructuredInference< GUM_SCALAR >::CData);
960 
961  for (const auto pot: __trash)
962  delete pot;
963  }
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: