aGrUM  0.18.1
a C++ library for (probabilistic) graphical models
gum::prm Namespace Reference

namespace for all probabilistic relational models entities More...

Namespaces

 gspan
 
 o3prm
 
 o3prmr
 

Classes

class  ClassBayesNet
 This class decorates a gum::prm::Class<GUM_SCALAR> has an IBaseBayesNet. More...
 
class  ClassDependencyGraph
 This class represent the dependencies of all classes in a PRM<GUM_SCALAR>. More...
 
class  ClusteredLayerGenerator
 <agrum/PRM/generator/clusteredLayerGenerator.h> More...
 
class  GroundedInference
 <agrum/PRM/groundedInference.h> More...
 
class  GSpan
 This class discovers pattern in a PRM<GUM_SCALAR>'s PRMSystem<GUM_SCALAR> to speed up structured inference. More...
 
class  InstanceBayesNet
 This class decorates an PRMInstance<GUM_SCALAR> as an IBaseBayesNet. More...
 
class  IPRMFactory
 non-template interface-like parent for every PRM Factory More...
 
class  LayerGenerator
 <agrum/PRM/generator/layerGenerator.h> More...
 
class  NameGenerator
 This is a name generator for classes, types, systems, instances and class elements. More...
 
struct  ParamScopeData
 
class  PRM
 This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>. More...
 
class  PRMAggregate
 
class  PRMAttribute
 PRMAttribute is a member of a Class in a PRM. More...
 
class  PRMClass
 A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantiated in PRMInstance. More...
 
class  PRMClassElement
 Abstract class representing an element of PRM class. More...
 
class  PRMClassElementContainer
 <agrum/PRM/classElementContainer.h> More...
 
class  PRMFactory
 Factory which builds a PRM<GUM_SCALAR>. More...
 
class  PRMFormAttribute
 <agrum/PRM/elements/formAttribute.h> More...
 
class  PRMFuncAttribute
 <agrum/PRM/elements/funcAttribute.h> More...
 
class  PRMGenerator
 This class is the base class to all PRM generators. More...
 
class  PRMInference
 This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>. More...
 
class  PRMInstance
 An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem. More...
 
class  PRMInterface
 An PRMInterface is implemented by a Class<GUM_SCALAR> and defines a set of PRMReferenceSlot<GUM_SCALAR> and PRMAttribute<GUM_SCALAR> which the implementing Class<GUM_SCALAR> must contain. More...
 
class  PRMObject
 Abstract base class for any element defined in a PRM. More...
 
class  PRMParameter
 PRMParameter is a member of a Class in a PRM. More...
 
class  PRMReferenceSlot
 A PRMReferenceSlot represent a relation between two PRMClassElementContainer. More...
 
class  PRMScalarAttribute
 <agrum/PRM/elements/scalarAttribute.h> More...
 
class  PRMSlotChain
 A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum::prm::PRMClassElement<GUM_SCALAR> are gum::prm::PRMReferenceSlot and the last gum::prm::PRMClassElement<GUM_SCALAR> an gum::prm::PRMAttribute or an gum::prm::PRMAggregate. More...
 
class  PRMSystem
 A PRMSystem is a container of PRMInstance and describe a relational skeleton. More...
 
class  PRMType
 This is a decoration of the DiscreteVariable class. More...
 
class  StructuredBayesBall
 <agrum/PRM/structuredBayesBall.h> More...
 
class  StructuredInference
 <agrum/PRM/structuredInference.h> More...
 
class  SVE
 This class is an implementation of the Structured Variable Elimination algorithm on PRM<GUM_SCALAR>. More...
 
class  SVED
 This class is an implementation of the Structured Value Elimination algorithm on PRM<GUM_SCALAR>. More...
 

Typedefs

typedef float prm_float
 PRMType for real numbers. More...
 

Functions

std::ostream & operator<< (std::ostream &out, PRMObject::prm_type obj_type)
 For printing PRMType easily. More...
 
template<typename GUM_SCALAR >
std::string __print_attribute__ (const PRMInstance< GUM_SCALAR > &i, const PRMAttribute< GUM_SCALAR > &a)
 
template<typename GUM_SCALAR >
std::string __print_instance__ (const PRMInstance< GUM_SCALAR > &i)
 
template<typename GUM_SCALAR >
std::string __print_system__ (const PRMSystem< GUM_SCALAR > &s)
 
template<typename LIST >
std::string __print_list__ (LIST l)
 
template<typename GUM_SCALAR >
std::string __print_pot__ (const Potential< GUM_SCALAR > &pot)
 
