aGrUM  0.20.3
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...
 
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 >
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)
 
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 46 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 35 of file SVE_tpl.h.

36  {
37  std::stringstream s;
38  const auto& class_a = i.type().get(a.safeName());
39  s << &(a.type().variable()) << " - ";
40  s << i.name() << "." << a.safeName() << ": input=" << i.type().isInputNode(class_a);
41  s << " output=" << i.type().isOutputNode(class_a)
42  << " inner=" << i.type().isInnerNode(class_a);
43  return s.str();
44  }

◆ __print_instance__()

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

Definition at line 47 of file SVE_tpl.h.

47  {
48  std::stringstream s;
49  s << i.name() << std::endl;
50  s << "Attributes: " << std::endl;
51  for (auto a: i) {
52  s << __print_attribute__(i, *(a.second));
53  }
54  if (i.type().slotChains().size()) {
55  s << std::endl << "SlotChains: " << std::endl;
56  for (auto sc: i.type().slotChains()) {
57  s << sc->name() << " ";
58  }
59  }
60  return s.str();
61  }
std::string __print_attribute__(const PRMInstance< GUM_SCALAR > &i, const PRMAttribute< GUM_SCALAR > &a)
Definition: SVE_tpl.h:35

◆ __print_list__()

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

Definition at line 73 of file SVE_tpl.h.

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

◆ __print_pot__()

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

Definition at line 84 of file SVE_tpl.h.

84  {
85  std::stringstream s;
86  s << "{";
87  for (auto var: pot.variablesSequence()) {
88  s << var << ", ";
89  }
90  s << "}";
91  return s.str();
92  }

◆ __print_set__()

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

Definition at line 95 of file SVE_tpl.h.

95  {
96  std::stringstream s;
97  s << "[";
98  for (auto p: set) {
99  s << __print_pot__(*p) << " ";
100  }
101  s << "]";
102  return s.str();
103  }
std::string __print_pot__(const Potential< GUM_SCALAR > &pot)
Definition: SVE_tpl.h:84

◆ __print_system__()

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

Definition at line 64 of file SVE_tpl.h.

64  {
65  std::stringstream str;
66  for (auto i: s) {
67  str << __print_instance__(*(i.second)) << std::endl;
68  }
69  return str.str();
70  }
std::string __print_instance__(const PRMInstance< GUM_SCALAR > &i)
Definition: SVE_tpl.h:47

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

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

◆ 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 28 of file utils_prm.cpp.

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

◆ 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 which the elimination of var is done.
trashAll create potentials are inserted in this set, useful to delete later.

Definition at line 102 of file utils_prm_tpl.h.

104  {
105  Potential< GUM_SCALAR >* pot = nullptr;
106  Potential< GUM_SCALAR >* tmp = nullptr;
107 
108  Set< const DiscreteVariable* > var_set;
109  var_set.insert(var);
110  Set< const Potential< GUM_SCALAR >* > pots;
111 
112  for (const auto p: pool)
113  if (p->contains(*var)) pots.insert(p);
114 
115  if (pots.size() == 0) {
116  return;
117  } else if (pots.size() == 1) {
118  tmp = const_cast< Potential< GUM_SCALAR >* >(*pots.begin());
119  pot = new Potential< GUM_SCALAR >(tmp->margSumOut(var_set));
120  } else {
121  MultiDimCombinationDefault< GUM_SCALAR, Potential > Comb(multPotential);
122  tmp = Comb.combine(pots);
123  pot = new Potential< GUM_SCALAR >(tmp->margSumOut(var_set));
124  delete tmp;
125  }
126 
127  for (const auto p: pots) {
128  pool.erase(const_cast< Potential< GUM_SCALAR >* >(p));
129 
130  if (trash.exists(const_cast< Potential< GUM_SCALAR >* >(p))) {
131  trash.erase(const_cast< Potential< GUM_SCALAR >* >(p));
132  delete const_cast< Potential< GUM_SCALAR >* >(p);
133  }
134  }
135 
136  pool.insert(pot);
137  trash.insert(pot);
138  }
Potential< GUM_SCALAR > * multPotential(const Potential< GUM_SCALAR > &t1, const Potential< GUM_SCALAR > &t2)
Definition: utils_prm_tpl.h:96

◆ 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 141 of file utils_prm_tpl.h.

143  {
144  for (auto var: elim_order) {
145  eliminateNode(var, pool, trash);
146  }
147  }
void eliminateNode(const DiscreteVariable *var, Set< Potential< GUM_SCALAR > * > &pool, Set< Potential< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.

◆ multPotential()

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

Definition at line 96 of file utils_prm_tpl.h.

97  {
98  return new Potential< GUM_SCALAR >(t1 * t2);
99  }

◆ 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 64 of file utils_prm.cpp.

64  {
65  static NodeId id = 0;
66  return ++id;
67  }
Size NodeId
Type for node ids.
Definition: graphElements.h:97

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

78  {
79  return (out << PRMObject::enum2str(obj_type));
80  }