37 template <
typename GUM_SCALAR >
39 const std::string& name,
51 template <
typename GUM_SCALAR >
58 "Illegal call to the copy constructor of gum::ScalarAttribute");
61 template <
typename GUM_SCALAR >
68 template <
typename GUM_SCALAR >
72 this->
cpf().content()->newFactory());
77 template <
typename GUM_SCALAR >
92 template <
typename GUM_SCALAR >
99 for (
auto var : source.
cpf().variablesSequence()) {
105 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
106 inst.inc(), jnst.inc()) {
107 __cpf->set(inst, source.
cpf().get(jnst));
110 GUM_ASSERT(inst.end() && jnst.end());
112 GUM_ASSERT(!
__cpf->contains(source.
type().variable()));
115 template <
typename GUM_SCALAR >
119 "Illegal call to the copy operator of gum::ScalarAttribute");
122 template <
typename GUM_SCALAR >
128 template <
typename GUM_SCALAR >
133 template <
typename GUM_SCALAR >
138 template <
typename GUM_SCALAR >
144 template <
typename GUM_SCALAR >
151 elt.
name() <<
" as parent of " << this->
name());
154 elt.
name() <<
" of wrong type as parent of " << this->
name());
159 template <
typename GUM_SCALAR >
163 template <
typename GUM_SCALAR >
173 "this ScalarAttribute can not have cast descendant");
181 for (inst.setFirst(); !inst.end(); inst.inc()) {
182 if (
type().
label_map()[inst.val(my_var)] == inst.val(cast_var)) {
183 cast->
cpf().set(inst, 1);
185 cast->
cpf().set(inst, 0);
192 template <
typename GUM_SCALAR >
199 "this ScalarAttribute can not have cast descendant");
201 std::stringstream msg;
202 msg <<
type().
name() <<
" is not a subtype of " << cast->
type().name();
208 template <
typename GUM_SCALAR >
227 template <
typename GUM_SCALAR >
230 if (&(old_type) ==
__type) {
235 "Cannot replace types with difference domain size");
245 for (
auto var : old->variablesSequence()) {
246 if (var != &(old_type.
variable())) {
255 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
256 inst.inc(), jnst.
inc()) {
257 __cpf->set(inst, old->get(jnst));
262 GUM_ASSERT(inst.end() && jnst.
end());
268 template <
typename GUM_SCALAR >
273 template <
typename GUM_SCALAR >
277 "Cannot replace types with difference domain size");
283 for (
auto var : old->variablesSequence()) {
284 if (var != &(
__type->variable())) {
287 __cpf->add(t->variable());
293 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
294 inst.inc(), jnst.
inc()) {
295 __cpf->set(inst, old->get(jnst));
303 GUM_ASSERT(inst.end() && jnst.
end());
virtual void addChild(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::_addChild().
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
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.
virtual void becomeCastDescendant(PRMType &subtype)
See gum::PRMClassElement::elt_type().
PRMType & superType()
Returns the super type of this type.
void setSuper(PRMType &t)
Changes the PRMType of this PRMType super.
virtual ~PRMScalarAttribute()
Destructor.
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
virtual void swap(const PRMType &old_type, const PRMType &new_type)
Swap old_type with new_type in the PRMClassElement cpt.
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 PRMAttribute< GUM_SCALAR > * newFactory(const PRMClass< GUM_SCALAR > &c) const
See gum::PRMClassElement::elt_type().
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const
See gum::PRMClassElement::elt_type().
virtual void copyCpf(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bif, const PRMAttribute< GUM_SCALAR > &source)
See gum::PRMClassElement::elt_type().
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
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
virtual const Potential< GUM_SCALAR > & cpf() const
See gum::PRMClassElement::cpf().
void inc()
Operator increment.
PRMType * __type
The random variable type of this attribute.
virtual const Potential< GUM_SCALAR > & cpf() const =0
See gum::PRMClassElement::cpf().
Set of pairs of elements with fast search for both elements.
Potential< GUM_SCALAR > * copyPotential(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const Potential< GUM_SCALAR > &source)
Returns a copy of a Potential after applying a bijection over the variables in source.
This is a decoration of the DiscreteVariable class.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
virtual PRMAttribute< GUM_SCALAR > * copy(Bijection< const DiscreteVariable *, const DiscreteVariable * > bij) const
See gum::PRMClassElement::elt_type().
Headers of gum::PRMAttribute.
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...
virtual void setAsCastDescendant(PRMAttribute< GUM_SCALAR > *attr)
See gum::PRMClassElement::elt_type().
Potential< GUM_SCALAR > * __cpf
A pointer on the Potential of this attribute.
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 ...
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const
See gum::PRMClassElement::elt_type().
virtual PRMType * _type()
<agrum/multidim/multiDimImplementation.h>
PRMAttribute is a member of a Class in a PRM.
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::_addParent().
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>
PRMScalarAttribute(const std::string &name, const PRMType &type, MultiDimImplementation< GUM_SCALAR > *impl=new MultiDimArray< GUM_SCALAR >())
Constructor used by gum::Class.
std::string _safeName
The safe name of this PRMClassElement.
#define GUM_ERROR(type, msg)
PRMScalarAttribute & operator=(const PRMScalarAttribute &from)
Copy operator. Don't use it.
bool end() const
Returns true if the Instantiation reached the end.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.