40 template <
typename GUM_SCALAR >
42 const std::string& name,
54 template <
typename GUM_SCALAR >
61 "Illegal call to the copy constructor of gum::ScalarAttribute");
64 template <
typename GUM_SCALAR >
71 template <
typename GUM_SCALAR >
75 this->
cpf().content()->newFactory());
80 template <
typename GUM_SCALAR >
95 template <
typename GUM_SCALAR >
102 for (
auto var : source.
cpf().variablesSequence()) {
108 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end());
109 inst.inc(), jnst.inc()) {
110 __cpf->set(inst, source.
cpf().get(jnst));
113 GUM_ASSERT(inst.end() && jnst.end());
115 GUM_ASSERT(!
__cpf->contains(source.
type().variable()));
118 template <
typename GUM_SCALAR >
122 "Illegal call to the copy operator of gum::ScalarAttribute");
125 template <
typename GUM_SCALAR >
131 template <
typename GUM_SCALAR >
136 template <
typename GUM_SCALAR >
141 template <
typename GUM_SCALAR >
147 template <
typename GUM_SCALAR >
154 elt.
name() <<
" as parent of " << this->
name());
157 elt.
name() <<
" of wrong type as parent of " << this->
name());
162 template <
typename GUM_SCALAR >
166 template <
typename GUM_SCALAR >
176 "this ScalarAttribute can not have cast descendant");
184 for (inst.setFirst(); !inst.end(); inst.inc()) {
185 if (
type().
label_map()[inst.val(my_var)] == inst.val(cast_var)) {
186 cast->
cpf().set(inst, 1);
188 cast->
cpf().set(inst, 0);
195 template <
typename GUM_SCALAR >
202 "this ScalarAttribute can not have cast descendant");
204 std::stringstream msg;
205 msg <<
type().
name() <<
" is not a subtype of " << cast->
type().name();
211 template <
typename GUM_SCALAR >
230 template <
typename GUM_SCALAR >
233 if (&(old_type) ==
__type) {
238 "Cannot replace types with difference domain size");
248 for (
auto var : old->variablesSequence()) {
249 if (var != &(old_type.
variable())) {
258 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
259 inst.inc(), jnst.
inc()) {
260 __cpf->set(inst, old->get(jnst));
265 GUM_ASSERT(inst.end() && jnst.
end());
271 template <
typename GUM_SCALAR >
276 template <
typename GUM_SCALAR >
280 "Cannot replace types with difference domain size");
286 for (
auto var : old->variablesSequence()) {
287 if (var != &(
__type->variable())) {
290 __cpf->add(t->variable());
296 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end());
297 inst.inc(), jnst.
inc()) {
298 __cpf->set(inst, old->get(jnst));
306 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().
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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().
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.