39 template <
typename GUM_SCALAR >
42 const std::string& name,
46 __type(new
PRMType(type)), __cpf(0), __formulas(impl), __class(&c) {
53 template <
typename GUM_SCALAR >
61 template <
typename GUM_SCALAR >
67 c, this->
name(), this->
type(), impl);
70 template <
typename GUM_SCALAR >
76 if (var != &(
__type->variable())) {
copy->__formulas->add(*var); }
80 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
81 inst.inc(), jnst.
inc()) {
85 GUM_ASSERT(
copy->__formulas->contains(
copy->__type->variable()));
89 template <
typename GUM_SCALAR >
96 for (
const auto& var : source.
cpf().variablesSequence()) {
106 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
107 inst.inc(), jnst.inc()) {
111 GUM_ASSERT(inst.end() && jnst.end());
116 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
117 inst.inc(), jnst.inc()) {
122 GUM_ASSERT(inst.end() && jnst.end());
134 template <
typename GUM_SCALAR >
140 template <
typename GUM_SCALAR >
145 template <
typename GUM_SCALAR >
150 template <
typename GUM_SCALAR >
156 template <
typename GUM_SCALAR >
167 elt.
name() <<
" as parent of " << this->
name());
170 elt.
name() <<
" of wrong type as parent of " << this->
name(););
176 template <
typename GUM_SCALAR >
180 template <
typename GUM_SCALAR >
190 "this ScalarAttribute can not have cast descendant");
199 for (inst.setFirst(); !inst.end(); inst.inc()) {
200 if (
type().
label_map()[inst.val(my_var)] == inst.val(cast_var)) {
201 cast->
cpf().set(inst, 1);
203 cast->
cpf().set(inst, 0);
211 template <
typename GUM_SCALAR >
218 "this ScalarAttribute can not have cast descendant");
220 std::stringstream msg;
221 msg <<
type().
name() <<
" is not a subtype of " << cast->
type().name();
228 template <
typename GUM_SCALAR >
253 template <
typename GUM_SCALAR >
261 template <
typename GUM_SCALAR >
267 template <
typename GUM_SCALAR >
278 auto params =
__class->scope();
287 if (val ==
"") { val =
"0.0"; }
291 for (
auto item : params) {
298 GUM_ASSERT(inst.
end() && jnst.
end());
304 template <
typename GUM_SCALAR >
314 template <
typename GUM_SCALAR >
320 template <
typename GUM_SCALAR >
323 if (&(old_type) ==
__type) {
328 "Cannot replace types with difference domain size");
338 for (
auto var : old->variablesSequence()) {
339 if (var != &(old_type.
variable())) {
348 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
349 inst.inc(), jnst.
inc()) {
360 GUM_ASSERT(inst.end() && jnst.
end());
366 template <
typename GUM_SCALAR >
371 template <
typename GUM_SCALAR >
375 "Cannot replace types with difference domain size");
381 for (
auto var : old->variablesSequence()) {
382 if (var != &(
__type->variable())) {
391 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
392 inst.inc(), jnst.
inc()) {
406 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().
gum is the global namespace for all aGrUM entities
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.
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.
Headers of gum::PRMScalarAttribute.