36 template <
typename GUM_SCALAR >
40 __instantiated(false), __type(&type) {
44 for (
const auto agg :
__type->aggregates())
49 for (
const auto attr :
__type->attributes())
53 template <
typename GUM_SCALAR >
67 template <
typename GUM_SCALAR >
75 template <
typename GUM_SCALAR >
78 for (
const auto chain :
type().slotChains()) {
84 for (
const auto attr :
type().attributes()) {
89 for (
const auto agg :
type().aggregates()) {
92 for (
const auto node :
type().containerDag().parents(agg->id())) {
96 auto elt = &(
type().get(node));
100 for (
const auto inst : instances) {
101 attr.
addParent(inst->get(sc->lastElt().safeName()));
108 template <
typename GUM_SCALAR >
111 auto first_id = sc->
chain()[0]->id();
115 for (
Size idx = 1; idx < sc->
chain().size() - 1; ++idx) {
117 for (
auto current : *
set) {
118 auto& ref = current->type().get(sc->
chain()[idx]->name());
119 for (
auto next : *(current->__referenceMap[ref.id()])) {
127 GUM_ASSERT(set->size() > 0);
137 for (
auto i : *
set) {
145 for (
auto instance : *
set) {
146 auto& attr = instance->get(sc->
lastElt().safeName());
147 __bijection.insert(&(sc->
type().variable()), &(attr.type().variable()));
152 template <
typename GUM_SCALAR >
158 elt = &(
type().get(
id));
171 "given Instance type is not a proper " 172 "subclass of the ReferenceSlot<GUM_SCALAR> slot type");
181 "ReferenceSlot<GUM_SCALAR> size limit reached");
192 if (!instance.
type().isSubTypeOf(sc.
end())) {
194 "given Instance type is not a proper " 195 "subclass of the ClassElementContainer pointed" 196 " by the SlotChain<GUM_SCALAR>");
211 if (!
type().isOutputNode(*elt)) {
213 "given ClassElement<GUM_SCALAR> is not an output node");
225 template <
typename GUM_SCALAR >
230 template <
typename GUM_SCALAR >
235 GUM_ASSERT(&(attr->type().variable()) != &(source->
type().variable()));
236 attr->setId(source->
id());
238 __bijection.insert(&(source->
type().variable()), &(attr->type().variable()));
241 template <
typename GUM_SCALAR >
246 GUM_ASSERT(&(attr->type().variable()) != &(source->
type().variable()));
248 attr->cpf().fill((GUM_SCALAR)0);
249 attr->setId(source->
id());
250 __bijection.insert(&(source->
type().variable()), &(attr->type().variable()));
254 template <
typename GUM_SCALAR >
263 template <
typename GUM_SCALAR >
269 template <
typename GUM_SCALAR >
274 template <
typename GUM_SCALAR >
279 template <
typename GUM_SCALAR >
284 template <
typename GUM_SCALAR >
289 template <
typename GUM_SCALAR >
294 template <
typename GUM_SCALAR >
303 template <
typename GUM_SCALAR >
313 template <
typename GUM_SCALAR >
323 template <
typename GUM_SCALAR >
333 template <
typename GUM_SCALAR >
342 std::make_pair(
this, sc->
lastElt().safeName()));
348 std::make_pair(
this, sc->
lastElt().safeName()));
352 template <
typename GUM_SCALAR >
358 template <
typename GUM_SCALAR >
366 "no Instance associated with the given NodeId");
370 "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> " 371 "matches the given NodeId");
375 template <
typename GUM_SCALAR >
382 "no ReferenceSlot<GUM_SCALAR> or SlotChain<GUM_SCALAR> " 383 "matches the given NodeId");
387 template <
typename GUM_SCALAR >
393 template <
typename GUM_SCALAR >
399 template <
typename GUM_SCALAR >
405 template <
typename GUM_SCALAR >
411 template <
typename GUM_SCALAR >
421 template <
typename GUM_SCALAR >
431 template <
typename GUM_SCALAR >
435 __iter(set.
begin()) {
439 template <
typename GUM_SCALAR >
447 template <
typename GUM_SCALAR >
452 template <
typename GUM_SCALAR >
459 template <
typename GUM_SCALAR >
466 template <
typename GUM_SCALAR >
471 template <
typename GUM_SCALAR >
477 template <
typename GUM_SCALAR >
483 template <
typename GUM_SCALAR >
489 template <
typename GUM_SCALAR >
495 template <
typename GUM_SCALAR >
503 template <
typename GUM_SCALAR >
511 template <
typename GUM_SCALAR >
516 template <
typename GUM_SCALAR >
524 template <
typename GUM_SCALAR >
531 template <
typename GUM_SCALAR >
536 template <
typename GUM_SCALAR >
542 template <
typename GUM_SCALAR >
548 template <
typename GUM_SCALAR >
554 template <
typename GUM_SCALAR >
560 template <
typename GUM_SCALAR >
566 template <
typename GUM_SCALAR >
572 template <
typename GUM_SCALAR >
578 template <
typename GUM_SCALAR >
584 template <
typename GUM_SCALAR >
585 INLINE std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
590 template <
typename GUM_SCALAR >
592 std::vector< std::pair< PRMInstance< GUM_SCALAR >*, std::string > >&
597 template <
typename GUM_SCALAR >
602 template <
typename GUM_SCALAR >
608 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...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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()
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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