55 template <
typename GUM_SCALAR >
61 for (
const auto agg:
_type_->aggregates())
66 for (
const auto attr:
_type_->attributes())
70 template <
typename GUM_SCALAR >
84 template <
typename GUM_SCALAR >
92 template <
typename GUM_SCALAR >
95 for (
const auto chain:
type().slotChains()) {
101 for (
const auto attr:
type().attributes()) {
106 for (
const auto agg: type().aggregates()) {
109 for (
const auto node: type().containerDag().parents(agg->id())) {
113 auto elt = &(
type().get(node));
119 for (
const auto inst: instances) {
120 attr.
addParent(inst->get(sc->lastElt().safeName()));
129 template <
typename GUM_SCALAR >
131 auto first_id = sc->
chain()[0]->id();
137 for (
auto current: *set) {
138 auto& ref = current->type().get(sc->
chain()[idx]->name());
139 for (
auto next: *(current->_referenceMap_[ref.id()])) {
147 GUM_ASSERT(set->size() > 0);
158 _addReferingInstance_(sc, i);
165 for (
auto instance: *set) {
166 auto& attr = instance->get(sc->
lastElt().safeName());
172 template <
typename GUM_SCALAR >
177 elt = &(
type().get(
id));
189 "given Instance type is not a proper "
190 "subclass of the ReferenceSlot<GUM_SCALAR> slot type");
204 PRMSlotChain< GUM_SCALAR >& sc
205 =
static_cast< PRMSlotChain< GUM_SCALAR >&
>(type().get(
id));
208 if (!instance.
type().isSubTypeOf(sc.end())) {
210 "given Instance type is not a proper "
211 "subclass of the ClassElementContainer pointed"
212 " by the SlotChain<GUM_SCALAR>");
216 if (_referenceMap_.exists(
id)
226 if (!type().isOutputNode(*elt)) {
236 _referenceMap_[id]->insert(&instance);
239 template <
typename GUM_SCALAR >
244 template <
typename GUM_SCALAR >
255 template <
typename GUM_SCALAR >
260 attr->
cpf().fill((GUM_SCALAR)0);
266 template <
typename GUM_SCALAR >
273 template <
typename GUM_SCALAR >
279 template <
typename GUM_SCALAR >
284 template <
typename GUM_SCALAR >
289 template <
typename GUM_SCALAR >
294 template <
typename GUM_SCALAR >
299 template <
typename GUM_SCALAR >
304 template <
typename GUM_SCALAR >
313 template <
typename GUM_SCALAR >
322 template <
typename GUM_SCALAR >
331 template <
typename GUM_SCALAR >
341 template <
typename GUM_SCALAR >
358 template <
typename GUM_SCALAR >
364 template <
typename GUM_SCALAR >
375 "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> "
376 "matches the given NodeId");
380 template <
typename GUM_SCALAR >
387 "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> "
388 "matches the given NodeId");
392 template <
typename GUM_SCALAR >
397 template <
typename GUM_SCALAR >
402 template <
typename GUM_SCALAR >
408 template <
typename GUM_SCALAR >
414 template <
typename GUM_SCALAR >
422 template <
typename GUM_SCALAR >
430 template <
typename GUM_SCALAR >
436 template <
typename GUM_SCALAR >
442 template <
typename GUM_SCALAR >
447 template <
typename GUM_SCALAR >
454 template <
typename GUM_SCALAR >
461 template <
typename GUM_SCALAR >
466 template <
typename GUM_SCALAR >
471 template <
typename GUM_SCALAR >
476 template <
typename GUM_SCALAR >
481 template <
typename GUM_SCALAR >
486 template <
typename GUM_SCALAR >
492 template <
typename GUM_SCALAR >
494 const RefConstIterator& from) : _set_(from._set_), _iter_(from._iter_) {
498 template <
typename GUM_SCALAR >
503 template <
typename GUM_SCALAR >
510 template <
typename GUM_SCALAR >
517 template <
typename GUM_SCALAR >
522 template <
typename GUM_SCALAR >
528 template <
typename GUM_SCALAR >
534 template <
typename GUM_SCALAR >
540 template <
typename GUM_SCALAR >
546 template <
typename GUM_SCALAR >
552 template <
typename GUM_SCALAR >
558 template <
typename GUM_SCALAR >
564 template <
typename GUM_SCALAR >
570 template <
typename GUM_SCALAR >
571 INLINE std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
576 template <
typename GUM_SCALAR >
577 INLINE
const std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
582 template <
typename GUM_SCALAR >
587 template <
typename GUM_SCALAR >
589 const auto& type_attr
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.
virtual PRMType & type()
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 const Tensor< GUM_SCALAR > & cpf() const =0
See gum::PRMClassElement::cpf().
virtual void copyCpf(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bif, const PRMAttribute< GUM_SCALAR > &source)=0
See gum::PRMClassElement::elt_type().
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)=0
See gum::PRMClassElement::addParent_().
virtual PRMType & type()=0
See gum::PRMClassElement::type().
Abstract class representing an element of PRM class.
virtual void setId(NodeId id)
Used to assign the id of this element.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
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=(const RefConstIterator &from)
const PRMInstance< GUM_SCALAR > & operator*() const
bool operator==(const RefConstIterator &from) const
RefConstIterator(const Set< PRMInstance< GUM_SCALAR > * > &set)
Set< PRMInstance< GUM_SCALAR > * >::const_iterator _iter_
RefConstIterator & operator++()
Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations.
PRMInstance< GUM_SCALAR > & operator*() const
RefIterator(Set< PRMInstance< GUM_SCALAR > * > &set)
RefIterator & operator=(const RefIterator &from)
Set< PRMInstance< GUM_SCALAR > * >::iterator _iter_
Set< PRMInstance< GUM_SCALAR > * > & _set_
bool operator==(const RefIterator &from) const
RefIterator & operator++()
bool operator!=(const RefIterator &from) const
PRMInstance< GUM_SCALAR > * operator->() 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...
void instantiate()
Instantiate all nodes which requires it.
const iterator & end()
Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in...
void _copyAttributeCPF_(PRMAttribute< double > *attr)
typename NodeProperty< PRMAttribute< GUM_SCALAR > * >::const_iterator const_iterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
NodeProperty< Set< PRMInstance< GUM_SCALAR > * > * > _referenceMap_
Mapping between the gum::prm::PRMReferenceSlot and gum::prm::PRMSlotChain<GUM_SCALAR> in type / and t...
PRMInstance< GUM_SCALAR > & operator=(const PRMClass< GUM_SCALAR > &from)
Copy operator. Don't use it.
virtual prm_type obj_type() const
Returns the PRM type of this object.
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...
InvRefIterator beginInvRef()
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
bool _instantiated_
True if this instance has been instantiated.
Bijection< const DiscreteVariable *, const DiscreteVariable * > _bijection_
A bijection used for MultiDim handling.
const InvRefIterator & endInvRef()
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
bool exists(NodeId id) const
Returns true if id matches an PRMAttribute<GUM_SCALAR> in this 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.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
PRMClass< GUM_SCALAR > * _type_
The type of this PRMInstance<GUM_SCALAR>.
const Set< PRMInstance< double > * > & getInstances(NodeId id) const
void _copyAttribute_(PRMAttribute< GUM_SCALAR > *source)
Used at construction to instantiate attributes.
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>.
typename NodeProperty< PRMAttribute< GUM_SCALAR > * >::iterator iterator
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
void _addReferingInstance_(PRMSlotChain< GUM_SCALAR > *sc, PRMInstance< GUM_SCALAR > *i)
Add this as a referring instance over the attribute pointed by sc in i.
bool hasRefAttr(NodeId id) const
Returns true if id has at least one referring PRMAttribute<GUM_SCALAR>.
PRMInstance(const std::string &name, PRMClass< GUM_SCALAR > &type)
Default constructor of an PRMInstance<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>.
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
const PRMInstance< GUM_SCALAR > & getInstance(NodeId id) const
Fast access to the first instance in a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.
iterator begin()
Returns an iterator at the begining of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInst...
virtual ~PRMInstance()
Destructor.
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.
Size size() const
Returns the number of attributes in this PRMInstance<GUM_SCALAR>.
void _copyAggregates_(PRMAggregate< GUM_SCALAR > *source)
Used at construction to instantiate aggregates.
void _doInstantiate_()
Starts this instance instantiations.
const std::string & name() const
Returns the name of this object.
prm_type
Enumeration of the different types of objects handled by a PRM.
PRMObject(const std::string &name)
Constructor.
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).
<agrum/PRM/elements/scalarAttribute.h>
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
Sequence< PRMClassElement< GUM_SCALAR > * > & chain()
Return the sequence representing the chain of elements in this PRMSlotChain.
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
virtual PRMType & type()
This is similar to the following call: this->lastElt().type().
bool isMultiple() const
Return true if this slot chain contains at least one multiple reference slot.
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