template<typename SET >
std::string __print_set__ (SET set)
 
void decomposePath (const std::string &path, std::vector< std::string > &v)
 Decompose a string in a vector of strings using "." as separators. More...
 
NodeId nextNodeId ()
 Returns the next value of an unique counter for PRM's node id. More...
 
template<typename GUM_SCALAR >
Potential< GUM_SCALAR > * copyPotential (const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const Potential< GUM_SCALAR > &source)
 Returns a copy of a Potential after applying a bijection over the variables in source. More...
 
template<typename GUM_SCALAR >
Potential< GUM_SCALAR > * multPotential (const Potential< GUM_SCALAR > &t1, const Potential< GUM_SCALAR > &t2)
 
template<typename GUM_SCALAR >
void eliminateNode (const DiscreteVariable *var, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
 Proceeds with the elimination of var in pool. More...
 
template<typename GUM_SCALAR >
void eliminateNodes (const std::vector< const DiscreteVariable * > &elim_order, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
 

Detailed Description

namespace for all probabilistic relational models entities

Typedef Documentation

◆ prm_float

typedef float gum::prm::prm_float

PRMType for real numbers.

Definition at line 47 of file utils_prm.h.

Function Documentation

◆ __print_attribute__()

template<typename GUM_SCALAR >
std::string gum::prm::__print_attribute__ ( const PRMInstance< GUM_SCALAR > &  i,
const PRMAttribute< GUM_SCALAR > &  a 
)

Definition at line 36 of file SVE_tpl.h.

References gum::prm::PRMObject::name(), gum::prm::PRMClassElement< GUM_SCALAR >::safeName(), gum::prm::PRMAttribute< GUM_SCALAR >::type(), gum::prm::PRMInstance< GUM_SCALAR >::type(), and gum::prm::PRMType::variable().

Referenced by __print_instance__().

37  {
38  std::stringstream s;
39  const auto& class_a = i.type().get(a.safeName());
40  s << &(a.type().variable()) << " - ";
41  s << i.name() << "." << a.safeName()
42  << ": input=" << i.type().isInputNode(class_a);
43  s << " output=" << i.type().isOutputNode(class_a)
44  << " inner=" << i.type().isInnerNode(class_a);
45  return s.str();
46  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __print_instance__()

template<typename GUM_SCALAR >
std::string gum::prm::__print_instance__ ( const PRMInstance< GUM_SCALAR > &  i)

Definition at line 49 of file SVE_tpl.h.

References __print_attribute__(), and gum::prm::PRMObject::name().

Referenced by __print_system__().

49  {
50  std::stringstream s;
51  s << i.name() << std::endl;
52  s << "Attributes: " << std::endl;
53  for (auto a: i) {
54  s << __print_attribute__(i, *(a.second));
55  }
56  if (i.type().slotChains().size()) {
57  s << std::endl << "SlotChains: " << std::endl;
58  for (auto sc: i.type().slotChains()) {
59  s << sc->name() << " ";
60  }
61  }
62  return s.str();
63  }
std::string __print_attribute__(const PRMInstance< GUM_SCALAR > &i, const PRMAttribute< GUM_SCALAR > &a)
Definition: SVE_tpl.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __print_list__()

template<typename LIST >
std::string gum::prm::__print_list__ ( LIST  l)

Definition at line 75 of file SVE_tpl.h.

75  {
76  std::stringstream s;
77  s << "[";
78  for (auto i: l) {
79  s << i->name() << " ";
80  }
81  s << "]";
82  return s.str();
83  }

◆ __print_pot__()

template<typename GUM_SCALAR >
std::string gum::prm::__print_pot__ ( const Potential< GUM_SCALAR > &  pot)

Definition at line 86 of file SVE_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::variablesSequence().

Referenced by __print_set__().

86  {
87  std::stringstream s;
88  s << "{";
89  for (auto var: pot.variablesSequence()) {
90  s << var << ", ";
91  }
92  s << "}";
93  return s.str();
94  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __print_set__()

template<typename SET >
std::string gum::prm::__print_set__ ( SET  set)

Definition at line 97 of file SVE_tpl.h.

References __print_pot__().

97  {
98  std::stringstream s;
99  s << "[";
100  for (auto p: set) {
101  s << __print_pot__(*p) << " ";
102  }
103  s << "]";
104  return s.str();
105  }
std::string __print_pot__(const Potential< GUM_SCALAR > &pot)
Definition: SVE_tpl.h:86
+ Here is the call graph for this function:

◆ __print_system__()

template<typename GUM_SCALAR >
std::string gum::prm::__print_system__ ( const PRMSystem< GUM_SCALAR > &  s)

Definition at line 66 of file SVE_tpl.h.

References __print_instance__().

66  {
67  std::stringstream str;
68  for (auto i: s) {
69  str << __print_instance__(*(i.second)) << std::endl;
70  }
71  return str.str();
72  }
std::string __print_instance__(const PRMInstance< GUM_SCALAR > &i)
Definition: SVE_tpl.h:49
+ Here is the call graph for this function:

◆ copyPotential()

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > * gum::prm::copyPotential ( const Bijection< const DiscreteVariable *, const DiscreteVariable * > &  bij,
const Potential< GUM_SCALAR > &  source 
)

Returns a copy of a Potential after applying a bijection over the variables in source.

This copies the Potential source in a new Potential by permuting all variables in source with respect to bij.

Warning
This method in most case creates the new Potential using a gum::MultiDimBijArray, this means that the created Potential holds a reference over source, so do not delete source if you still need the created potential.
Parameters
bijA Bijection of DiscreteVariable where firsts are variables in source and seconds variables added in the returned Potential.
sourceThe copied Potential.
Returns
a pointer over a Potential which is a copy of source.
Exceptions
FatalErrorraised if an unknown MultiDimImplementation is encountered.

Definition at line 29 of file utils_prm_tpl.h.

References gum::MultiDimDecorator< GUM_SCALAR >::add(), gum::MultiDimBucket< GUM_SCALAR >::compute(), gum::MultiDimDecorator< GUM_SCALAR >::content(), GUM_ERROR, gum::MultiDimImplementation< GUM_SCALAR >::newFactory(), gum::BijectionImplementation< T1, T2, Alloc, std::is_scalar< T1 >::value &&std::is_scalar< T2 >::value >::second(), and gum::MultiDimImplementation< GUM_SCALAR >::variablesSequence().

Referenced by gum::prm::PRMScalarAttribute< GUM_SCALAR >::copy(), gum::prm::SVED< GUM_SCALAR >::insertLiftedNodes__(), gum::prm::SVE< GUM_SCALAR >::insertLiftedNodes__(), gum::prm::StructuredInference< GUM_SCALAR >::reduceAloneInstances__(), and gum::prm::StructuredInference< GUM_SCALAR >::translatePotSet__().

31  {
32  const MultiDimImplementation< GUM_SCALAR >* impl = source.content();
33  Potential< GUM_SCALAR >* p = 0;
34 
35  try {
36  if (dynamic_cast< const MultiDimReadOnly< GUM_SCALAR >* >(impl)) {
37  if (dynamic_cast< const MultiDimNoisyORCompound< GUM_SCALAR >* >(impl)) {
38  p = new Potential< GUM_SCALAR >(
39  new MultiDimNoisyORCompound< GUM_SCALAR >(
40  bij,
41  static_cast< const MultiDimNoisyORCompound< GUM_SCALAR >& >(
42  *impl)));
43  } else if (dynamic_cast< const MultiDimNoisyORNet< GUM_SCALAR >* >(
44  impl)) {
45  p = new Potential< GUM_SCALAR >(new MultiDimNoisyORNet< GUM_SCALAR >(
46  bij,
47  static_cast< const MultiDimNoisyORNet< GUM_SCALAR >& >(*impl)));
48  } else if (dynamic_cast<
49  const aggregator::MultiDimAggregator< GUM_SCALAR >* >(
50  impl)) {
51  p = new Potential< GUM_SCALAR >(
52  static_cast< MultiDimImplementation< GUM_SCALAR >* >(
53  impl->newFactory()));
54 
55  for (auto var: impl->variablesSequence())
56  p->add(*(bij.second(var)));
57  } else if (dynamic_cast< const MultiDimBucket< GUM_SCALAR >* >(impl)) {
58  // This is necessary just to prevent non initialized arrays
59  const_cast< MultiDimBucket< GUM_SCALAR >* >(
60  static_cast< const MultiDimBucket< GUM_SCALAR >* >(impl))
61  ->compute();
62 
63  try {
64  p = new Potential< GUM_SCALAR >(new MultiDimBijArray< GUM_SCALAR >(
65  bij,
66  static_cast< const MultiDimBucket< GUM_SCALAR >* >(impl)
67  ->bucket()));
68  } catch (OperationNotAllowed&) {
69  // This is an empty bucket, it happens if all variables were
70  // eliminated
71  return new Potential< GUM_SCALAR >();
72  }
73  } else {
74  GUM_ERROR(FatalError,
75  "encountered an unexpected MultiDim implementation");
76  }
77  } else {
78  if (dynamic_cast< const MultiDimArray< GUM_SCALAR >* >(impl)) {
79  p = new Potential< GUM_SCALAR >(new MultiDimBijArray< GUM_SCALAR >(
80  bij, static_cast< const MultiDimArray< GUM_SCALAR >& >(*impl)));
81  } else if (dynamic_cast< const MultiDimBijArray< GUM_SCALAR >* >(impl)) {
82  p = new Potential< GUM_SCALAR >(new MultiDimBijArray< GUM_SCALAR >(
83  bij, static_cast< const MultiDimBijArray< GUM_SCALAR >& >(*impl)));
84  } else if (dynamic_cast< const MultiDimSparse< GUM_SCALAR >* >(impl)) {
85  GUM_ERROR(FatalError,
86  "There is no MultiDimSparse in PRMs, normally...");
87  } else {
88  // Just need to make the copy using the bijection but we only use
89  // multidim array
90  GUM_ERROR(FatalError,
91  "encountered an unexpected MultiDim implementation");
92  }
93  }
94 
95  return p;
96  } catch (Exception&) {
97  if (p) delete p;
98 
99  throw;
100  }
101  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ decomposePath()

void gum::prm::decomposePath ( const std::string &  path,
std::vector< std::string > &  v 
)

Decompose a string in a vector of strings using "." as separators.

Definition at line 29 of file utils_prm.cpp.

References gum::prm::PRMObject::LEFT_CAST(), and gum::prm::PRMObject::RIGHT_CAST().

Referenced by gum::prm::PRMFactory< GUM_SCALAR >::buildSlotChain__(), and gum::prm::o3prm::O3ClassFactory< GUM_SCALAR >::resolveSlotChain__().

29  {
30  size_t prev = 0;
31  size_t length = 0;
32  size_t idx_1 = path.find(".");
33  size_t idx_2 = path.find(PRMObject::LEFT_CAST());
34 
35  if (idx_2 == std::string::npos) {
36  // ignore safe names
37  size_t idx = idx_1;
38 
39  while (idx != std::string::npos) {
40  length = idx - prev;
41  v.push_back(path.substr(prev, length));
42  prev = idx + 1;
43  idx = path.find(".", prev);
44  }
45  } else {
46  size_t tmp = 0;
47 
48  while (idx_1 != std::string::npos) {
49  if (idx_1 < idx_2) {
50  length = idx_1 - prev;
51  v.push_back(path.substr(prev, length));
52  prev = idx_1 + 1;
53  idx_1 = path.find(".", prev);
54  } else if (idx_2 < idx_1) {
55  tmp = path.find(PRMObject::RIGHT_CAST(), idx_2);
56  idx_1 = path.find(".", tmp);
57  idx_2 = path.find(PRMObject::LEFT_CAST(), tmp);
58  }
59  }
60  }
61 
62  v.push_back(path.substr(prev, std::string::npos));
63  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eliminateNode()

template<typename GUM_SCALAR >
void gum::prm::eliminateNode ( const DiscreteVariable var,
Set< Potential< GUM_SCALAR > * > &  pool,
Set< Potential< GUM_SCALAR > * > &  trash 
)

Proceeds with the elimination of var in pool.

Parameters
varThe variable eliminated from every potentials in pool.
poolA pool of potentials in wich the elimination of var is done.
trashAll create potentials are inserted in this set, useful to delete later.

Definition at line 111 of file utils_prm_tpl.h.

References gum::Set< Key, Alloc >::begin(), gum::MultiDimCombinationDefault< GUM_SCALAR, TABLE >::combine(), gum::MultiDimDecorator< GUM_SCALAR >::erase(), gum::Set< Key, Alloc >::insert(), gum::Potential< GUM_SCALAR >::margSumOut(), multPotential(), and gum::Set< Key, Alloc >::size().

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::buildReduceGraph__(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), eliminateNodes(), gum::prm::SVED< GUM_SCALAR >::eliminateNodesWithEvidence__(), gum::prm::StructuredInference< GUM_SCALAR >::eliminateObservedNodes__(), gum::prm::StructuredInference< GUM_SCALAR >::eliminateObservedNodesInSource__(), gum::prm::SVED< GUM_SCALAR >::initLiftedNodes__(), gum::prm::SVE< GUM_SCALAR >::initLiftedNodes__(), gum::prm::StructuredInference< GUM_SCALAR >::reduceAloneInstances__(), and gum::prm::StructuredInference< GUM_SCALAR >::reducePattern__().

113  {
114  Potential< GUM_SCALAR >* pot = nullptr;
115  Potential< GUM_SCALAR >* tmp = nullptr;
116 
117  Set< const DiscreteVariable* > var_set;
118  var_set.insert(var);
119  Set< const Potential< GUM_SCALAR >* > pots;
120 
121  for (const auto p: pool)
122  if (p->contains(*var)) pots.insert(p);
123 
124  if (pots.size() == 0) {
125  return;
126  } else if (pots.size() == 1) {
127  tmp = const_cast< Potential< GUM_SCALAR >* >(*pots.begin());
128  pot = new Potential< GUM_SCALAR >(tmp->margSumOut(var_set));
129  } else {
130  MultiDimCombinationDefault< GUM_SCALAR, Potential > Comb(multPotential);
131  tmp = Comb.combine(pots);
132  pot = new Potential< GUM_SCALAR >(tmp->margSumOut(var_set));
133  delete tmp;
134  }
135 
136  for (const auto p: pots) {
137  pool.erase(const_cast< Potential< GUM_SCALAR >* >(p));
138 
139  if (trash.exists(const_cast< Potential< GUM_SCALAR >* >(p))) {
140  trash.erase(const_cast< Potential< GUM_SCALAR >* >(p));
141  delete const_cast< Potential< GUM_SCALAR >* >(p);
142  }
143  }
144 
145  pool.insert(pot);
146  trash.insert(pot);
147  }
Potential< GUM_SCALAR > * multPotential(const Potential< GUM_SCALAR > &t1, const Potential< GUM_SCALAR > &t2)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eliminateNodes()

template<typename GUM_SCALAR >
void gum::prm::eliminateNodes ( const std::vector< const DiscreteVariable * > &  elim_order,
Set< Potential< GUM_SCALAR > * > &  pool,
Set< Potential< GUM_SCALAR > * > &  trash 
)

Definition at line 150 of file utils_prm_tpl.h.

References eliminateNode().

Referenced by gum::prm::SVED< GUM_SCALAR >::eliminateNodes__(), gum::prm::SVE< GUM_SCALAR >::eliminateNodes__(), gum::prm::SVED< GUM_SCALAR >::eliminateNodesDownward__(), gum::prm::SVED< GUM_SCALAR >::eliminateNodesUpward__(), gum::prm::SVE< GUM_SCALAR >::eliminateNodesWithEvidence__(), and gum::prm::SVE< GUM_SCALAR >::variableElimination__().

152  {
153  for (auto var: elim_order) {
154  eliminateNode(var, pool, trash);
155  }
156  }
void eliminateNode(const DiscreteVariable *var, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ multPotential()

template<typename GUM_SCALAR >
Potential< GUM_SCALAR > * gum::prm::multPotential ( const Potential< GUM_SCALAR > &  t1,
const Potential< GUM_SCALAR > &  t2 
)

Definition at line 105 of file utils_prm_tpl.h.

Referenced by eliminateNode(), and gum::prm::StructuredInference< GUM_SCALAR >::posterior_().

106  {
107  return new Potential< GUM_SCALAR >(t1 * t2);
108  }
+ Here is the caller graph for this function:

◆ nextNodeId()

NodeId gum::prm::nextNodeId ( )

Returns the next value of an unique counter for PRM's node id.

Returns
Returns the next value of an unique counter for PRM's node id.

Definition at line 65 of file utils_prm.cpp.

Referenced by gum::prm::PRMInterface< double >::add(), gum::prm::PRMClass< double >::add(), gum::prm::PRMClass< double >::addCastDescendants__(), gum::prm::PRMInterface< double >::addCastDescendants__(), gum::build_node(), gum::prm::PRMInterface< double >::overloadAttribute__(), gum::prm::PRMClass< double >::overloadAttribute__(), and gum::MultiDimFunctionGraphManager< bool, ExactTerminalNodePolicy >::reduce_().

65  {
66  static NodeId id = 0;
67  return ++id;
68  }
Size NodeId
Type for node ids.
Definition: graphElements.h:98
+ Here is the caller graph for this function:

◆ operator<<()

std::ostream & gum::prm::operator<< ( std::ostream &  out,
PRMObject::prm_type  obj_type 
)

For printing PRMType easily.

Definition at line 78 of file PRMObject.cpp.

References gum::prm::PRMObject::enum2str().

78  {
79  return (out << PRMObject::enum2str(obj_type));
80  }
+ Here is the call graph for this function: