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

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

#include <PRMFormAttribute.h>

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

Public Member Functions

 PRMFormAttribute (const PRMClass< GUM_SCALAR > &c, const std::string &name, const PRMType &type, MultiDimImplementation< std::string > *impl=new MultiDimArray< std::string >())
 
virtual ~PRMFormAttribute ()
 
virtual PRMAttribute< GUM_SCALAR > * newFactory (const PRMClass< GUM_SCALAR > &c) const
 See gum::prm::PRMAttribute. More...
 
virtual PRMAttribute< GUM_SCALAR > * copy (Bijection< const DiscreteVariable *, const DiscreteVariable * > bij) const
 See gum::prm::PRMAttribute. More...
 
virtual void copyCpf (const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bif, const PRMAttribute< GUM_SCALAR > &source)
 See gum::prm::PRMAttribute. More...
 
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type () const
 See gum::prm::PRMAttribute. More...
 
virtual PRMTypetype ()
 See gum::prm::PRMAttribute. More...
 
virtual const PRMTypetype () const
 See gum::prm::PRMAttribute. More...
 
virtual const Potential< GUM_SCALAR > & cpf () const
 See gum::prm::PRMAttribute. More...
 
virtual void addParent (const PRMClassElement< GUM_SCALAR > &elt)
 See gum::prm::PRMAttribute. More...
 
virtual void addChild (const PRMClassElement< GUM_SCALAR > &elt)
 See gum::prm::PRMAttribute. More...
 
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant () const
 See gum::prm::PRMAttribute. More...
 
virtual void setAsCastDescendant (PRMAttribute< GUM_SCALAR > *attr)
 See gum::prm::PRMAttribute. More...
 
virtual void becomeCastDescendant (PRMType &subtype)
 Change this attribute to be a cast descendant of a an attribute with type subtype. More...
 
virtual MultiDimImplementation< std::string > & formulas ()
 
virtual const MultiDimImplementation< std::string > & formulas () const
 
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

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::PRMFormAttribute< GUM_SCALAR >

<agrum/PRM/elements/formAttribute.h>

PRMFormAttribute is a member of a Class in a PRM.

See also
PRM PRMFactory Class PRMClassElement PRMType<GUM_SCALAR> Potential PRMAttribute

Definition at line 49 of file PRMFormAttribute.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

◆ PRMFormAttribute() [1/2]

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

Definition at line 42 of file PRMFormAttribute_tpl.h.

45  :
46  PRMAttribute< GUM_SCALAR >(name),
47  _type_(new PRMType(type)), _cpf_(0), _formulas_(impl), _class_(&c) {
48  GUM_CONSTRUCTOR(PRMFormAttribute);
49  _formulas_->add(_type_->variable());
51  }
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.
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
const PRMClass< GUM_SCALAR > * _class_
A pointe toward the class of this attribute.
std::string safeName_
The safe name of this PRMClassElement.
PRMType * _type_
The random variable type of this attribute.
PRMFormAttribute(const PRMClass< GUM_SCALAR > &c, const std::string &name, const PRMType &type, MultiDimImplementation< std::string > *impl=new MultiDimArray< std::string >())
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
static std::string LEFT_CAST()
Enumeration of the different types of objects handled by a PRM.
Definition: PRMObject.h:79
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
virtual PRMType & type()
See gum::prm::PRMAttribute.

◆ ~PRMFormAttribute()

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

Definition at line 54 of file PRMFormAttribute_tpl.h.

54  {
55  GUM_DESTRUCTOR(PRMFormAttribute);
56  delete _type_;
57  delete _cpf_;
58  delete _formulas_;
59  }
Potential< GUM_SCALAR > * _cpf_
A pointer on the Potential of this attribute.
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
PRMType * _type_
The random variable type of this attribute.
PRMFormAttribute(const PRMClass< GUM_SCALAR > &c, const std::string &name, const PRMType &type, MultiDimImplementation< std::string > *impl=new MultiDimArray< std::string >())

◆ PRMFormAttribute() [2/2]

template<typename GUM_SCALAR >
gum::prm::PRMFormAttribute< GUM_SCALAR >::PRMFormAttribute ( const PRMFormAttribute< GUM_SCALAR > &  source)
private

Definition at line 242 of file PRMFormAttribute_tpl.h.

242  :
243  PRMAttribute< GUM_SCALAR >(source.name()) {
244  GUM_CONS_CPY(PRMFormAttribute);
245  GUM_ERROR(OperationNotAllowed, "Cannot copy FormAttribute")
246  }
PRMFormAttribute(const PRMClass< GUM_SCALAR > &c, const std::string &name, const PRMType &type, MultiDimImplementation< std::string > *impl=new MultiDimArray< std::string >())
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

Member Function Documentation

◆ _fillCpf_()

template<typename GUM_SCALAR >
void gum::prm::PRMFormAttribute< GUM_SCALAR >::_fillCpf_ ( ) const
private

Definition at line 255 of file PRMFormAttribute_tpl.h.

255  {
256  try {
257  if (_cpf_) { delete _cpf_; }
258 
259  _cpf_ = new Potential< GUM_SCALAR >();
260 
261  for (auto var: _formulas_->variablesSequence()) {
262  _cpf_->add(*var);
263  }
264 
265  auto params = _class_->scope();
266 
267  Instantiation inst(_formulas_);
268  Instantiation jnst(_cpf_);
269 
270  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
271  inst.inc(), jnst.inc()) {
272  // With CPT defined using rules, empty values can appear
273  auto val = _formulas_->get(inst);
274  if (val == "") { val = "0.0"; }
275 
276  Formula f(val);
277 
278  for (auto item: params) {
279  f.variables().insert(item.first, item.second->value());
280  }
281 
282  _cpf_->set(jnst, (GUM_SCALAR)f.result());
283  }
284 
285  GUM_ASSERT(inst.end() && jnst.end());
286 
287  } catch (Exception&) { GUM_ERROR(NotFound, "undefined value in cpt") }
288  GUM_ASSERT(_formulas_->contains(_type_->variable()))
289  }
Potential< GUM_SCALAR > * _cpf_
A pointer on the Potential of this attribute.
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
const PRMClass< GUM_SCALAR > * _class_
A pointe toward the class of this attribute.
PRMType * _type_
The random variable type of this attribute.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ addChild()

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

See gum::prm::PRMAttribute.

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

Definition at line 171 of file PRMFormAttribute_tpl.h.

171 {}

◆ addParent()

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

See gum::prm::PRMAttribute.

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

Definition at line 153 of file PRMFormAttribute_tpl.h.

153  {
154  try {
155  if (_cpf_) {
156  delete _cpf_;
157  _cpf_ = 0;
158  }
159  _formulas_->add(elt.type().variable());
160  } catch (DuplicateElement&) {
161  GUM_ERROR(DuplicateElement, elt.name() << " as parent of " << this->name())
162  } catch (OperationNotAllowed&) {
163  GUM_ERROR(OperationNotAllowed,
164  elt.name() << " of wrong type as parent of " << this->name();)
165  }
166 
167  GUM_ASSERT(_formulas_->contains(_type_->variable()));
168  }
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.
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
PRMType * _type_
The random variable type of this attribute.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ becomeCastDescendant()

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

Change this attribute to be a cast descendant of a an attribute with type subtype.

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

Definition at line 217 of file PRMFormAttribute_tpl.h.

217  {
218  delete _formulas_;
219 
220  _formulas_ = new MultiDimArray< std::string >();
221  _formulas_->add(type().variable());
222  _formulas_->add(subtype.variable());
223 
224  Instantiation inst(_formulas_);
225 
226  for (inst.setFirst(); !inst.end(); inst.inc()) {
227  auto my_pos = inst.pos(subtype.variable());
228  if (subtype.label_map()[my_pos] == inst.pos(type().variable())) {
229  _formulas_->set(inst, "1");
230  } else {
231  _formulas_->set(inst, "0");
232  }
233  }
234 
235  if (_cpf_) {
236  delete _cpf_;
237  _cpf_ = nullptr;
238  }
239  }
Potential< GUM_SCALAR > * _cpf_
A pointer on the Potential of this attribute.
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
virtual PRMType & type()
See gum::prm::PRMAttribute.

◆ 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 71 of file PRMClassElement_tpl.h.

71  {
72  if (type().isSubTypeOf(t)) {
73  return PRMObject::LEFT_CAST() + t.name() + PRMObject::RIGHT_CAST() + name();
74  } else {
75  GUM_ERROR(OperationNotAllowed, "illegal cast")
76  }
77  }
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:51

◆ copy()

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

See gum::prm::PRMAttribute.

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

Definition at line 70 of file PRMFormAttribute_tpl.h.

71  {
72  auto copy = new PRMFormAttribute< GUM_SCALAR >(*_class_, this->name(), this->type());
73  for (auto var: _formulas_->variablesSequence()) {
74  if (var != &(_type_->variable())) { copy->_formulas_->add(*var); }
75  }
76 
77  Instantiation inst(*(copy->_formulas_)), jnst(*_formulas_);
78  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end()); inst.inc(), jnst.inc()) {
79  copy->_formulas_->set(inst, _formulas_->get(jnst));
80  }
81 
82  GUM_ASSERT(copy->_formulas_->contains(copy->_type_->variable()));
83  return copy;
84  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
const PRMClass< GUM_SCALAR > * _class_
A pointe toward the class of this attribute.
PRMType * _type_
The random variable type of this attribute.
virtual PRMAttribute< GUM_SCALAR > * copy(Bijection< const DiscreteVariable *, const DiscreteVariable * > bij) const
See gum::prm::PRMAttribute.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
virtual PRMType & type()
See gum::prm::PRMAttribute.

◆ copyCpf()

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

See gum::prm::PRMAttribute.

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

Definition at line 87 of file PRMFormAttribute_tpl.h.

89  {
90  delete _formulas_;
91  _formulas_ = new MultiDimArray< std::string >();
92 
93  for (const auto& var: source.cpf().variablesSequence()) {
94  _formulas_->add(*(bij.second(var)));
95  }
96 
97  if (dynamic_cast< const PRMFormAttribute< GUM_SCALAR >* >(&source)) {
98  const auto& src = static_cast< const PRMFormAttribute< GUM_SCALAR >& >(source);
99 
100  Instantiation inst(_formulas_), jnst(src._formulas_);
101 
102  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
103  inst.inc(), jnst.inc()) {
104  _formulas_->set(inst, src._formulas_->get(jnst));
105  }
106 
107  GUM_ASSERT(inst.end() && jnst.end());
108 
109  } else {
110  Instantiation inst(_formulas_), jnst(source.cpf());
111 
112  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
113  inst.inc(), jnst.inc()) {
114  auto val = std::to_string(source.cpf().get(jnst));
115  _formulas_->set(inst, val);
116  }
117 
118  GUM_ASSERT(inst.end() && jnst.end());
119  }
120 
121  if (_cpf_) {
122  delete _cpf_;
123  _cpf_ = 0;
124  }
125 
126  GUM_ASSERT(_formulas_->contains(_type_->variable()));
127  GUM_ASSERT(!_formulas_->contains(source.type().variable()));
128  }
Potential< GUM_SCALAR > * _cpf_
A pointer on the Potential of this attribute.
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
PRMType * _type_
The random variable type of this attribute.
std::string to_string(const Formula &f)
Definition: formula_inl.h:474
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.

◆ cpf()

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

See gum::prm::PRMAttribute.

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

Definition at line 147 of file PRMFormAttribute_tpl.h.

147  {
148  if (_cpf_ == 0) { _fillCpf_(); }
149  return *_cpf_;
150  }
Potential< GUM_SCALAR > * _cpf_
A pointer on the Potential of this attribute.

◆ elt_type()

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

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

◆ formulas() [1/2]

template<typename GUM_SCALAR >
MultiDimImplementation< std::string > & gum::prm::PRMFormAttribute< GUM_SCALAR >::formulas ( )
virtual

Definition at line 292 of file PRMFormAttribute_tpl.h.

292  {
293  if (_cpf_) {
294  delete _cpf_;
295  _cpf_ = 0;
296  }
297  return *_formulas_;
298  }
Potential< GUM_SCALAR > * _cpf_
A pointer on the Potential of this attribute.
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.

◆ formulas() [2/2]

template<typename GUM_SCALAR >
const MultiDimImplementation< std::string > & gum::prm::PRMFormAttribute< GUM_SCALAR >::formulas ( ) const
virtual

Definition at line 301 of file PRMFormAttribute_tpl.h.

301  {
302  return *_formulas_;
303  }
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.

◆ getCastDescendant()

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

See gum::prm::PRMAttribute.

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

Definition at line 174 of file PRMFormAttribute_tpl.h.

174  {
175  PRMScalarAttribute< GUM_SCALAR >* cast = 0;
176 
177  try {
178  cast = new PRMScalarAttribute< GUM_SCALAR >(this->name(), type().superType());
179  } catch (NotFound&) {
180  GUM_ERROR(OperationNotAllowed, "this ScalarAttribute can not have cast descendant")
181  }
182 
183  cast->addParent(*this);
184 
185  const DiscreteVariable& my_var = type().variable();
186  DiscreteVariable& cast_var = cast->type().variable();
187  Instantiation inst(cast->cpf());
188 
189  for (inst.setFirst(); !inst.end(); inst.inc()) {
190  if (type().label_map()[inst.val(my_var)] == inst.val(cast_var)) {
191  cast->cpf().set(inst, 1);
192  } else {
193  cast->cpf().set(inst, 0);
194  }
195  }
196 
197  GUM_ASSERT(_formulas_->contains(_type_->variable()));
198  return cast;
199  }
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
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
PRMType * _type_
The random variable type of this attribute.
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:88
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
virtual PRMType & type()
See gum::prm::PRMAttribute.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ 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 51 of file PRMClassElement_tpl.h.

51  {
52  return _id_;
53  }
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 136 of file PRMClassElement.h.

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

◆ 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 131 of file PRMClassElement.h.

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

◆ 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 { return obj.obj_type() == prm_type::CLASS; }
+ 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 117 of file PRMObject.h.

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

117  {
118  return obj.obj_type() == prm_type::INSTANCE;
119  }
+ 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 112 of file PRMObject.h.

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

112  {
113  return obj.obj_type() == prm_type::PRM_INTERFACE;
114  }
+ 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 146 of file PRMClassElement.h.

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

◆ 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 126 of file PRMClassElement.h.

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

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

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

◆ 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:205
+ 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; }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
std::string _name_
Definition: PRMObject.h:205
+ Here is the call graph for this function:

◆ newFactory()

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

See gum::prm::PRMAttribute.

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

Definition at line 63 of file PRMFormAttribute_tpl.h.

63  {
64  auto impl
66  return new PRMFormAttribute< GUM_SCALAR >(c, this->name(), this->type(), impl);
67  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const override=0
Creates an empty clone of this MultiDimContainer.
virtual PRMType & type()
See gum::prm::PRMAttribute.

◆ 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 56 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 46 of file PRMObject_inl.h.

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

46 { return _name_ != obj.name(); }
std::string _name_
Definition: PRMObject.h:205
+ Here is the call graph for this function:

◆ operator=()

template<typename GUM_SCALAR >
PRMFormAttribute< GUM_SCALAR > & gum::prm::PRMFormAttribute< GUM_SCALAR >::operator= ( const PRMFormAttribute< GUM_SCALAR > &  source)
private

Definition at line 250 of file PRMFormAttribute_tpl.h.

250  {
251  GUM_ERROR(OperationNotAllowed, "Cannot copy FormAttribute")
252  }
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ 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 { return _name_ == obj.name(); }
std::string _name_
Definition: PRMObject.h:205
+ 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 51 of file PRMAttribute_tpl.h.

51  {
52  auto old_type = this->type_();
53  this->type_(source->type_());
54  source->type_(old_type);
55  }
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 66 of file PRMClassElement_tpl.h.

66  {
67  return safeName_;
68  }
std::string safeName_
The safe name of this PRMClassElement.

◆ setAsCastDescendant()

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

See gum::prm::PRMAttribute.

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

Definition at line 202 of file PRMFormAttribute_tpl.h.

202  {
203  try {
204  type().setSuper(cast->type());
205  } catch (OperationNotAllowed&) {
206  GUM_ERROR(OperationNotAllowed, "this ScalarAttribute can not have cast descendant")
207  } catch (TypeError&) {
208  std::stringstream msg;
209  msg << type().name() << " is not a subtype of " << cast->type().name();
210  GUM_ERROR(TypeError, msg.str())
211  }
212 
213  cast->becomeCastDescendant(type());
214  }
const std::string & name() const
Returns the name of this object.
Definition: PRMType_inl.h:65
void setSuper(PRMType &t)
Changes the PRMType of this PRMType super.
Definition: PRMType_inl.h:77
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
virtual PRMType & type()
See gum::prm::PRMAttribute.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ 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 61 of file PRMClassElement_tpl.h.

61  {
62  _id_ = id;
63  }
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::PRMFormAttribute< 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 306 of file PRMFormAttribute_tpl.h.

306  {
307  if (&(old_type) == _type_) {
308  GUM_ERROR(OperationNotAllowed, "Cannot replace attribute own type")
309  }
310  if (old_type->domainSize() != new_type->domainSize()) {
311  GUM_ERROR(OperationNotAllowed, "Cannot replace types with difference domain size")
312  }
313  if (!_formulas_->contains(old_type.variable())) {
314  GUM_ERROR(NotFound, "could not find variable " + old_type.name())
315  }
316 
317  auto old = _formulas_;
318 
319  _formulas_ = new MultiDimArray< std::string >();
320 
321  for (auto var: old->variablesSequence()) {
322  if (var != &(old_type.variable())) {
323  _formulas_->add(*var);
324  } else {
325  _formulas_->add(new_type.variable());
326  }
327  }
328 
329  Instantiation inst(_formulas_), jnst(old);
330 
331  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end()); inst.inc(), jnst.inc()) {
332  _formulas_->set(inst, old->get(jnst));
333  }
334 
335  delete old;
336 
337  if (_cpf_) {
338  delete _cpf_;
339  _cpf_ = 0;
340  }
341 
342  GUM_ASSERT(inst.end() && jnst.end());
343  GUM_ASSERT(_formulas_->contains(_type_->variable()));
344  GUM_ASSERT(!_formulas_->contains(new_type.variable()));
345  GUM_ASSERT(_formulas_->contains(new_type.variable()));
346  }
Potential< GUM_SCALAR > * _cpf_
A pointer on the Potential of this attribute.
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
PRMType * _type_
The random variable type of this attribute.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

◆ type() [1/2]

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

See gum::prm::PRMAttribute.

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

Definition at line 137 of file PRMFormAttribute_tpl.h.

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

◆ type() [2/2]

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

See gum::prm::PRMAttribute.

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

Definition at line 142 of file PRMFormAttribute_tpl.h.

142  {
143  return *_type_;
144  }
PRMType * _type_
The random variable type of this attribute.

◆ type_() [1/2]

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

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

Definition at line 349 of file PRMFormAttribute_tpl.h.

349  {
350  return _type_;
351  }
PRMType * _type_
The random variable type of this attribute.

◆ type_() [2/2]

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

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

Definition at line 354 of file PRMFormAttribute_tpl.h.

354  {
355  if (_type_->variable().domainSize() != t->variable().domainSize()) {
356  GUM_ERROR(OperationNotAllowed, "Cannot replace types with difference domain size")
357  }
358  auto old = _formulas_;
359 
360  _formulas_ = new MultiDimArray< std::string >();
361 
362  for (auto var: old->variablesSequence()) {
363  if (var != &(_type_->variable())) {
364  _formulas_->add(*var);
365  } else {
366  _formulas_->add(t->variable());
367  }
368  }
369 
370  Instantiation inst(_formulas_), jnst(old);
371 
372  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end()); inst.inc(), jnst.inc()) {
373  _formulas_->set(inst, old->get(jnst));
374  }
375 
376  delete old;
377 
378  _type_ = t;
379 
380  if (_cpf_) {
381  delete _cpf_;
382  _cpf_ = 0;
383  }
384 
385  GUM_ASSERT(_formulas_->contains(_type_->variable()));
386  GUM_ASSERT(inst.end() && jnst.end());
387  }
Potential< GUM_SCALAR > * _cpf_
A pointer on the Potential of this attribute.
MultiDimImplementation< std::string > * _formulas_
A pointer on the Potential of this attribute.
virtual Size domainSize() const =0
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
PRMType * _type_
The random variable type of this attribute.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51

Member Data Documentation

◆ _class_

template<typename GUM_SCALAR >
const PRMClass< GUM_SCALAR >* gum::prm::PRMFormAttribute< GUM_SCALAR >::_class_
private

A pointe toward the class of this attribute.

Definition at line 119 of file PRMFormAttribute.h.

◆ _cpf_

template<typename GUM_SCALAR >
Potential< GUM_SCALAR >* gum::prm::PRMFormAttribute< GUM_SCALAR >::_cpf_
mutableprivate

A pointer on the Potential of this attribute.

Definition at line 113 of file PRMFormAttribute.h.

◆ _formulas_

template<typename GUM_SCALAR >
MultiDimImplementation< std::string >* gum::prm::PRMFormAttribute< GUM_SCALAR >::_formulas_
private

A pointer on the Potential of this attribute.

Definition at line 116 of file PRMFormAttribute.h.

◆ _type_

template<typename GUM_SCALAR >
PRMType* gum::prm::PRMFormAttribute< GUM_SCALAR >::_type_
private

The random variable type of this attribute.

Definition at line 110 of file PRMFormAttribute.h.

◆ safeName_

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

The safe name of this PRMClassElement.

Definition at line 265 of file PRMClassElement.h.


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