aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
gum::prm::PRMScalarAttribute< GUM_SCALAR > Class Template Reference

<agrum/PRM/elements/scalarAttribute.h> More...

#include <PRMScalarAttribute.h>

+ Inheritance diagram for gum::prm::PRMScalarAttribute< GUM_SCALAR >:
+ Collaboration diagram for gum::prm::PRMScalarAttribute< GUM_SCALAR >:

Public Member Functions

Constructor & destructor.
 PRMScalarAttribute (const std::string &name, const PRMType &type, MultiDimImplementation< GUM_SCALAR > *impl=new MultiDimArray< GUM_SCALAR >())
 Constructor used by gum::Class. More...
 
virtual ~PRMScalarAttribute ()
 Destructor. More...
 
Getters & setters
virtual PRMAttribute< GUM_SCALAR > * newFactory (const PRMClass< GUM_SCALAR > &c) const
 See gum::PRMClassElement::elt_type(). More...
 
virtual PRMAttribute< GUM_SCALAR > * copy (Bijection< const DiscreteVariable *, const DiscreteVariable * > bij) const
 See gum::PRMClassElement::elt_type(). More...
 
virtual void copyCpf (const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bif, const PRMAttribute< GUM_SCALAR > &source)
 See gum::PRMClassElement::elt_type(). More...
 
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type () const
 See gum::PRMClassElement::elt_type(). More...
 
virtual PRMTypetype ()
 See gum::PRMClassElement::type(). More...
 
virtual const PRMTypetype () const
 See gum::PRMClassElement::type(). More...
 
virtual const Potential< GUM_SCALAR > & cpf () const
 See gum::PRMClassElement::cpf(). More...
 
virtual void addParent (const PRMClassElement< GUM_SCALAR > &elt)
 See gum::PRMClassElement::addParent_(). More...
 
virtual void addChild (const PRMClassElement< GUM_SCALAR > &elt)
 See gum::PRMClassElement::addChild_(). More...
 
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant () const
 See gum::PRMClassElement::elt_type(). More...
 
virtual void setAsCastDescendant (PRMAttribute< GUM_SCALAR > *attr)
 See gum::PRMClassElement::elt_type(). More...
 
virtual void becomeCastDescendant (PRMType &subtype)
 See gum::PRMClassElement::elt_type(). More...
 
virtual void swap (const PRMType &old_type, const PRMType &new_type)
 Swap old_type with new_type in the PRMClassElement cpt. More...
 
Getters & setters
virtual void overload (PRMAttribute< GUM_SCALAR > *source)
 Set this as overload of source (necessayr to preserver internal pointers for MultiDims). More...
 
Getters & setters
NodeId id () const
 Returns the NodeId of this element in it's class DAG. More...
 
virtual void setId (NodeId id)
 Used to assign the id of this element. More...
 
virtual PRMObject::prm_type obj_type () const
 
Fast access to random variable's properties
const std::string & safeName () const
 Returns the safe name of this PRMClassElement, if any. More...
 
virtual std::string cast (const PRMType &t) const
 Returns the name of the cast descendant with PRMType t of this PRMClassElement. More...
 
Getters & setters.
const std::string & name () const
 Returns the name of this object. More...
 
void name (const std::string &name)
 Change the name of the PRM Object. More...
 
Operators
bool operator== (const PRMObject &obj) const
 To PRMObject are equal if they have the same name (which is unique). More...
 
bool operator!= (const PRMObject &obj) const
 To PRMObject are equal if they have the same name (which is unique). More...
 

Protected Attributes

std::string safeName_
 The safe name of this PRMClassElement. More...
 

Protected Member Functions

 PRMScalarAttribute (const PRMScalarAttribute &source)
 Copy constructor. Don't use it. More...
 
PRMScalarAttributeoperator= (const PRMScalarAttribute &from)
 Copy operator. Don't use it. More...
 
virtual PRMTypetype_ ()
 
virtual void type_ (PRMType *t)
 

Built-in type

enum  ClassElementType {
  prm_attribute, prm_aggregate, prm_refslot, prm_slotchain,
  prm_parameter
}
 Returns true if obj_ptr is of type PRMReferenceSlot. More...
 
static std::string enum2str (ClassElementType type)
 Returns true if obj_ptr is of type PRMReferenceSlot. More...
 
static INLINE bool isReferenceSlot (const PRMClassElement< GUM_SCALAR > &elt)
 Returns true if obj_ptr is of type PRMReferenceSlot. More...
 
static INLINE bool isAttribute (const PRMClassElement< GUM_SCALAR > &elt)
 Returns true if obj_ptr is of type PRMAttribute. More...
 
static INLINE bool isAggregate (const PRMClassElement< GUM_SCALAR > &elt)
 Return true if obj is of type PRMAggregate. More...
 
static INLINE bool isSlotChain (const PRMClassElement< GUM_SCALAR > &elt)
 Return true if obj is of type PRMSlotChain. More...
 
static INLINE bool isParameter (const PRMClassElement< GUM_SCALAR > &elt)
 Return true if obj is of type PRMParameter. More...
 

Built-in types.

enum  prm_type : char {
  prm_type::ALL, prm_type::CLASS, prm_type::PRM_INTERFACE, prm_type::CLASS_ELT,
  prm_type::TYPE, prm_type::SYSTEM, prm_type::INSTANCE
}
 Enumeration of the different types of objects handled by a PRM. More...
 
static std::string enum2str (prm_type type)
 Returns the string representation of a PRMObject. More...
 
static std::string LEFT_CAST ()
 Enumeration of the different types of objects handled by a PRM. More...
 
static std::string RIGHT_CAST ()
 Enumeration of the different types of objects handled by a PRM. More...
 
static INLINE bool isClass (const PRMObject &obj)
 Returns true if obj_ptr is of type Class. More...
 
static INLINE bool isInterface (const PRMObject &obj)
 Returns true if obj_ptr is of type PRMInterface. More...
 
static INLINE bool isInstance (const PRMObject &obj)
 Returns true if obj_ptr is of type PRMInstance. More...
 

Detailed Description

template<typename GUM_SCALAR>
class gum::prm::PRMScalarAttribute< GUM_SCALAR >

<agrum/PRM/elements/scalarAttribute.h>

PRMScalarAttribute is a member of a Class in a PRM.

A PRMScalarAttribute is defined by its name, its containing class, its type and by a Conditional Probability Function (aka CPF but represented by a Potential).

An attribute in a PRM is the equivalent of a random variable in a bayesian network.

This class is constructed by a gum::PRMFactory and is deleted by its gum::Class.

Built-in copies (copy constructor and copy operator) are illegal due to various problems raised by redondant information.

See also
PRM PRMFactory Class PRMClassElement PRMType Potential

Definition at line 66 of file PRMScalarAttribute.h.

Member Enumeration Documentation

◆ ClassElementType

template<typename GUM_SCALAR>
enum gum::prm::PRMClassElement::ClassElementType
inherited

Returns true if obj_ptr is of type PRMReferenceSlot.

Enumerator
prm_attribute 
prm_aggregate 
prm_refslot 
prm_slotchain 
prm_parameter 

Definition at line 94 of file PRMClassElement.h.

◆ prm_type

enum gum::prm::PRMObject::prm_type : char
stronginherited

Enumeration of the different types of objects handled by a PRM.

The "all" type is used to tell that we want any kind of PRMType (useful with iterators for example). No PRMObject will ever have "all" as type.

Enumerator
ALL 
CLASS 
PRM_INTERFACE 
CLASS_ELT 
TYPE 
SYSTEM 
INSTANCE 

Definition at line 68 of file PRMObject.h.

68  : char
69  {
70  ALL,
71  CLASS,
72  PRM_INTERFACE,
73  CLASS_ELT,
74  TYPE,
75  SYSTEM,
76  INSTANCE
77  };

Constructor & Destructor Documentation

◆ PRMScalarAttribute() [1/2]

template<typename GUM_SCALAR >
gum::prm::PRMScalarAttribute< GUM_SCALAR >::PRMScalarAttribute ( const std::string &  name,
const PRMType type,
MultiDimImplementation< GUM_SCALAR > *  impl = new MultiDimArray< GUM_SCALAR >() 
)

Constructor used by gum::Class.

This will create an PRMAttribute with only one variable: type and with the given implementation.

Parameters
nameThe name of this PRMAttribute.
typeThe type of this PRMAttribute, it is copied.
implThe MultiDimImplementation used by the internal Potential of this PRMAttribute. it will be deleted after the call of ~PRMAttribute.

Definition at line 40 of file PRMScalarAttribute_tpl.h.

