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

typedef float gum::prm::prm_float

PRMType for real numbers.

Definition at line 44 of file utils_prm.h.

Function Documentation

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

Definition at line 33 of file SVE_tpl.h.

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

Referenced by __print_instance__().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 46 of file SVE_tpl.h.

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

Referenced by __print_system__().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 72 of file SVE_tpl.h.

72  {
73  std::stringstream s;
74  s << "[";
75  for (auto i : l) {
76  s << i->name() << " ";
77  }
78  s << "]";
79  return s.str();
80  }
template<typename GUM_SCALAR >
std::string gum::prm::__print_pot__ ( const Potential< GUM_SCALAR > &  pot)

Definition at line 83 of file SVE_tpl.h.

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

Referenced by __print_set__().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 94 of file SVE_tpl.h.

References __print_pot__().

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

+ Here is the call graph for this function:

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

Definition at line 63 of file SVE_tpl.h.

References __print_instance__().

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

+ Here is the call graph for this function:

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 27 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::SVED< GUM_SCALAR >::__insertLiftedNodes(), gum::prm::SVE< GUM_SCALAR >::__insertLiftedNodes(), gum::prm::StructuredInference< GUM_SCALAR >::__reduceAloneInstances(), gum::prm::StructuredInference< GUM_SCALAR >::__translatePotSet(), and gum::prm::PRMScalarAttribute< GUM_SCALAR >::copy().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 108 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::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(), gum::prm::StructuredInference< GUM_SCALAR >::__reducePattern(), gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), and eliminateNodes().

110  {
111  Potential< GUM_SCALAR >* pot = nullptr;
112  Potential< GUM_SCALAR >* tmp = nullptr;
113 
114  Set< const DiscreteVariable* > var_set;
115  var_set.insert(var);
116  Set< const Potential< GUM_SCALAR >* > pots;
117 
118  for (const auto p : pool)
119  if (p->contains(*var)) pots.insert(p);
120 
121  if (pots.size() == 0) {
122  return;
123  } else if (pots.size() == 1) {
124  tmp = const_cast< Potential< GUM_SCALAR >* >(*pots.begin());
125  pot = new Potential< GUM_SCALAR >(tmp->margSumOut(var_set));
126  } else {
127  MultiDimCombinationDefault< GUM_SCALAR, Potential > Comb(multPotential);
128  tmp = Comb.combine(pots);
129  pot = new Potential< GUM_SCALAR >(tmp->margSumOut(var_set));
130  delete tmp;
131  }
132 
133  for (const auto p : pots) {
134  pool.erase(const_cast< Potential< GUM_SCALAR >* >(p));
135 
136  if (trash.exists(const_cast< Potential< GUM_SCALAR >* >(p))) {
137  trash.erase(const_cast< Potential< GUM_SCALAR >* >(p));
138  delete const_cast< Potential< GUM_SCALAR >* >(p);
139  }
140  }
141 
142  pool.insert(pot);
143  trash.insert(pot);
144  }
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:

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

149  {
150  for (auto var : elim_order) {
151  eliminateNode(var, pool, trash);
152  }
153  }
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:

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

Definition at line 102 of file utils_prm_tpl.h.

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

103  {
104  return new Potential< GUM_SCALAR >(t1 * t2);
105  }

+ Here is the caller graph for this function:

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

Referenced by gum::prm::PRMClass< GUM_SCALAR >::__addCastDescendants(), gum::prm::PRMInterface< GUM_SCALAR >::__addCastDescendants(), gum::prm::PRMInterface< GUM_SCALAR >::__overloadAttribute(), gum::prm::PRMClass< GUM_SCALAR >::__overloadAttribute(), gum::MultiDimFunctionGraphManager< GUM_SCALAR, TerminalNodePolicy >::_reduce(), gum::prm::PRMInterface< GUM_SCALAR >::add(), and gum::prm::PRMClass< GUM_SCALAR >::add().

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

+ Here is the caller graph for this function:

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

For printing PRMType easily.

Definition at line 75 of file PRMObject.cpp.

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

75  {
76  return (out << PRMObject::enum2str(obj_type));
77  }

+ Here is the call graph for this function: