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

namespace for all probabilistic relational models entities More...

Namespaces

namespace  gspan
namespace  o3prm
namespace  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  PRMAggregate
class  PRMAttribute
 PRMAttribute is a member of a Class in a PRM. 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  PRMClass
 A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantiated in PRMInstance. More...
struct  ParamScopeData
class  PRMClassElement
 Abstract class representing an element of PRM class. More...
class  PRMClassElementContainer
 <agrum/PRM/classElementContainer.h> More...
class  PRMFormAttribute
 <agrum/PRM/elements/formAttribute.h> More...
class  PRMFuncAttribute
 <agrum/PRM/elements/funcAttribute.h> More...
class  PRMInstance
 An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem. More...
class  PRMObject
 Abstract base class for any element defined in a PRM. 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  PRMReferenceSlot
 A PRMReferenceSlot represent a relation between two PRMClassElementContainer. More...
class  PRMSystem
 A PRMSystem is a container of PRMInstance and describe a relational skeleton. More...
class  PRMParameter
 PRMParameter is a member of a Class in a PRM. More...
class  PRMScalarAttribute
 <agrum/PRM/elements/scalarAttribute.h> More...
class  PRMFactory
 Factory which builds a PRM<GUM_SCALAR>. More...
class  PRMType
 This is a decoration of the DiscreteVariable class. More...
class  ClusteredLayerGenerator
 <agrum/PRM/generator/clusteredLayerGenerator.h> 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...
class  PRMGenerator
 This class is the base class to all PRM generators. More...
class  GSpan
 This class discovers pattern in a PRM<GUM_SCALAR>'s PRMSystem<GUM_SCALAR> to speed up structured inference. More...
class  GroundedInference
 <agrum/PRM/groundedInference.h> More...
class  PRMInference
 This abstract class is used as base class for all inference class on PRM<GUM_SCALAR>. 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...
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  PRM
 This class represents a Probabilistic Relational PRMSystem<GUM_SCALAR>. More...

Typedefs

using prm_float = float
 PRMType for real numbers.

Functions

std::ostream & operator<< (std::ostream &out, PRMObject::prm_type obj_type)
 For printing PRMType easily.
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 Tensor< 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.
NodeId nextNodeId ()
 Returns the next value of an unique counter for PRM's node id.
template<typename GUM_SCALAR>
Tensor< GUM_SCALAR > * copyTensor (const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const Tensor< GUM_SCALAR > &source)
 Returns a copy of a Tensor after applying a bijection over the variables in source.
template<typename GUM_SCALAR>
Tensor< GUM_SCALAR > multTensor (const Tensor< GUM_SCALAR > &t1, const Tensor< GUM_SCALAR > &t2)
template<typename GUM_SCALAR>
void eliminateNode (const DiscreteVariable *var, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
 Proceeds with the elimination of var in pool.
template<typename GUM_SCALAR>
void eliminateNodes (const std::vector< const DiscreteVariable * > &elim_order, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)

Detailed Description

namespace for all probabilistic relational models entities

Typedef Documentation

◆ prm_float

using gum::prm::prm_float = float

PRMType for real numbers.

Definition at line 65 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 56 of file SVE_tpl.h.

57 {
58 std::stringstream s;
59 const auto& class_a = i.type().get(a.safeName());
60 s << &(a.type().variable()) << " - ";
61 s << i.name() << "." << a.safeName() << ": input=" << i.type().isInputNode(class_a);
62 s << " output=" << i.type().isOutputNode(class_a)
63 << " inner=" << i.type().isInnerNode(class_a);
64 return s.str();
65 }
virtual PRMType & type()=0
See gum::PRMClassElement::type().
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
const std::string & name() const
Returns the name of this object.

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

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 68 of file SVE_tpl.h.

68 {
69 std::stringstream s;
70 s << i.name() << std::endl;
71 s << "Attributes: " << std::endl;
72 for (auto a: i) {
73 s << __print_attribute__(i, *(a.second));
74 }
75 if (i.type().slotChains().size()) {
76 s << std::endl << "SlotChains: " << std::endl;
77 for (auto sc: i.type().slotChains()) {
78 s << sc->name() << " ";
79 }
80 }
81 return s.str();
82 }
std::string __print_attribute__(const PRMInstance< GUM_SCALAR > &i, const PRMAttribute< GUM_SCALAR > &a)
Definition SVE_tpl.h:56

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

Referenced by __print_system__().

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 94 of file SVE_tpl.h.

94 {
95 std::stringstream s;
96 s << "[";
97 for (auto i: l) {
98 s << i->name() << " ";
99 }
100 s << "]";
101 return s.str();
102 }

◆ __print_pot__()

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

Definition at line 105 of file SVE_tpl.h.

105 {
106 std::stringstream s;
107 s << "{";
108 for (auto var: pot.variablesSequence()) {
109 s << var << ", ";
110 }
111 s << "}";
112 return s.str();
113 }

Referenced by __print_set__().

Here is the caller graph for this function:

◆ __print_set__()

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

Definition at line 116 of file SVE_tpl.h.

116 {
117 std::stringstream s;
118 s << "[";
119 for (auto p: set) {
120 s << __print_pot__(*p) << " ";
121 }
122 s << "]";
123 return s.str();
124 }
std::string __print_pot__(const Tensor< GUM_SCALAR > &pot)
Definition SVE_tpl.h:105

References __print_pot__().

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 85 of file SVE_tpl.h.

85 {
86 std::stringstream str;
87 for (auto i: s) {
88 str << __print_instance__(*(i.second)) << std::endl;
89 }
90 return str.str();
91 }
std::string __print_instance__(const PRMInstance< GUM_SCALAR > &i)
Definition SVE_tpl.h:68

References __print_instance__().

Here is the call graph for this function:

◆ copyTensor()

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

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

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

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

Definition at line 50 of file utils_prm_tpl.h.

51 {
52 const MultiDimImplementation< GUM_SCALAR >* impl = source.content();
53 Tensor< GUM_SCALAR >* p = 0;
54
55 try {
56 if (dynamic_cast< const MultiDimReadOnly< GUM_SCALAR >* >(impl)) {
57 if (dynamic_cast< const MultiDimNoisyORCompound< GUM_SCALAR >* >(impl)) {
58 p = new Tensor< GUM_SCALAR >(new MultiDimNoisyORCompound< GUM_SCALAR >(
59 bij,
60 static_cast< const MultiDimNoisyORCompound< GUM_SCALAR >& >(*impl)));
61 } else if (dynamic_cast< const MultiDimNoisyORNet< GUM_SCALAR >* >(impl)) {
62 p = new Tensor< GUM_SCALAR >(new MultiDimNoisyORNet< GUM_SCALAR >(
63 bij,
64 static_cast< const MultiDimNoisyORNet< GUM_SCALAR >& >(*impl)));
65 } else if (dynamic_cast< const aggregator::MultiDimAggregator< GUM_SCALAR >* >(impl)) {
66 p = new Tensor< GUM_SCALAR >(
67 static_cast< MultiDimImplementation< GUM_SCALAR >* >(impl->newFactory()));
68
69 for (auto var: impl->variablesSequence())
70 p->add(*(bij.second(var)));
71 } else if (dynamic_cast< const MultiDimBucket< GUM_SCALAR >* >(impl)) {
72 // This is necessary just to prevent non initialized arrays
73 const_cast< MultiDimBucket< GUM_SCALAR >* >(
74 static_cast< const MultiDimBucket< GUM_SCALAR >* >(impl))
75 ->compute();
76
77 try {
78 p = new Tensor< GUM_SCALAR >(new MultiDimBijArray< GUM_SCALAR >(
79 bij,
80 static_cast< const MultiDimBucket< GUM_SCALAR >* >(impl)->bucket()));
81 } catch (OperationNotAllowed const&) {
82 // This is an empty bucket, it happens if all variables were
83 // eliminated
84 return new Tensor< GUM_SCALAR >();
85 }
86 } else {
87 GUM_ERROR(FatalError, "encountered an unexpected MultiDim implementation")
88 }
89 } else {
90 if (dynamic_cast< const MultiDimArray< GUM_SCALAR >* >(impl)) {
91 p = new Tensor< GUM_SCALAR >(new MultiDimBijArray< GUM_SCALAR >(
92 bij,
93 static_cast< const MultiDimArray< GUM_SCALAR >& >(*impl)));
94 } else if (dynamic_cast< const MultiDimBijArray< GUM_SCALAR >* >(impl)) {
95 p = new Tensor< GUM_SCALAR >(new MultiDimBijArray< GUM_SCALAR >(
96 bij,
97 static_cast< const MultiDimBijArray< GUM_SCALAR >& >(*impl)));
98 } else if (dynamic_cast< const MultiDimSparse< GUM_SCALAR >* >(impl)) {
99 GUM_ERROR(FatalError, "There is no MultiDimSparse in PRMs, normally...")
100 } else {
101 // Just need to make the copy using the bijection but we only use
102 // multidim array
103 GUM_ERROR(FatalError, "encountered an unexpected MultiDim implementation")
104 }
105 }
106
107 return p;
108 } catch (Exception const&) {
109 if (p) delete p;
110
111 throw;
112 }
113 }
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
<agrum/base/multidim/multiDimImplementation.h>
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const override=0
Creates an empty clone of this MultiDimContainer.
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
Noisy OR representation.
Abstract base class for all multi dimensionnal read only structure.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References GUM_ERROR, gum::MultiDimImplementation< GUM_SCALAR >::newFactory(), gum::BijectionImplementation< T1, T2, Gen >::second(), and gum::MultiDimImplementation< GUM_SCALAR >::variablesSequence().

Referenced by gum::prm::SVE< GUM_SCALAR >::_insertLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_insertLiftedNodes_(), gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_(), gum::prm::StructuredInference< GUM_SCALAR >::_translatePotSet_(), and gum::prm::PRMScalarAttribute< GUM_SCALAR >::copy().

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

48 {
49 size_t prev = 0;
50 size_t length = 0;
51 size_t idx_1 = path.find(".");
52 size_t idx_2 = path.find(PRMObject::LEFT_CAST());
53
54 if (idx_2 == std::string::npos) {
55 // ignore safe names
56 size_t idx = idx_1;
57
58 while (idx != std::string::npos) {
59 length = idx - prev;
60 v.push_back(path.substr(prev, length));
61 prev = idx + 1;
62 idx = path.find(".", prev);
63 }
64 } else {
65 size_t tmp = 0;
66
67 while (idx_1 != std::string::npos) {
68 if (idx_1 < idx_2) {
69 length = idx_1 - prev;
70 v.push_back(path.substr(prev, length));
71 prev = idx_1 + 1;
72 idx_1 = path.find(".", prev);
73 } else if (idx_2 < idx_1) {
74 tmp = path.find(PRMObject::RIGHT_CAST(), idx_2);
75 idx_1 = path.find(".", tmp);
76 idx_2 = path.find(PRMObject::LEFT_CAST(), tmp);
77 }
78 }
79 }
80
81 v.push_back(path.substr(prev, std::string::npos));
82 }
static std::string LEFT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition PRMObject.h:90
static std::string RIGHT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition PRMObject.h:92

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

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< Tensor< GUM_SCALAR > * > & pool,
Set< Tensor< GUM_SCALAR > * > & trash )

Proceeds with the elimination of var in pool.

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

Definition at line 123 of file utils_prm_tpl.h.

125 {
126 Tensor< GUM_SCALAR >* pot = nullptr;
127 Tensor< GUM_SCALAR >* tmp = nullptr;
128
129 gum::VariableSet var_set;
130 var_set.insert(var);
132
133 for (const auto p: pool)
134 if (p->contains(*var)) pots.insert(p);
135
136 if (pots.size() == 0) {
137 return;
138 } else if (pots.size() == 1) {
139 tmp = const_cast< Tensor< GUM_SCALAR >* >(*pots.begin());
140 pot = new Tensor< GUM_SCALAR >(tmp->sumOut(var_set));
141 } else {
142 MultiDimCombinationDefault< Tensor< GUM_SCALAR > > Comb(multTensor);
143 tmp = Comb.execute(pots);
144 pot = new Tensor< GUM_SCALAR >(tmp->sumOut(var_set));
145 delete tmp;
146 }
147
148 for (const auto p: pots) {
149 pool.erase(const_cast< Tensor< GUM_SCALAR >* >(p));
150
151 if (trash.exists(const_cast< Tensor< GUM_SCALAR >* >(p))) {
152 trash.erase(const_cast< Tensor< GUM_SCALAR >* >(p));
153 delete const_cast< Tensor< GUM_SCALAR >* >(p);
154 }
155 }
156
157 pool.insert(pot);
158 trash.insert(pot);
159 }
Representation of a set.
Definition set.h:131
iterator begin() const
The usual unsafe begin iterator to parse the set.
Definition set_tpl.h:438
Size size() const noexcept
Returns the number of elements in the set.
Definition set_tpl.h:636
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
Definition set_tpl.h:533
void insert(const Key &k)
Inserts a new element into the set.
Definition set_tpl.h:539
void erase(const Key &k)
Erases an element from the set.
Definition set_tpl.h:582
Tensor< GUM_SCALAR > multTensor(const Tensor< GUM_SCALAR > &t1, const Tensor< GUM_SCALAR > &t2)
Set< const DiscreteVariable * > VariableSet

References gum::Set< Key >::begin(), gum::MultiDimCombinationDefault< TABLE >::execute(), gum::Set< Key >::insert(), multTensor(), and gum::Set< Key >::size().

Referenced by gum::prm::StructuredInference< GUM_SCALAR >::CData::CData(), 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::SVE< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::SVED< GUM_SCALAR >::_initLiftedNodes_(), gum::prm::StructuredInference< GUM_SCALAR >::_reduceAloneInstances_(), gum::prm::StructuredInference< GUM_SCALAR >::_reducePattern_(), and eliminateNodes().

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< Tensor< GUM_SCALAR > * > & pool,
Set< Tensor< GUM_SCALAR > * > & trash )

Definition at line 162 of file utils_prm_tpl.h.

164 {
165 for (auto var: elim_order) {
166 eliminateNode(var, pool, trash);
167 }
168 }
void eliminateNode(const DiscreteVariable *var, Set< Tensor< GUM_SCALAR > * > &pool, Set< Tensor< GUM_SCALAR > * > &trash)
Proceeds with the elimination of var in pool.

References eliminateNode().

Referenced by gum::prm::SVE< GUM_SCALAR >::_eliminateNodes_(), gum::prm::SVED< 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_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ multTensor()

template<typename GUM_SCALAR>
Tensor< GUM_SCALAR > gum::prm::multTensor ( const Tensor< GUM_SCALAR > & t1,
const Tensor< GUM_SCALAR > & t2 )

Definition at line 117 of file utils_prm_tpl.h.

118 {
119 return t1 * t2;
120 }

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

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

84 {
85 static NodeId id = 0;
86 return ++id;
87 }
Size NodeId
Type for node ids.

Referenced by gum::prm::PRMClass< GUM_SCALAR >::_addCastDescendants_(), gum::prm::PRMClass< GUM_SCALAR >::_addCastDescendants_(), gum::prm::PRMClass< GUM_SCALAR >::_overloadAttribute_(), gum::prm::PRMClass< GUM_SCALAR >::add(), gum::prm::PRMInterface< double >::addArc(), and gum::prm::PRMInterface< double >::implementations().

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 101 of file PRMObject.cpp.

101 {
102 return (out << PRMObject::enum2str(obj_type));
103 }
static std::string enum2str(prm_type type)
Returns the string representation of a PRMObject.
Definition PRMObject.h:95

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

Here is the call graph for this function: