60 template < GUM_Numeric GUM_SCALAR >
62 std::string_view
name,
74 template < GUM_Numeric GUM_SCALAR >
82 template < GUM_Numeric GUM_SCALAR >
89 template < GUM_Numeric GUM_SCALAR >
93 this->
cpf().content()->newFactory());
97 template < GUM_Numeric GUM_SCALAR >
112 template < GUM_Numeric GUM_SCALAR >
117 _cpf_ =
new Tensor< GUM_SCALAR >();
119 for (
auto var: source.
cpf().variablesSequence()) {
125 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end()); inst.inc(), jnst.
inc()) {
126 _cpf_->set(inst, source.
cpf().get(jnst));
129 GUM_ASSERT(inst.end() && jnst.
end());
134 template < GUM_Numeric GUM_SCALAR >
140 template < GUM_Numeric GUM_SCALAR >
146 template < GUM_Numeric GUM_SCALAR >
151 template < GUM_Numeric GUM_SCALAR >
156 template < GUM_Numeric GUM_SCALAR >
161 template < GUM_Numeric GUM_SCALAR >
173 template < GUM_Numeric GUM_SCALAR >
176 template < GUM_Numeric GUM_SCALAR >
178 if (!
type().isSubType()) {
183 cast->addParent(*
this);
189 if (
type().label_map()[inst.
val(my_var)] == inst.
val(cast_var)) {
190 cast->cpf().set(inst, 1);
192 cast->cpf().set(inst, 0);
199 template < GUM_Numeric GUM_SCALAR >
207 std::format(
"{} is not a subtype of {}",
type().
name(),
cast->type().name()))
212 template < GUM_Numeric GUM_SCALAR >
215 _cpf_ =
new Tensor< GUM_SCALAR >();
231 template < GUM_Numeric GUM_SCALAR >
233 if (&(old_type) ==
_type_) {
245 _cpf_ =
new Tensor< GUM_SCALAR >();
247 for (
auto var: old->variablesSequence()) {
248 if (var != &(old_type.
variable())) {
257 for (inst.setFirst(), jnst.
setFirst(); !(inst.end() || jnst.
end()); inst.inc(), jnst.
inc()) {
258 _cpf_->set(inst, old->get(jnst));
263 GUM_ASSERT(inst.end() && jnst.
end());
269 template < GUM_Numeric GUM_SCALAR >
274 template < GUM_Numeric GUM_SCALAR >
281 _cpf_ =
new Tensor< GUM_SCALAR >();
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()); inst.inc(), jnst.
inc()) {
294 _cpf_->set(inst, old->get(jnst));
302 GUM_ASSERT(inst.end() && jnst.
end());
Headers of gum::PRMAttribute.
Headers of gum::PRMScalarAttribute.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
bool existsFirst(const T1 &first) const
Returns true if first is the first element in a pair in the gum::Bijection.
Set of pairs of elements with fast search for both elements.
Base class for discrete random variable.
virtual Size domainSize() const =0
Exception : a similar element already exists.
Exception : fatal (unknown ?) error.
Class for assigning/browsing values to tuples of discrete variables.
bool end() const
Returns true if the Instantiation reached the end.
void inc()
Operator increment.
Idx pos(const DiscreteVariable &v) const final
Returns the position of the variable v.
Idx val(Idx i) const
Returns the current value of the variable at position i.
void setFirst()
Assign the first values to the tuple of the Instantiation.
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Exception : wrong type for this operation.
PRMAttribute is a member of a Class in a PRM.
PRMAttribute(std::string_view name)
Destructor.
const Tensor< GUM_SCALAR > & cpf() const override=0
See gum::PRMClassElement::cpf().
PRMType & type() override=0
See gum::PRMClassElement::type().
Abstract class representing an element of PRM class.
virtual std::string cast(const PRMType &t) const
Returns the name of the cast descendant with PRMType t of this PRMClassElement.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
std::string safeName_
The safe name of this PRMClassElement.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
const std::string & name() const
Returns the name of this object.
static std::string RIGHT_CAST()
Enumeration of the different types of objects handled by a PRM.
static std::string LEFT_CAST()
Enumeration of the different types of objects handled by a PRM.
<agrum/PRM/elements/scalarAttribute.h>
void swap(const PRMType &old_type, const PRMType &new_type) override
Swap old_type with new_type in the PRMClassElement cpt.
~PRMScalarAttribute() override
Destructor.
void addParent(const PRMClassElement< GUM_SCALAR > &elt) override
See gum::PRMClassElement::addParent_().
void copyCpf(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bif, const PRMAttribute< GUM_SCALAR > &source) override
See gum::PRMClassElement::elt_type().
PRMType * _type_
The random variable type of this attribute.
Tensor< GUM_SCALAR > * _cpf_
A pointer on the Tensor of this attribute.
void addChild(const PRMClassElement< GUM_SCALAR > &elt) override
See gum::PRMClassElement::addChild_().
PRMType & type() override
See gum::PRMClassElement::type().
void becomeCastDescendant(PRMType &subtype) override
See gum::PRMClassElement::elt_type().
const Tensor< GUM_SCALAR > & cpf() const override
See gum::PRMClassElement::cpf().
void setAsCastDescendant(PRMAttribute< GUM_SCALAR > *attr) override
See gum::PRMClassElement::elt_type().
PRMType * type_() override
PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const override
See gum::PRMClassElement::elt_type().
PRMAttribute< GUM_SCALAR > * getCastDescendant() const override
See gum::PRMClassElement::elt_type().
PRMAttribute< GUM_SCALAR > * newFactory(const PRMClass< GUM_SCALAR > &c) const override
See gum::PRMClassElement::elt_type().
PRMScalarAttribute & operator=(const PRMScalarAttribute &from)
Copy operator. Don't use it.
PRMScalarAttribute(std::string_view name, const PRMType &type, MultiDimImplementation< GUM_SCALAR > *impl=new MultiDimArray< GUM_SCALAR >())
Constructor used by gum::Class.
PRMAttribute< GUM_SCALAR > * copy(Bijection< const DiscreteVariable *, const DiscreteVariable * > bij) const override
See gum::PRMClassElement::elt_type().
This is a decoration of the DiscreteVariable class.
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 ...
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
const std::string & name() const
Returns the name of this object.
#define GUM_ERROR(type, msg)
namespace for all probabilistic relational models entities
Tensor< GUM_SCALAR > * copyTensor(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const Tensor< GUM_SCALAR > &source)
Returns a copy of a Tensor after applying a bijection over the variables in source.
gum is the global namespace for all aGrUM entities