aGrUM  0.20.2
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.

46  :
47  PRMAttribute< GUM_SCALAR >(name),
48  type__(new PRMType(type)), cpf__(0), formulas__(impl), class__(&c) {
49  GUM_CONSTRUCTOR(PRMFormAttribute);
50  formulas__->add(type__->variable());
53  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
std::string safeName_
The safe name of this PRMClassElement.
const PRMClass< GUM_SCALAR > * class__
A pointe toward the class of this attribute.
PRMFormAttribute(const PRMClass< GUM_SCALAR > &c, const std::string &name, const PRMType &type, MultiDimImplementation< std::string > *impl=new MultiDimArray< std::string >())
MultiDimImplementation< std::string > * formulas__
A pointer on the Potential of this attribute.
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
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
virtual PRMType & type()
See gum::prm::PRMAttribute.
PRMType * type__
The random variable type of this attribute.

◆ ~PRMFormAttribute()

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

Definition at line 56 of file PRMFormAttribute_tpl.h.

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

◆ PRMFormAttribute() [2/2]

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

Definition at line 259 of file PRMFormAttribute_tpl.h.

260  :
261  PRMAttribute< GUM_SCALAR >(source.name()) {
262  GUM_CONS_CPY(PRMFormAttribute);
263  GUM_ERROR(OperationNotAllowed, "Cannot copy FormAttribute");
264  }
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:54

Member Function Documentation

◆ 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 182 of file PRMFormAttribute_tpl.h.

183  {}

◆ 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 162 of file PRMFormAttribute_tpl.h.

163  {
164  try {
165  if (cpf__) {
166  delete cpf__;
167  cpf__ = 0;
168  }
169  formulas__->add(elt.type().variable());
170  } catch (DuplicateElement&) {
171  GUM_ERROR(DuplicateElement,
172  elt.name() << " as parent of " << this->name());
173  } catch (OperationNotAllowed&) {
174  GUM_ERROR(OperationNotAllowed,
175  elt.name() << " of wrong type as parent of " << this->name(););
176  }
177 
178  GUM_ASSERT(formulas__->contains(type__->variable()));
179  }
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 void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
PRMType * type__
The random variable type of this attribute.

◆ 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 234 of file PRMFormAttribute_tpl.h.

234  {
235  delete formulas__;
236 
237  formulas__ = new MultiDimArray< std::string >();
238  formulas__->add(type().variable());
239  formulas__->add(subtype.variable());
240 
241  Instantiation inst(formulas__);
242 
243  for (inst.setFirst(); !inst.end(); inst.inc()) {
244  auto my_pos = inst.pos(subtype.variable());
245  if (subtype.label_map()[my_pos] == inst.pos(type().variable())) {
246  formulas__->set(inst, "1");
247  } else {
248  formulas__->set(inst, "0");
249  }
250  }
251 
252  if (cpf__) {
253  delete cpf__;
254  cpf__ = nullptr;
255  }
256  }
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
MultiDimImplementation< std::string > * formulas__
A pointer on the Potential of this attribute.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
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 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::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 75 of file PRMFormAttribute_tpl.h.

76  {
77  auto copy = new PRMFormAttribute< GUM_SCALAR >(*class__,
78  this->name(),
79  this->type());
80  for (auto var: formulas__->variablesSequence()) {
81  if (var != &(type__->variable())) { copy->formulas__->add(*var); }
82  }
83 
84  Instantiation inst(*(copy->formulas__)), jnst(*formulas__);
85  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
86  inst.inc(), jnst.inc()) {
87  copy->formulas__->set(inst, formulas__->get(jnst));
88  }
89 
90  GUM_ASSERT(copy->formulas__->contains(copy->type__->variable()));
91  return copy;
92  }
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:34
const PRMClass< GUM_SCALAR > * class__
A pointe toward the class of this attribute.
MultiDimImplementation< std::string > * formulas__
A pointer on the Potential 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.
PRMType * type__
The random variable type of this attribute.

◆ 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 95 of file PRMFormAttribute_tpl.h.

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

◆ 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 156 of file PRMFormAttribute_tpl.h.

156  {
157  if (cpf__ == 0) { fillCpf__(); }
158  return *cpf__;
159  }
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.

◆ fillCpf__()

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

Definition at line 273 of file PRMFormAttribute_tpl.h.

273  {
274  try {
275  if (cpf__) { delete cpf__; }
276 
277  cpf__ = new Potential< GUM_SCALAR >();
278 
279  for (auto var: formulas__->variablesSequence()) {
280  cpf__->add(*var);
281  }
282 
283  auto params = class__->scope();
284 
285  Instantiation inst(formulas__);
286  Instantiation jnst(cpf__);
287 
288  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
289  inst.inc(), jnst.inc()) {
290  // With CPT defined using rules, empty values can appear
291  auto val = formulas__->get(inst);
292  if (val == "") { val = "0.0"; }
293 
294  Formula f(val);
295 
296  for (auto item: params) {
297  f.variables().insert(item.first, item.second->value());
298  }
299 
300  cpf__->set(jnst, (GUM_SCALAR)f.result());
301  }
302 
303  GUM_ASSERT(inst.end() && jnst.end());
304 
305  } catch (Exception&) { GUM_ERROR(NotFound, "undefined value in cpt"); }
306  GUM_ASSERT(formulas__->contains(type__->variable()));
307  }
const PRMClass< GUM_SCALAR > * class__
A pointe toward the class of this attribute.
MultiDimImplementation< std::string > * formulas__
A pointer on the Potential of this attribute.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
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:54
PRMType * type__
The random variable type of this attribute.

◆ formulas() [1/2]

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

Definition at line 311 of file PRMFormAttribute_tpl.h.

311  {
312  if (cpf__) {
313  delete cpf__;
314  cpf__ = 0;
315  }
316  return *formulas__;
317  }
MultiDimImplementation< std::string > * formulas__
A pointer on the Potential of this attribute.
Potential< GUM_SCALAR > * cpf__
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 321 of file PRMFormAttribute_tpl.h.

321  {
322  return *formulas__;
323  }
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 187 of file PRMFormAttribute_tpl.h.

187  {
188  PRMScalarAttribute< GUM_SCALAR >* cast = 0;
189 
190  try {
191  cast = new PRMScalarAttribute< GUM_SCALAR >(this->name(),
192  type().superType());
193  } catch (NotFound&) {
194  GUM_ERROR(OperationNotAllowed,
195  "this ScalarAttribute can not have cast descendant");
196  }
197 
198  cast->addParent(*this);
199 
200  const DiscreteVariable& my_var = type().variable();
201  DiscreteVariable& cast_var = cast->type().variable();
202  Instantiation inst(cast->cpf());
203 
204  for (inst.setFirst(); !inst.end(); inst.inc()) {
205  if (type().label_map()[inst.val(my_var)] == inst.val(cast_var)) {
206  cast->cpf().set(inst, 1);
207  } else {
208  cast->cpf().set(inst, 0);
209  }
210  }
211 
212  GUM_ASSERT(formulas__->contains(type__->variable()));
213  return cast;
214  }
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 std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
MultiDimImplementation< std::string > * formulas__
A pointer on the Potential 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:93
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:54
PRMType * type__
The random variable type of this attribute.

◆ 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::PRMFormAttribute< GUM_SCALAR >::newFactory ( const PRMClass< GUM_SCALAR > &  c) const
virtual

See gum::prm::PRMAttribute.

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

Definition at line 64 of file PRMFormAttribute_tpl.h.

65  {
66  auto impl = static_cast< MultiDimImplementation< std::string >* >(
67  this->formulas__->newFactory());
68  return new PRMFormAttribute< GUM_SCALAR >(c,
69  this->name(),
70  this->type(),
71  impl);
72  }
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 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 >
PRMFormAttribute< GUM_SCALAR > & gum::prm::PRMFormAttribute< GUM_SCALAR >::operator= ( const PRMFormAttribute< GUM_SCALAR > &  source)
private

Definition at line 267 of file PRMFormAttribute_tpl.h.

268  {
269  GUM_ERROR(OperationNotAllowed, "Cannot copy FormAttribute");
270  }
#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::PRMFormAttribute< GUM_SCALAR >::setAsCastDescendant ( PRMAttribute< GUM_SCALAR > *  attr)
virtual

See gum::prm::PRMAttribute.

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

Definition at line 217 of file PRMFormAttribute_tpl.h.

218  {
219  try {
220  type().setSuper(cast->type());
221  } catch (OperationNotAllowed&) {
222  GUM_ERROR(OperationNotAllowed,
223  "this ScalarAttribute can not have cast descendant");
224  } catch (TypeError&) {
225  std::stringstream msg;
226  msg << type().name() << " is not a subtype of " << cast->type().name();
227  GUM_ERROR(TypeError, msg.str());
228  }
229 
230  cast->becomeCastDescendant(type());
231  }
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 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: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::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 326 of file PRMFormAttribute_tpl.h.

327  {
328  if (&(old_type) == type__) {
329  GUM_ERROR(OperationNotAllowed, "Cannot replace attribute own type");
330  }
331  if (old_type->domainSize() != new_type->domainSize()) {
332  GUM_ERROR(OperationNotAllowed,
333  "Cannot replace types with difference domain size");
334  }
335  if (!formulas__->contains(old_type.variable())) {
336  GUM_ERROR(NotFound, "could not find variable " + old_type.name());
337  }
338 
339  auto old = formulas__;
340 
341  formulas__ = new MultiDimArray< std::string >();
342 
343  for (auto var: old->variablesSequence()) {
344  if (var != &(old_type.variable())) {
345  formulas__->add(*var);
346  } else {
347  formulas__->add(new_type.variable());
348  }
349  }
350 
351  Instantiation inst(formulas__), jnst(old);
352 
353  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
354  inst.inc(), jnst.inc()) {
355  formulas__->set(inst, old->get(jnst));
356  }
357 
358  delete old;
359 
360  if (cpf__) {
361  delete cpf__;
362  cpf__ = 0;
363  }
364 
365  GUM_ASSERT(inst.end() && jnst.end());
366  GUM_ASSERT(formulas__->contains(type__->variable()));
367  GUM_ASSERT(!formulas__->contains(new_type.variable()));
368  GUM_ASSERT(formulas__->contains(new_type.variable()));
369  }
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
MultiDimImplementation< std::string > * formulas__
A pointer on the Potential of this attribute.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
PRMType * type__
The random variable type of this attribute.

◆ 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 146 of file PRMFormAttribute_tpl.h.

146  {
147  return *type__;
148  }
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 151 of file PRMFormAttribute_tpl.h.

151  {
152  return *type__;
153  }
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 372 of file PRMFormAttribute_tpl.h.

372  {
373  return type__;
374  }
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 377 of file PRMFormAttribute_tpl.h.

377  {
378  if (type__->variable().domainSize() != t->variable().domainSize()) {
379  GUM_ERROR(OperationNotAllowed,
380  "Cannot replace types with difference domain size");
381  }
382  auto old = formulas__;
383 
384  formulas__ = new MultiDimArray< std::string >();
385 
386  for (auto var: old->variablesSequence()) {
387  if (var != &(type__->variable())) {
388  formulas__->add(*var);
389  } else {
390  formulas__->add(t->variable());
391  }
392  }
393 
394  Instantiation inst(formulas__), jnst(old);
395 
396  for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
397  inst.inc(), jnst.inc()) {
398  formulas__->set(inst, old->get(jnst));
399  }
400 
401  delete old;
402 
403  type__ = t;
404 
405  if (cpf__) {
406  delete cpf__;
407  cpf__ = 0;
408  }
409 
410  GUM_ASSERT(formulas__->contains(type__->variable()));
411  GUM_ASSERT(inst.end() && jnst.end());
412  }
virtual Size domainSize() const =0
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
MultiDimImplementation< std::string > * formulas__
A pointer on the Potential of this attribute.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
Potential< GUM_SCALAR > * cpf__
A pointer on the Potential of this attribute.
virtual bool contains(const DiscreteVariable &v) const override
Returns true if var is in *this.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:54
PRMType * type__
The random variable type of this attribute.

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 122 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 116 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 119 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 266 of file PRMClassElement.h.

◆ type__

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

The random variable type of this attribute.

Definition at line 113 of file PRMFormAttribute.h.


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