33 template <
typename GUM_SCALAR >
37 __instantiated(false), __type(&type) {
41 for (
const auto agg :
__type->aggregates())
46 for (
const auto attr :
__type->attributes())
50 template <
typename GUM_SCALAR >
64 template <
typename GUM_SCALAR >
72 template <
typename GUM_SCALAR >
75 for (
const auto chain :
type().slotChains()) {
81 for (
const auto attr :
type().attributes()) {
86 for (
const auto agg :
type().aggregates()) {
89 for (
const auto node :
type().containerDag().parents(agg->id())) {
93 auto elt = &(
type().get(node));
97 for (
const auto inst : instances) {
98 attr.
addParent(inst->get(sc->lastElt().safeName()));
105 template <
typename GUM_SCALAR >
108 auto first_id = sc->
chain()[0]->id();
112 for (
Size idx = 1; idx < sc->
chain().size() - 1; ++idx) {
114 for (
auto current : *
set) {
115 auto& ref = current->type().get(sc->
chain()[idx]->name());
116 for (
auto next : *(current->__referenceMap[ref.id()])) {
124 GUM_ASSERT(set->size() > 0);
134 for (
auto i : *
set) {
142 for (
auto instance : *
set) {
143 auto& attr = instance->get(sc->
lastElt().safeName());
144 __bijection.insert(&(sc->
type().variable()), &(attr.type().variable()));
149 template <
typename GUM_SCALAR >
155 elt = &(
type().get(
id));
168 "given Instance type is not a proper " 169 "subclass of the ReferenceSlot<GUM_SCALAR> slot type");
178 "ReferenceSlot<GUM_SCALAR> size limit reached");
189 if (!instance.
type().isSubTypeOf(sc.
end())) {
191 "given Instance type is not a proper " 192 "subclass of the ClassElementContainer pointed" 193 " by the SlotChain<GUM_SCALAR>");
208 if (!
type().isOutputNode(*elt)) {
210 "given ClassElement<GUM_SCALAR> is not an output node");
222 template <
typename GUM_SCALAR >
227 template <
typename GUM_SCALAR >
232 GUM_ASSERT(&(attr->type().variable()) != &(source->
type().variable()));
233 attr->setId(source->
id());
235 __bijection.insert(&(source->
type().variable()), &(attr->type().variable()));
238 template <
typename GUM_SCALAR >
243 GUM_ASSERT(&(attr->type().variable()) != &(source->
type().variable()));
245 attr->cpf().fill((GUM_SCALAR)0);
246 attr->setId(source->
id());
247 __bijection.insert(&(source->
type().variable()), &(attr->type().variable()));
251 template <
typename GUM_SCALAR >
260 template <
typename GUM_SCALAR >
266 template <
typename GUM_SCALAR >
271 template <
typename GUM_SCALAR >
276 template <
typename GUM_SCALAR >
281 template <
typename GUM_SCALAR >
286 template <
typename GUM_SCALAR >
291 template <
typename GUM_SCALAR >
300 template <
typename GUM_SCALAR >
310 template <
typename GUM_SCALAR >
320 template <
typename GUM_SCALAR >
330 template <
typename GUM_SCALAR >
339 std::make_pair(
this, sc->
lastElt().safeName()));
345 std::make_pair(
this, sc->
lastElt().safeName()));
349 template <
typename GUM_SCALAR >
355 template <
typename GUM_SCALAR >
363 "no Instance associated with the given NodeId");
367 "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> " 368 "matches the given NodeId");
372 template <
typename GUM_SCALAR >
379 "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> " 380 "matches the given NodeId");
384 template <
typename GUM_SCALAR >
390 template <
typename GUM_SCALAR >
396 template <
typename GUM_SCALAR >
402 template <
typename GUM_SCALAR >
408 template <
typename GUM_SCALAR >
418 template <
typename GUM_SCALAR >
428 template <
typename GUM_SCALAR >
432 __iter(set.
begin()) {
436 template <
typename GUM_SCALAR >
444 template <
typename GUM_SCALAR >
449 template <
typename GUM_SCALAR >
456 template <
typename GUM_SCALAR >
463 template <
typename GUM_SCALAR >
468 template <
typename GUM_SCALAR >
474 template <
typename GUM_SCALAR >
480 template <
typename GUM_SCALAR >
486 template <
typename GUM_SCALAR >
492 template <
typename GUM_SCALAR >
500 template <
typename GUM_SCALAR >
508 template <
typename GUM_SCALAR >
513 template <
typename GUM_SCALAR >
521 template <
typename GUM_SCALAR >
528 template <
typename GUM_SCALAR >
533 template <
typename GUM_SCALAR >
539 template <
typename GUM_SCALAR >
545 template <
typename GUM_SCALAR >
551 template <
typename GUM_SCALAR >
557 template <
typename GUM_SCALAR >
563 template <
typename GUM_SCALAR >
569 template <
typename GUM_SCALAR >
575 template <
typename GUM_SCALAR >
581 template <
typename GUM_SCALAR >
582 INLINE std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
587 template <
typename GUM_SCALAR >
589 std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
594 template <
typename GUM_SCALAR >
599 template <
typename GUM_SCALAR >
605 GUM_ASSERT(attr->
cpf().contains(attr->
type().variable()));
const PRMInstance< GUM_SCALAR > & operator*() const
PRMClass< GUM_SCALAR > * __type
The type 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>.
RefConstIterator(const Set< PRMInstance< GUM_SCALAR > * > &set)
Unsafe Const Iterators for hashtablesHashTableConstIterator provides a fast but unsafe way to parse H...
Set< PRMInstance< GUM_SCALAR > *>::const_iterator __iter
virtual ~PRMInstance()
Destructor.
MultiDimImplementation< GUM_SCALAR > * buildImpl() const
Returns a pointer over an empty gum::MultiDimImplementation of the good type for this PRMAggregate...
void add(NodeId id, PRMInstance< GUM_SCALAR > &instance)
Add an PRMInstance<GUM_SCALAR> to a given PRMReferenceSlot, PRMSlotChain<GUM_SCALAR> or output node...
PRMInstance(const std::string &name, PRMClass< GUM_SCALAR > &type)
Default constructor of an PRMInstance<GUM_SCALAR>.
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)=0
See gum::PRMClassElement::_addParent().
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
const std::string & name() const
Returns the name of this object.
virtual PRMType & type()=0
See gum::PRMClassElement::type().
An PRMInstance is a Bayesian Network fragment defined by a Class and used in a PRMSystem.
void instantiate()
Instantiate all nodes which requires it.
bool operator==(const RefIterator &from) const
void __addReferingInstance(PRMSlotChain< GUM_SCALAR > *sc, PRMInstance< GUM_SCALAR > *i)
Add this as a referring instance over the attribute pointed by sc in i.
Unsafe Iterators for hashtablesHashTableIterator provides a fast but unsafe way to parse HashTables...
Headers of MultiDimSparse.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
Bijection< const DiscreteVariable *, const DiscreteVariable *> __bijection
A bijection used for MultiDim handling.
PRMInstance< GUM_SCALAR > * operator->() const
Abstract class representing an element of PRM class.
NodeProperty< std::vector< pair > *> __referingAttr
The set of pair (instance, attribute) referring an attribute of this instance.
bool exists(NodeId id) const
Returns true if id matches an PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
RefIterator & operator++()
void __doInstantiate()
Starts this instance instantiations.
virtual PRMType & type()
This is similar to the following call: this->lastElt().type()
gum is the global namespace for all aGrUM entities
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)...
bool __instantiated
True if this instance has been instantiated.
Size size() const
Returns the number of attributes 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...
RefIterator(Set< PRMInstance< GUM_SCALAR > * > &set)
Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations.
void __copyAttributeCPF(PRMAttribute< GUM_SCALAR > *attr)
Copy the content of an PRMAttribute<GUM_SCALAR> from its Class<GUM_SCALAR> counterpart.
void __instantiateSlotChain(PRMSlotChain< GUM_SCALAR > *sc)
Retrieve all instances referred by sc.
InvRefIterator beginInvRef()
Alias to iterate over the gum::prm::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.
Representation of a setA Set is a structure that contains arbitrary elements.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
PRMInstance< GUM_SCALAR > & operator*() const
RefConstIterator & operator++()
void __copyAttribute(PRMAttribute< GUM_SCALAR > *source)
Used at construction to instantiate attributes.
prm_type
Enumeration of the different types of objects handled by a PRM.
bool operator==(const RefConstIterator &from) const
bool isMultiple() const
Return true if this slot chain contains at least one multiple reference slot.
void __copyAggregates(PRMAggregate< GUM_SCALAR > *source)
Used at construction to instantiate aggregates.
virtual const Potential< GUM_SCALAR > & cpf() const =0
See gum::PRMClassElement::cpf().
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...
Set< PRMInstance< GUM_SCALAR > *> & __set
PRMInstance< GUM_SCALAR > & operator=(const PRMClass< GUM_SCALAR > &from)
Copy operator. Don't use it.
PRMClassElementContainer< GUM_SCALAR > & end()
Returns the PRMClassElement<GUM_SCALAR>Container over which this slot chain ends. ...
Set of pairs of elements with fast search for both elements.
virtual prm_type obj_type() const
Returns the PRM type of this object.
virtual ClassElementType elt_type() const =0
Return the type of class element this object is.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
Abstract base class for any element defined in a PRM.
bool operator!=(const RefConstIterator &from) const
virtual PRMType & type()
See gum::PRMClassElement::type().
Set< PRMInstance< GUM_SCALAR > *>::iterator __iter
NodeId id() const
Returns the NodeId of this element in it's class DAG.
const iterator & end()
Returns a reference over the iterator at the end of the list of gum::prm::PRMAttribute<GUM_SCALAR> in...
Headers of gum::prm::PRMInstance<GUM_SCALAR>
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
bool hasRefAttr(NodeId id) const
Returns true if id has at least one referring PRMAttribute<GUM_SCALAR>.
const PRMInstance< GUM_SCALAR > * operator->() const
RefConstIterator & operator=(const RefConstIterator &from)
virtual void copyCpf(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bif, const PRMAttribute< GUM_SCALAR > &source)=0
See gum::PRMClassElement::elt_type().
PRMAttribute is a member of a Class in a PRM.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
RefIterator & operator=(const RefIterator &from)
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
iterator begin()
Returns an iterator at the begining of the list of gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInst...
Nested class to iterate over PRMReferenceSlot and PRMSlotChain<GUM_SCALAR> instantiations.
const InvRefIterator & endInvRef()
Alias to iterate over the gum::prm::PRMAttribute<GUM_SCALAR> in this PRMInstance<GUM_SCALAR>.
<agrum/PRM/elements/scalarAttribute.h>
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
bool operator!=(const RefIterator &from) const
#define GUM_ERROR(type, msg)
NodeProperty< PRMAttribute< GUM_SCALAR > *> __nodeIdMap
The gum::prm::PRMAttribute<GUM_SCALAR> and gum::prm::PRMAggregate<GUM_SCALAR> of this PRMInstance<GUM...
Sequence< PRMClassElement< GUM_SCALAR > *> & chain()
Return the sequence representing the chain of elements in this PRMSlotChain.
const Set< PRMInstance< GUM_SCALAR > *> & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
const Set< PRMInstance< GUM_SCALAR > *> & __set