43  :
44  PRMAttribute< GUM_SCALAR >(name),
45  type__(new PRMType(type)), cpf__(new Potential< GUM_SCALAR >(impl)) {
46  GUM_CONSTRUCTOR(PRMScalarAttribute);
47  cpf__->add(type__->variable());
48 
51  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
virtual PRMType & type()
See gum::PRMClassElement::type().
std::string safeName_
The safe name of this PRMClassElement.
PRMType * type__
The random variable type of this attribute.
static std::string LEFT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:79
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
const std::string & name() const
returns the name of the variable
static std::string RIGHT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:80
PRMScalarAttribute(const std::string &name, const PRMType &type, MultiDimImplementation< GUM_SCALAR > *impl=new MultiDimArray< GUM_SCALAR >())
Constructor used by gum::Class.

◆ ~PRMScalarAttribute()

template<typename GUM_SCALAR >
gum::prm::PRMScalarAttribute< GUM_SCALAR >::~PRMScalarAttribute ( )
virtual

Destructor.

Definition at line 64 of file PRMScalarAttribute_tpl.h.

64  {
65  GUM_DESTRUCTOR(PRMScalarAttribute);
66  delete cpf__;
67  delete type__;
68  }
PRMType * type__
The random variable type of this attribute.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
PRMScalarAttribute(const std::string &name, const PRMType &type, MultiDimImplementation< GUM_SCALAR > *impl=new MultiDimArray< GUM_SCALAR >())
Constructor used by gum::Class.

◆ PRMScalarAttribute() [2/2]

template<typename GUM_SCALAR >
gum::prm::PRMScalarAttribute< GUM_SCALAR >::PRMScalarAttribute ( const PRMScalarAttribute< GUM_SCALAR > &  source)
protected

Copy constructor. Don't use it.

Definition at line 54 of file PRMScalarAttribute_tpl.h.

55  :
56  PRMAttribute< GUM_SCALAR >(source),
57  type__(0), cpf__(0) {
58  GUM_CONS_CPY(PRMScalarAttribute);
59  GUM_ERROR(FatalError,
60  "Illegal call to the copy constructor of gum::ScalarAttribute");
61  }
PRMType * type__
The random variable type of this attribute.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
PRMScalarAttribute(const std::string &name, const PRMType &type, MultiDimImplementation< GUM_SCALAR > *impl=new MultiDimArray< GUM_SCALAR >())
Constructor used by gum::Class.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

Member Function Documentation

◆ addChild()

template<typename GUM_SCALAR >
INLINE void gum::prm::PRMScalarAttribute< GUM_SCALAR >::addChild ( const PRMClassElement< GUM_SCALAR > &  elt)
virtual

See gum::PRMClassElement::addChild_().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Reimplemented in gum::prm::PRMFuncAttribute< GUM_SCALAR >.

Definition at line 163 of file PRMScalarAttribute_tpl.h.

164  {}

◆ addParent()

template<typename GUM_SCALAR >
INLINE void gum::prm::PRMScalarAttribute< GUM_SCALAR >::addParent ( const PRMClassElement< GUM_SCALAR > &  elt)
virtual

See gum::PRMClassElement::addParent_().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Reimplemented in gum::prm::PRMFuncAttribute< GUM_SCALAR >.

Definition at line 148 of file PRMScalarAttribute_tpl.h.

149  {
150  try {
151  cpf__->add(elt.type().variable());
152  } catch (DuplicateElement&) {
153  GUM_ERROR(DuplicateElement,
154  elt.name() << " as parent of " << this->name());
155  } catch (OperationNotAllowed&) {
156  GUM_ERROR(OperationNotAllowed,
157  elt.name() << " of wrong type as parent of " << this->name());
158  }
159  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ becomeCastDescendant()

template<typename GUM_SCALAR >
void gum::prm::PRMScalarAttribute< GUM_SCALAR >::becomeCastDescendant ( PRMType subtype)
virtual

See gum::PRMClassElement::elt_type().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 212 of file PRMScalarAttribute_tpl.h.

212  {
213  delete cpf__;
214  cpf__ = new Potential< GUM_SCALAR >();
215  cpf__->add(type().variable());
216  cpf__->add(subtype.variable());
217 
218  Instantiation inst(*cpf__);
219 
220  for (inst.setFirst(); !inst.end(); inst.inc()) {
221  auto my_pos = inst.pos(subtype.variable());
222  if (subtype.label_map()[my_pos] == inst.pos(type().variable())) {
223  cpf__->set(inst, 1);
224  } else {
225  cpf__->set(inst, 0);
226  }
227  }
228  }
virtual PRMType & type()
See gum::PRMClassElement::type().
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.

◆ cast()

template<typename GUM_SCALAR >
INLINE std::string gum::prm::PRMClassElement< GUM_SCALAR >::cast ( const PRMType t) const
virtualinherited

Returns the name of the cast descendant with PRMType t of this PRMClassElement.

Parameters
tThe type in which we want to cast this PRMClassElement.
Exceptions
OperationNotAllowedIf the cast is impossible.

Definition at line 75 of file PRMClassElement_tpl.h.

75  {
76  if (type().isSubTypeOf(t)) {
77  return PRMObject::LEFT_CAST() + t.name() + PRMObject::RIGHT_CAST()
78  + name();
79  } else {
80  GUM_ERROR(OperationNotAllowed, "illegal cast");
81  }
82  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
static std::string LEFT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:79
static std::string RIGHT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:80
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ copy()

template<typename GUM_SCALAR >
PRMAttribute< GUM_SCALAR > * gum::prm::PRMScalarAttribute< GUM_SCALAR >::copy ( Bijection< const DiscreteVariable *, const DiscreteVariable * >  bij) const
virtual

See gum::PRMClassElement::elt_type().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 81 of file PRMScalarAttribute_tpl.h.

82  {
83  auto copy = new PRMScalarAttribute< GUM_SCALAR >(this->name(), this->type());
84 
85  if (!bij.existsFirst(&(type().variable()))) {
86  bij.insert(&(type().variable()), &(copy->type().variable()));
87  }
88 
89  delete copy->cpf__;
90  copy->cpf__ = copyPotential(bij, cpf());
91 
92  return copy;
93  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
virtual PRMType & type()
See gum::PRMClassElement::type().
virtual const Potential< GUM_SCALAR > & cpf() const
See gum::PRMClassElement::cpf().
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.
Definition: utils_prm_tpl.h:28
virtual PRMAttribute< GUM_SCALAR > * copy(Bijection< const DiscreteVariable *, const DiscreteVariable * > bij) const
See gum::PRMClassElement::elt_type().

◆ copyCpf()

template<typename GUM_SCALAR >
void gum::prm::PRMScalarAttribute< GUM_SCALAR >::copyCpf ( const Bijection< const DiscreteVariable *, const DiscreteVariable * > &  bif,
const PRMAttribute< GUM_SCALAR > &  source 
)
virtual

See gum::PRMClassElement::elt_type().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 96 of file PRMScalarAttribute_tpl.h.

98  {
99  delete cpf__;
100  cpf__ = new Potential< GUM_SCALAR >();
101 
102  for (auto var: source.cpf().variablesSequence()) {
103  cpf__->add(*(bij.second(var)));
104  }
105 
106  Instantiation inst(*cpf__), jnst(source.cpf());
107 
108  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
109  inst.inc(), jnst.inc()) {
110  cpf__->set(inst, source.cpf().get(jnst));
111  }
112 
113  GUM_ASSERT(inst.end() && jnst.end());
114  GUM_ASSERT(cpf__->contains(type__->variable()));
115  GUM_ASSERT(!cpf__->contains(source.type().variable()));
116  }
PRMType * type__
The random variable type of this attribute.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.

◆ cpf()

template<typename GUM_SCALAR >
INLINE const Potential< GUM_SCALAR > & gum::prm::PRMScalarAttribute< GUM_SCALAR >::cpf ( ) const
virtual

See gum::PRMClassElement::cpf().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 143 of file PRMScalarAttribute_tpl.h.

143  {
144  return *cpf__;
145  }
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.

◆ elt_type()

template<typename GUM_SCALAR >
INLINE PRMClassElement< GUM_SCALAR >::ClassElementType gum::prm::PRMScalarAttribute< GUM_SCALAR >::elt_type ( ) const
virtual

See gum::PRMClassElement::elt_type().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 127 of file PRMScalarAttribute_tpl.h.

127  {
128  return this->prm_attribute;
129  }

◆ enum2str() [1/2]

static std::string gum::prm::PRMObject::enum2str ( prm_type  type)
inlinestaticinherited

Returns the string representation of a PRMObject.

Definition at line 83 of file PRMObject.h.

83  {
84  switch (type) {
85  case prm_type::CLASS:
86  return "PRMType::CLASS";
87 
89  return "PRMType::CLASS_ELT";
90 
91  case prm_type::TYPE:
92  return "PRMType::TYPE";
93 
94  case prm_type::SYSTEM:
95  return "PRMType::SYSTEM";
96 
97  case prm_type::INSTANCE:
98  return "PRMType::INSTANCE";
99 
101  return "PRMType::PRM_INTERFACE";
102 
103  default:
104  return "unknown";
105  }
106  }

◆ enum2str() [2/2]

template<typename GUM_SCALAR>
static std::string gum::prm::PRMClassElement< GUM_SCALAR >::enum2str ( ClassElementType  type)
inlinestaticinherited

Returns true if obj_ptr is of type PRMReferenceSlot.

Definition at line 103 of file PRMClassElement.h.

103  {
104  switch (type) {
105  case prm_attribute:
106  return "prm_attribute";
107 
108  case prm_aggregate:
109  return "prm_aggregate";
110 
111  case prm_refslot:
112  return "prm_refslot";
113 
114  case prm_slotchain:
115  return "prm_slotchain";
116 
117  case prm_parameter:
118  return "prm_parameter";
119 
120  default:
121  return "unknown";
122  }
123  }
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.

◆ getCastDescendant()

template<typename GUM_SCALAR >
PRMAttribute< GUM_SCALAR > * gum::prm::PRMScalarAttribute< GUM_SCALAR >::getCastDescendant ( ) const
virtual

See gum::PRMClassElement::elt_type().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 168 of file PRMScalarAttribute_tpl.h.

168  {
169  PRMScalarAttribute< GUM_SCALAR >* cast = 0;
170 
171  try {
172  cast = new PRMScalarAttribute< GUM_SCALAR >(this->name(),
173  type().superType());
174  } catch (NotFound&) {
175  GUM_ERROR(OperationNotAllowed,
176  "this ScalarAttribute can not have cast descendant");
177  }
178 
179  cast->addParent(*this);
180  const DiscreteVariable& my_var = type().variable();
181  DiscreteVariable& cast_var = cast->type().variable();
182  Instantiation inst(cast->cpf());
183 
184  for (inst.setFirst(); !inst.end(); inst.inc()) {
185  if (type().label_map()[inst.val(my_var)] == inst.val(cast_var)) {
186  cast->cpf().set(inst, 1);
187  } else {
188  cast->cpf().set(inst, 0);
189  }
190  }
191 
192  return cast;
193  }
PRMType & superType()
Returns the super type of this type.
Definition: PRMType_inl.h:35
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
Definition: PRMType_inl.h:44
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
virtual PRMType & type()
See gum::PRMClassElement::type().
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
const std::vector< Idx > & label_map() const
Returns the vector in which the i-th element is the Idx of the super type&#39;s label for the i-th label ...
Definition: PRMType_inl.h:93
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ id()

template<typename GUM_SCALAR >
INLINE NodeId gum::prm::PRMClassElement< GUM_SCALAR >::id ( ) const
inherited

Returns the NodeId of this element in it's class DAG.

Definition at line 54 of file PRMClassElement_tpl.h.

54  {
55  return id__;
56  }
NodeId id__
The node&#39;s id of this element.

◆ isAggregate()

template<typename GUM_SCALAR>
static INLINE bool gum::prm::PRMClassElement< GUM_SCALAR >::isAggregate ( const PRMClassElement< GUM_SCALAR > &  elt)
inlinestaticinherited

Return true if obj is of type PRMAggregate.

Definition at line 137 of file PRMClassElement.h.

137  {
138  return elt.elt_type() == prm_aggregate;
139  }

◆ isAttribute()

template<typename GUM_SCALAR>
static INLINE bool gum::prm::PRMClassElement< GUM_SCALAR >::isAttribute ( const PRMClassElement< GUM_SCALAR > &  elt)
inlinestaticinherited

Returns true if obj_ptr is of type PRMAttribute.

Definition at line 132 of file PRMClassElement.h.

132  {
133  return elt.elt_type() == prm_attribute;
134  }

◆ isClass()

static INLINE bool gum::prm::PRMObject::isClass ( const PRMObject obj)
inlinestaticinherited

Returns true if obj_ptr is of type Class.

Definition at line 109 of file PRMObject.h.

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

109  {
110  return obj.obj_type() == prm_type::CLASS;
111  }
+ Here is the call graph for this function:

◆ isInstance()

static INLINE bool gum::prm::PRMObject::isInstance ( const PRMObject obj)
inlinestaticinherited

Returns true if obj_ptr is of type PRMInstance.

Definition at line 119 of file PRMObject.h.

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

119  {
120  return obj.obj_type() == prm_type::INSTANCE;
121  }
+ Here is the call graph for this function:

◆ isInterface()

static INLINE bool gum::prm::PRMObject::isInterface ( const PRMObject obj)
inlinestaticinherited

Returns true if obj_ptr is of type PRMInterface.

Definition at line 114 of file PRMObject.h.

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

114  {
115  return obj.obj_type() == prm_type::PRM_INTERFACE;
116  }
+ Here is the call graph for this function:

◆ isParameter()

template<typename GUM_SCALAR>
static INLINE bool gum::prm::PRMClassElement< GUM_SCALAR >::isParameter ( const PRMClassElement< GUM_SCALAR > &  elt)
inlinestaticinherited

Return true if obj is of type PRMParameter.

Definition at line 147 of file PRMClassElement.h.

147  {
148  return elt.elt_type() == prm_parameter;
149  }

◆ isReferenceSlot()

template<typename GUM_SCALAR>
static INLINE bool gum::prm::PRMClassElement< GUM_SCALAR >::isReferenceSlot ( const PRMClassElement< GUM_SCALAR > &  elt)
inlinestaticinherited

Returns true if obj_ptr is of type PRMReferenceSlot.

Definition at line 127 of file PRMClassElement.h.

127  {
128  return elt.elt_type() == prm_refslot;
129  }

◆ isSlotChain()

template<typename GUM_SCALAR>
static INLINE bool gum::prm::PRMClassElement< GUM_SCALAR >::isSlotChain ( const PRMClassElement< GUM_SCALAR > &  elt)
inlinestaticinherited

Return true if obj is of type PRMSlotChain.

Definition at line 142 of file PRMClassElement.h.

142  {
143  return elt.elt_type() == prm_slotchain;
144  }

◆ LEFT_CAST()

static std::string gum::prm::PRMObject::LEFT_CAST ( )
inlinestaticinherited

Enumeration of the different types of objects handled by a PRM.

The "all" type is used to tell that we want any kind of PRMType (useful with iterators for example). No PRMObject will ever have "all" as type.

Definition at line 79 of file PRMObject.h.

79 { return "("; }

◆ name() [1/2]

INLINE const std::string & gum::prm::PRMObject::name ( ) const
inherited

Returns the name of this object.

Definition at line 34 of file PRMObject_inl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

34 { return name__; }
std::string name__
Definition: PRMObject.h:207
+ Here is the call graph for this function:

◆ name() [2/2]

INLINE void gum::prm::PRMObject::name ( const std::string &  name)
inherited

Change the name of the PRM Object.

Warning
Don't do this unless you know what you are doing !

Definition at line 38 of file PRMObject_inl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

38 { name__ = name; }
std::string name__
Definition: PRMObject.h:207
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
+ Here is the call graph for this function:

◆ newFactory()

template<typename GUM_SCALAR >
PRMAttribute< GUM_SCALAR > * gum::prm::PRMScalarAttribute< GUM_SCALAR >::newFactory ( const PRMClass< GUM_SCALAR > &  c) const
virtual

See gum::PRMClassElement::elt_type().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 71 of file PRMScalarAttribute_tpl.h.

72  {
73  auto impl = static_cast< MultiDimImplementation< GUM_SCALAR >* >(
74  this->cpf().content()->newFactory());
75  return new PRMScalarAttribute< GUM_SCALAR >(this->name(),
76  this->type(),
77  impl);
78  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
virtual PRMType & type()
See gum::PRMClassElement::type().
virtual const Potential< GUM_SCALAR > & cpf() const
See gum::PRMClassElement::cpf().

◆ obj_type()

template<typename GUM_SCALAR >
INLINE PRMObject::prm_type gum::prm::PRMClassElement< GUM_SCALAR >::obj_type ( ) const
virtualinherited
See also
gum::PRMObject::obj_type().

Implements gum::prm::PRMObject.

Definition at line 59 of file PRMClassElement_tpl.h.

◆ operator!=()

INLINE bool gum::prm::PRMObject::operator!= ( const PRMObject obj) const
inherited

To PRMObject are equal if they have the same name (which is unique).

Definition at line 48 of file PRMObject_inl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

48  {
49  return name__ != obj.name();
50  }
std::string name__
Definition: PRMObject.h:207
+ Here is the call graph for this function:

◆ operator=()

template<typename GUM_SCALAR >
PRMScalarAttribute< GUM_SCALAR > & gum::prm::PRMScalarAttribute< GUM_SCALAR >::operator= ( const PRMScalarAttribute< GUM_SCALAR > &  from)
protected

Copy operator. Don't use it.

Definition at line 119 of file PRMScalarAttribute_tpl.h.

120  {
121  GUM_ERROR(FatalError,
122  "Illegal call to the copy operator of gum::ScalarAttribute");
123  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ operator==()

INLINE bool gum::prm::PRMObject::operator== ( const PRMObject obj) const
inherited

To PRMObject are equal if they have the same name (which is unique).

Definition at line 42 of file PRMObject_inl.h.

References gum::prm::ParamScopeData< GUM_SCALAR >::ParamScopeData().

42  {
43  return name__ == obj.name();
44  }
std::string name__
Definition: PRMObject.h:207
+ Here is the call graph for this function:

◆ overload()

template<typename GUM_SCALAR>
void gum::prm::PRMAttribute< GUM_SCALAR >::overload ( PRMAttribute< GUM_SCALAR > *  source)
virtualinherited

Set this as overload of source (necessayr to preserver internal pointers for MultiDims).

Definition at line 52 of file PRMAttribute_tpl.h.

52  {
53  auto old_type = this->type_();
54  this->type_(source->type_());
55  source->type_(old_type);
56  }
virtual PRMType * type_()=0

◆ RIGHT_CAST()

static std::string gum::prm::PRMObject::RIGHT_CAST ( )
inlinestaticinherited

Enumeration of the different types of objects handled by a PRM.

The "all" type is used to tell that we want any kind of PRMType (useful with iterators for example). No PRMObject will ever have "all" as type.

Definition at line 80 of file PRMObject.h.

80 { return ")"; }

◆ safeName()

template<typename GUM_SCALAR >
INLINE const std::string & gum::prm::PRMClassElement< GUM_SCALAR >::safeName ( ) const
inherited

Returns the safe name of this PRMClassElement, if any.

This will only work if this PRMClassElement is an PRMAttribute or an PRMAggregate.

Returns
Returns the safe name of this PRMClassElement.
Exceptions
NotFound&Raised if this PRMClassElement does not have any safe name.

Definition at line 69 of file PRMClassElement_tpl.h.

69  {
70  return safeName_;
71  }
std::string safeName_
The safe name of this PRMClassElement.

◆ setAsCastDescendant()

template<typename GUM_SCALAR >
void gum::prm::PRMScalarAttribute< GUM_SCALAR >::setAsCastDescendant ( PRMAttribute< GUM_SCALAR > *  attr)
virtual

See gum::PRMClassElement::elt_type().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 196 of file PRMScalarAttribute_tpl.h.

197  {
198  try {
199  type().setSuper(cast->type());
200  } catch (OperationNotAllowed&) {
201  GUM_ERROR(OperationNotAllowed,
202  "this ScalarAttribute can not have cast descendant");
203  } catch (TypeError&) {
204  std::stringstream msg;
205  msg << type().name() << " is not a subtype of " << cast->type().name();
206  GUM_ERROR(TypeError, msg.str());
207  }
208  cast->becomeCastDescendant(type());
209  }
const std::string & name() const
Returns the name of this object.
Definition: PRMType_inl.h:67
void setSuper(PRMType &t)
Changes the PRMType of this PRMType super.
Definition: PRMType_inl.h:79
virtual PRMType & type()
See gum::PRMClassElement::type().
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ setId()

template<typename GUM_SCALAR >
INLINE void gum::prm::PRMClassElement< GUM_SCALAR >::setId ( NodeId  id)
virtualinherited

Used to assign the id of this element.

Definition at line 64 of file PRMClassElement_tpl.h.

64  {
65  id__ = id;
66  }
NodeId id__
The node&#39;s id of this element.
NodeId id() const
Returns the NodeId of this element in it&#39;s class DAG.

◆ swap()

template<typename GUM_SCALAR >
void gum::prm::PRMScalarAttribute< GUM_SCALAR >::swap ( const PRMType old_type,
const PRMType new_type 
)
virtual

Swap old_type with new_type in the PRMClassElement cpt.

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 231 of file PRMScalarAttribute_tpl.h.

232  {
233  if (&(old_type) == type__) {
234  GUM_ERROR(OperationNotAllowed, "Cannot replace attribute own type");
235  }
236  if (old_type->domainSize() != new_type->domainSize()) {
237  GUM_ERROR(OperationNotAllowed,
238  "Cannot replace types with difference domain size");
239  }
240  if (!cpf__->contains(old_type.variable())) {
241  GUM_ERROR(NotFound, "could not find variable " + old_type.name());
242  }
243 
244  auto old = cpf__;
245 
246  cpf__ = new Potential< GUM_SCALAR >();
247 
248  for (auto var: old->variablesSequence()) {
249  if (var != &(old_type.variable())) {
250  cpf__->add(*var);
251  } else {
252  cpf__->add(new_type.variable());
253  }
254  }
255 
256  Instantiation inst(cpf__), jnst(old);
257 
258  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
259  inst.inc(), jnst.inc()) {
260  cpf__->set(inst, old->get(jnst));
261  }
262 
263  delete old;
264 
265  GUM_ASSERT(inst.end() && jnst.end());
266  GUM_ASSERT(cpf__->contains(type__->variable()));
267  GUM_ASSERT(cpf__->contains(new_type.variable()));
268  GUM_ASSERT(!cpf__->contains(old_type.variable()));
269  }
PRMType * type__
The random variable type of this attribute.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

◆ type() [1/2]

template<typename GUM_SCALAR >
INLINE PRMType & gum::prm::PRMScalarAttribute< GUM_SCALAR >::type ( )
virtual

See gum::PRMClassElement::type().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 132 of file PRMScalarAttribute_tpl.h.

132  {
133  return *type__;
134  }
PRMType * type__
The random variable type of this attribute.

◆ type() [2/2]

template<typename GUM_SCALAR >
INLINE const PRMType & gum::prm::PRMScalarAttribute< GUM_SCALAR >::type ( ) const
virtual

See gum::PRMClassElement::type().

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 137 of file PRMScalarAttribute_tpl.h.

137  {
138  return *type__;
139  }
PRMType * type__
The random variable type of this attribute.

◆ type_() [1/2]

template<typename GUM_SCALAR >
PRMType * gum::prm::PRMScalarAttribute< GUM_SCALAR >::type_ ( )
protectedvirtual

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 272 of file PRMScalarAttribute_tpl.h.

272  {
273  return type__;
274  }
PRMType * type__
The random variable type of this attribute.

◆ type_() [2/2]

template<typename GUM_SCALAR >
void gum::prm::PRMScalarAttribute< GUM_SCALAR >::type_ ( PRMType t)
protectedvirtual

Implements gum::prm::PRMAttribute< GUM_SCALAR >.

Definition at line 277 of file PRMScalarAttribute_tpl.h.

277  {
278  if (type__->variable().domainSize() != t->variable().domainSize()) {
279  GUM_ERROR(OperationNotAllowed,
280  "Cannot replace types with difference domain size");
281  }
282  auto old = cpf__;
283 
284  cpf__ = new Potential< GUM_SCALAR >();
285 
286  for (auto var: old->variablesSequence()) {
287  if (var != &(type__->variable())) {
288  cpf__->add(*var);
289  } else {
290  cpf__->add(t->variable());
291  }
292  }
293 
294  Instantiation inst(cpf__), jnst(old);
295 
296  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
297  inst.inc(), jnst.inc()) {
298  cpf__->set(inst, old->get(jnst));
299  }
300 
301  delete old;
302 
303  type__ = t;
304 
305  GUM_ASSERT(cpf__->contains(type__->variable()));
306  GUM_ASSERT(inst.end() && jnst.end());
307  }
virtual Size domainSize() const =0
PRMType * type__
The random variable type of this attribute.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54

Member Data Documentation

◆ cpf__

template<typename GUM_SCALAR >
Potential< GUM_SCALAR >* gum::prm::PRMScalarAttribute< GUM_SCALAR >::cpf__
private

A pointer on the Potential of this attribute.

Definition at line 155 of file PRMScalarAttribute.h.

◆ safeName_

template<typename GUM_SCALAR>
std::string gum::prm::PRMClassElement< GUM_SCALAR >::safeName_
protectedinherited

The safe name of this PRMClassElement.

Definition at line 266 of file PRMClassElement.h.

◆ type__

template<typename GUM_SCALAR >
PRMType* gum::prm::PRMScalarAttribute< GUM_SCALAR >::type__
private

The random variable type of this attribute.

Definition at line 152 of file PRMScalarAttribute.h.


The documentation for this class was generated from the following files: