42 template <
typename GUM_SCALAR >
45 const std::string& name,
49 __type(new
PRMType(type)), __cpf(0), __formulas(impl), __class(&c) {
56 template <
typename GUM_SCALAR >
64 template <
typename GUM_SCALAR >
70 c, this->
name(), this->
type(), impl);
73 template <
typename GUM_SCALAR >
79 if (var != &(
__type->variable())) {
copy->__formulas->add(*var); }
83 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
84 inst.inc(), jnst.
inc()) {
88 GUM_ASSERT(
copy->__formulas->contains(
copy->__type->variable()));
92 template <
typename GUM_SCALAR >
99 for (
const auto& var : source.
cpf().variablesSequence()) {
109 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
110 inst.inc(), jnst.inc()) {
114 GUM_ASSERT(inst.end() && jnst.end());
119 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
120 inst.inc(), jnst.inc()) {
125 GUM_ASSERT(inst.end() && jnst.end());
137 template <
typename GUM_SCALAR >
143 template <
typename GUM_SCALAR >
148 template <
typename GUM_SCALAR >
153 template <
typename GUM_SCALAR >
159 template <
typename GUM_SCALAR >
170 elt.
name() <<
" as parent of " << this->
name());
173 elt.
name() <<
" of wrong type as parent of " << this->
name(););
179 template <
typename GUM_SCALAR >
183 template <
typename GUM_SCALAR >
193 "this ScalarAttribute can not have cast descendant");
202 for (inst.setFirst(); !inst.end(); inst.inc()) {
203 if (
type().
label_map()[inst.val(my_var)] == inst.val(cast_var)) {
204 cast->
cpf().set(inst, 1);
206 cast->
cpf().set(inst, 0);
214 template <
typename GUM_SCALAR >
221 "this ScalarAttribute can not have cast descendant");
223 std::stringstream msg;
224 msg <<
type().
name() <<
" is not a subtype of " << cast->
type().name();
231 template <
typename GUM_SCALAR >
256 template <
typename GUM_SCALAR >
264 template <
typename GUM_SCALAR >
270 template <
typename GUM_SCALAR >
281 auto params =
__class->scope();
290 if (val ==
"") { val =
"0.0"; }
294 for (
auto item : params) {
301 GUM_ASSERT(inst.
end() && jnst.
end());
307 template <
typename GUM_SCALAR >
317 template <
typename GUM_SCALAR >
323 template <
typename GUM_SCALAR >
326 if (&(old_type) ==
__type) {
331 "Cannot replace types with difference domain size");
341 for (
auto var : old->variablesSequence()) {
342 if (var != &(old_type.
variable())) {
351 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
352 inst.inc(), jnst.
inc()) {
363 GUM_ASSERT(inst.end() && jnst.
end());
369 template <
typename GUM_SCALAR >
374 template <
typename GUM_SCALAR >
378 "Cannot replace types with difference domain size");
384 for (
auto var : old->variablesSequence()) {
385 if (var != &(
__type->variable())) {
394 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
395 inst.inc(), jnst.
inc()) {
409 GUM_ASSERT(inst.end() && jnst.
end());
aGrUM's Potential is a multi-dimensional array with tensor operators.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
const std::string & name() const
Returns the name of this object.
PRMType & superType()
Returns the super type of this type.
void setSuper(PRMType &t)
Changes the PRMType of this PRMType super.
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
const std::string & name() const
Returns the name of this object.
virtual PRMType & type()=0
See gum::PRMClassElement::type().
Abstract class representing an element of PRM class.
Base class for discrete random variable.
virtual PRMType & type()
See gum::PRMClassElement::type().
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void becomeCastDescendant(PRMType &subtype)=0
Change this attribute to be a cast descendant of a an attribute with type subtype.
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
virtual Size domainSize() const =0
virtual const Potential< GUM_SCALAR > & cpf() const
See gum::PRMClassElement::cpf().
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
std::string to_string(const Formula &f)
void inc()
Operator increment.
virtual const Potential< GUM_SCALAR > & cpf() const =0
See gum::PRMClassElement::cpf().
Base class for all aGrUM's exceptions.
Multidimensional matrix stored as an array in memory.
Set of pairs of elements with fast search for both elements.
This is a decoration of the DiscreteVariable class.
virtual void add(const DiscreteVariable &v) override
Adds a new var to the variables of the multidimensional matrix.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
Class for assigning/browsing values to tuples of discrete variables.
static std::string LEFT_CAST()
Enumeration of the different types of objects handled by a PRM.
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
void setFirst()
Assign the first values to the tuple of the Instantiation.
const std::vector< Idx > & label_map() const
Returns the vector in which the i-th element is the Idx of the super type's label for the i-th label ...
PRMAttribute is a member of a Class in a PRM.
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.
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::_addParent().
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const override=0
Creates an empty clone of this MultiDimContainer.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
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.
<agrum/PRM/elements/scalarAttribute.h>
std::string _safeName
The safe name of this PRMClassElement.
#define GUM_ERROR(type, msg)
bool end() const
Returns true if the Instantiation reached the end.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.