56 template < GUM_Numeric GUM_SCALAR >
62 for (
const auto agg:
_type_->aggregates())
67 for (
const auto attr:
_type_->attributes())
71 template < GUM_Numeric GUM_SCALAR >
85 template < GUM_Numeric GUM_SCALAR >
93 template < GUM_Numeric GUM_SCALAR >
96 for (
const auto chain:
type().slotChains()) {
102 for (
const auto attr:
type().attributes()) {
107 for (
const auto agg:
type().aggregates()) {
110 for (
const auto node:
type().containerDag().parents(agg->id())) {
114 auto elt = &(
type().get(node));
118 for (
const auto inst: *(*p_ref)) {
119 attr.
addParent(inst->get(sc->lastElt().safeName()));
127 template < GUM_Numeric GUM_SCALAR >
129 auto first_id = sc->
chain()[0]->id();
131 if (!p_first) {
return; }
136 for (
auto current: *set) {
137 auto& ref = current->type().get(sc->
chain()[idx]->name());
138 auto p_next = current->_referenceMap_.tryGet(ref.id());
143 "the reference slot " << ref.name() <<
" of " << current->name()
144 <<
" is not assigned")
146 for (
auto next: *(*p_next)) {
154 GUM_ASSERT(set->size() > 0);
172 for (
auto instance: *set) {
173 auto& attr = instance->get(sc->
lastElt().safeName());
179 template < GUM_Numeric GUM_SCALAR >
192 "given Instance type is not a proper "
193 "subclass of the ReferenceSlot<GUM_SCALAR> slot type");
200 && ((*p_ref_slot)->size() == 1)) {
212 if (!instance.
type().isSubTypeOf(sc.
end())) {
214 "given Instance type is not a proper "
215 "subclass of the ClassElementContainer pointed"
216 " by the SlotChain<GUM_SCALAR>");
222 && ((*p_ref_sc)->size() == 1)) {
230 if (!
type().isOutputNode(*elt)) {
242 (*p_ref_add)->insert(&instance);
245 template < GUM_Numeric GUM_SCALAR >
250 template < GUM_Numeric GUM_SCALAR >
255 GUM_ASSERT(&(attr->type().variable()) != &(source->
type().
variable()));
256 attr->setId(source->
id());
261 template < GUM_Numeric GUM_SCALAR >
264 GUM_ASSERT(&(attr->type().variable()) != &(source->
type().
variable()));
266 attr->cpf().fill((GUM_SCALAR)0);
267 attr->setId(source->
id());
272 template < GUM_Numeric GUM_SCALAR >
279 template < GUM_Numeric GUM_SCALAR >
285 template < GUM_Numeric GUM_SCALAR >
290 template < GUM_Numeric GUM_SCALAR >
295 template < GUM_Numeric GUM_SCALAR >
300 template < GUM_Numeric GUM_SCALAR >
305 template < GUM_Numeric GUM_SCALAR >
310 template < GUM_Numeric GUM_SCALAR >
317 template < GUM_Numeric GUM_SCALAR >
324 template < GUM_Numeric GUM_SCALAR >
330 template < GUM_Numeric GUM_SCALAR >
336 template < GUM_Numeric GUM_SCALAR >
348 (*p_rm)->insert(
this);
352 template < GUM_Numeric GUM_SCALAR >
358 template < GUM_Numeric GUM_SCALAR >
363 "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> "
364 "matches the given NodeId")
365 if ((*p)->size() > 0) {
366 return **((*p)->begin());
372 template < GUM_Numeric GUM_SCALAR >
378 "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> "
379 "matches the given NodeId")
383 template < GUM_Numeric GUM_SCALAR >
388 template < GUM_Numeric GUM_SCALAR >
393 template < GUM_Numeric GUM_SCALAR >
398 template < GUM_Numeric GUM_SCALAR >
404 template < GUM_Numeric GUM_SCALAR >
411 template < GUM_Numeric GUM_SCALAR >
419 template < GUM_Numeric GUM_SCALAR >
425 template < GUM_Numeric GUM_SCALAR >
431 template < GUM_Numeric GUM_SCALAR >
436 template < GUM_Numeric GUM_SCALAR >
443 template < GUM_Numeric GUM_SCALAR >
450 template < GUM_Numeric GUM_SCALAR >
455 template < GUM_Numeric GUM_SCALAR >
460 template < GUM_Numeric GUM_SCALAR >
465 template < GUM_Numeric GUM_SCALAR >
470 template < GUM_Numeric GUM_SCALAR >
475 template < GUM_Numeric GUM_SCALAR >
481 template < GUM_Numeric GUM_SCALAR >
487 template < GUM_Numeric GUM_SCALAR >
492 template < GUM_Numeric GUM_SCALAR >
499 template < GUM_Numeric GUM_SCALAR >
506 template < GUM_Numeric GUM_SCALAR >
511 template < GUM_Numeric GUM_SCALAR >
517 template < GUM_Numeric GUM_SCALAR >
523 template < GUM_Numeric GUM_SCALAR >
529 template < GUM_Numeric GUM_SCALAR >
535 template < GUM_Numeric GUM_SCALAR >
540 template < GUM_Numeric GUM_SCALAR >
546 template < GUM_Numeric GUM_SCALAR >
552 template < GUM_Numeric GUM_SCALAR >
558 template < GUM_Numeric GUM_SCALAR >
559 std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
564 template < GUM_Numeric GUM_SCALAR >
565 const std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
570 template < GUM_Numeric GUM_SCALAR >
573 return p && (!(*p)->empty());
576 template < GUM_Numeric GUM_SCALAR >
578 const auto& type_attr
585 "cannot build the CPT of " <<
name() <<
"." << attr->
name()
586 <<
": a reference slot of " <<
name()
587 <<
" is probably not assigned")
Headers of gum::prm::PRMInstance<GUM_SCALAR>.
Set of pairs of elements with fast search for both elements.
Exception : fatal (unknown ?) error.
Exception : the element we looked for cannot be found.
Exception : out of bound.
Exception : wrong subtype or subclass.
Exception : a looked-for element could not be found.
Exception: wrong PRMClassElement for this operation.
PRMType & type() override
See gum::PRMClassElement::type().
MultiDimImplementation< GUM_SCALAR > * buildImpl() const
Returns a pointer over an empty gum::MultiDimImplementation of the good type for this PRMAggregate.
PRMAttribute is a member of a Class in a PRM.
virtual void copyCpf(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bif, const PRMAttribute< GUM_SCALAR > &source)=0
See gum::PRMClassElement::elt_type().
const Tensor< GUM_SCALAR > & cpf() const override=0
See gum::PRMClassElement::cpf().
PRMType & type() override=0
See gum::PRMClassElement::type().
void addParent(const PRMClassElement< GUM_SCALAR > &elt) override=0
See gum::PRMClassElement::addParent_().
Abstract class representing an element of PRM class.
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations.
const Set< PRMInstance< GUM_SCALAR > * > & _set_
bool operator==(const RefConstIterator &from) const
const PRMInstance< GUM_SCALAR > & operator*() const
RefConstIterator & operator++()
Set< PRMInstance< GUM_SCALAR > * >::const_iterator _iter_
RefConstIterator & operator=(const RefConstIterator &from)
bool operator!=(const RefConstIterator &from) const
RefConstIterator(const Set< PRMInstance< GUM_SCALAR > * > &set)
const PRMInstance< GUM_SCALAR > * operator->() const
Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations.
PRMInstance< GUM_SCALAR > & operator*() const
Set< PRMInstance< GUM_SCALAR > * >::iterator _iter_
Set< PRMInstance< GUM_SCALAR > * > & _set_
RefIterator(Set< PRMInstance< GUM_SCALAR > * > &set)
bool operator==(const RefIterator &from) const
RefIterator & operator++()
PRMInstance< GUM_SCALAR > * operator->() const
RefIterator & operator=(const RefIterator &from)
bool operator!=(const RefIterator &from) const
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
NodeProperty< PRMAttribute< GUM_SCALAR > * > _nodeIdMap_
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
const PRMInstance< GUM_SCALAR > & getInstance(NodeId id) const
Fast access to the first instance in a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.
void instantiate()
Instantiate all nodes which requires it.
PRMInstance< GUM_SCALAR > & operator=(const PRMClass< GUM_SCALAR > &from)
Copy operator. Don't use it.
bool exists(NodeId id) const
Returns true if id matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
const iterator & end()
Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in...
typename NodeProperty< PRMAttribute< GUM_SCALAR > * >::const_iterator const_iterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
void _copyAttribute_(PRMAttribute< GUM_SCALAR > *source)
Used at construction to instantiate attributes.
NodeProperty< Set< PRMInstance< GUM_SCALAR > * > * > _referenceMap_
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and t...
prm_type obj_type() const override
Returns the PRM type of this object.
bool _instantiated_
True if this instance has been instantiated.
void _copyAggregates_(PRMAggregate< GUM_SCALAR > *source)
Used at construction to instantiate aggregates.
Bijection< const DiscreteVariable *, const DiscreteVariable * > _bijection_
A bijection used for MultiDim handling.
Size size() const
Returns the number of attributes in this PRMInstance<GUM_SCALAR>.
~PRMInstance() override
Destructor.
PRMClass< GUM_SCALAR > * _type_
The type of this PRMInstance<GUM_SCALAR>.
void _instantiateSlotChain_(PRMSlotChain< GUM_SCALAR > *sc)
Retrieve all instances referred by sc.
typename NodeProperty< std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > * >::const_iterator InvRefConstIterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
typename NodeProperty< PRMAttribute< GUM_SCALAR > * >::iterator iterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
bool hasRefAttr(NodeId id) const
Returns true if id has at least one referring PRMAttribute<GUM_SCALAR>.
typename NodeProperty< std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > * >::iterator InvRefIterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
void add(NodeId id, PRMInstance< GUM_SCALAR > &instance)
Add an PRMInstance<GUM_SCALAR> to a given PRMReferenceSlot, PRMSlotChain<GUM_SCALAR> or output node.
NodeProperty< std::vector< pair > * > _referingAttr_
The set of pair (instance, attribute) referring an attribute of this instance.
InvRefIterator beginInvRef()
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
const Bijection< const DiscreteVariable *, const DiscreteVariable * > & bijection() const
Returns a mapping between DiscreteVariable used in this and the ones used in this PRMInstance<GUM_SCA...
void _copyAttributeCPF_(PRMAttribute< GUM_SCALAR > *attr)
Copy the content of an PRMAttribute<GUM_SCALAR> from its Class<GUM_SCALAR> counterpart.
const InvRefIterator & endInvRef()
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
PRMInstance(std::string_view name, PRMClass< GUM_SCALAR > &type)
Default constructor of an PRMInstance<GUM_SCALAR>.
std::vector< std::pair< PRMInstance< GUM_SCALAR > *, std::string > > & getRefAttr(NodeId id)
Returns a vector of pairs of refering attributes of id.
void _addReferingInstance_(PRMSlotChain< GUM_SCALAR > *sc, PRMInstance< GUM_SCALAR > *i)
Add this as a referring instance over the attribute pointed by sc in i.
void _doInstantiate_()
Starts this instance instantiations.
iterator begin()
Returns an iterator at the begining of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInst...
const Set< PRMInstance< GUM_SCALAR > * > & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
PRMObject(std::string_view name)
Constructor.
const std::string & name() const
Returns the name of this object.
prm_type
Enumeration of the different types of objects handled by a PRM.
A PRMReferenceSlot represent a relation between two PRMClassElementContainer.
PRMClassElementContainer< GUM_SCALAR > & slotType()
Returns the type of this slot, which is a PRMClassElementContainer (it is not the type of PRMObject).
PRMScalarAttribute(std::string_view name, const PRMType &type, MultiDimImplementation< GUM_SCALAR > *impl=new MultiDimArray< GUM_SCALAR >())
Constructor used by gum::Class.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
PRMType & type() override
This is similar to the following call: this->lastElt().type().
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
Sequence< PRMClassElement< GUM_SCALAR > * > & chain()
Return the sequence representing the chain of elements in this PRMSlotChain.
bool isMultiple() const
Return true if this slot chain contains at least one multiple reference slot.
PRMClassElementContainer< GUM_SCALAR > & end()
Returns the PRMClassElement<GUM_SCALAR>Container over which this slot chain ends.
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size NodeId
Type for node ids.
Headers of MultiDimSparse.
namespace for all probabilistic relational models entities
gum is the global namespace for all aGrUM entities