36 template <
typename GUM_SCALAR >
41 template <
typename GUM_SCALAR >
45 for (
const auto& elt : *
this)
48 for (
const auto& elt : __instanceMap)
51 for (
const auto& elt : __arrayMap)
52 delete elt.second.second;
55 template <
typename GUM_SCALAR >
57 if (__nameMap.exists(i->
name())) {
60 "an Instance<GUM_SCALAR> with the same is already in this System");
63 NodeId id = __skeleton.addNode();
64 __nodeIdMap.insert(
id, i);
65 __nameMap.insert(i->
name(), i);
68 __instanceMap[&(i->
type())]->insert(i);
70 __instanceMap.insert(&(i->
type()),
72 __instanceMap[&(i->
type())]->insert(i);
78 template <
typename GUM_SCALAR >
88 __groundAttr(*(iter.val()), factory);
94 __groundRef(*(iter.val()), factory);
98 template <
typename GUM_SCALAR >
102 for (
const auto node : instance.
type().containerDag()) {
107 switch (instance.
type().get(node).elt_type()) {
110 std::stringstream elt_name;
111 elt_name << instance.
name() <<
"." 112 << instance.
type().get(node).safeName();
121 std::stringstream elt_name;
122 elt_name << instance.
name() <<
"." 123 << instance.
type().get(node).safeName();
124 __groundAgg(instance.
type().get(node), elt_name.str(), factory);
135 template <
typename GUM_SCALAR >
138 const std::string& name,
214 template <
typename GUM_SCALAR >
218 for (
const auto& elt : instance) {
219 std::stringstream elt_name;
220 elt_name << instance.
name() <<
"." << elt.second->safeName();
223 for (
const auto par :
224 instance.type().containerDag().parents(elt.second->id())) {
225 switch (instance.type().get(par).elt_type()) {
228 std::stringstream parent_name;
229 parent_name << instance.
name() <<
"." 230 << instance.get(par).safeName();
236 std::string parent_name =
238 instance.type().get(par))
242 for (
const auto ref : instance.getInstances(par)) {
243 std::stringstream sBuff;
244 sBuff << ref->name() <<
"." << parent_name;
263 instance.type().get(elt.second->safeName())))
264 __groundPotential(instance, *elt.second, factory);
268 template <
typename GUM_SCALAR >
274 std::stringstream var_name;
277 &(factory.
variable(var_name.str())));
279 for (
const auto parent : instance.
type().containerDag().parents(attr.
id())) {
280 switch (instance.
type().get(parent).elt_type()) {
283 std::stringstream parent_name;
284 parent_name << instance.
name() <<
"." 285 << instance.
get(parent).safeName();
286 bijection.
insert(&(instance.
get(parent).type().variable()),
287 &(factory.
variable(parent_name.str())));
292 std::stringstream parent_name;
295 instance.
type().get(parent));
302 &(factory.
variable(parent_name.str())));
308 "invalid ClassElement<GUM_SCALAR> type as parent.");
318 for (
auto var : attr.
cpf().variablesSequence()) {
322 for (inst.
setFirst(), jnst.setFirst(); !(inst.
end() || jnst.end());
323 inst.
inc(), jnst.inc()) {
324 p->
set(jnst, attr.
cpf().get(inst));
326 GUM_ASSERT(inst.
end() && jnst.end());
330 template <
typename GUM_SCALAR >
333 return add(array, &i);
336 template <
typename GUM_SCALAR >
341 template <
typename GUM_SCALAR >
344 return *(__nodeIdMap[id]);
350 template <
typename GUM_SCALAR >
354 return *(__nodeIdMap[id]);
360 template <
typename GUM_SCALAR >
370 template <
typename GUM_SCALAR >
372 return PRMObject::prm_type::SYSTEM;
375 template <
typename GUM_SCALAR >
377 return __nodeIdMap.
size();
380 template <
typename GUM_SCALAR >
386 template <
typename GUM_SCALAR >
389 return __nameMap.
exists(name);
392 template <
typename GUM_SCALAR >
394 return __arrayMap.
exists(name);
397 template <
typename GUM_SCALAR >
399 for (
auto iter = begin(); iter != end(); ++iter) {
404 template <
typename GUM_SCALAR >
408 return *(__nameMap[name]);
411 "found no Instance<GUM_SCALAR> matching the given name");
415 template <
typename GUM_SCALAR >
419 return *(__nameMap[name]);
422 "found no Instance<GUM_SCALAR> matching the given name");
426 template <
typename GUM_SCALAR >
434 "the given Class<GUM_SCALAR> has no instantiation in this System");
438 template <
typename GUM_SCALAR >
442 return *(__arrayMap[name].second);
448 template <
typename GUM_SCALAR >
452 return *(__arrayMap[name].first);
458 template <
typename GUM_SCALAR >
462 return *(__arrayMap[name].first);
468 template <
typename GUM_SCALAR >
472 if (i->
type().isSubTypeOf(*(__arrayMap[array].first))) {
474 __arrayMap[array].second->insert(i);
478 "the given Instance<GUM_SCALAR> is of an incorrect " 479 "Class<GUM_SCALAR> type");
486 template <
typename GUM_SCALAR >
489 if (__arrayMap.exists(array)) {
491 "an array '" << array <<
"' is already in this System");
494 __arrayMap.insert(array,
499 template <
typename GUM_SCALAR >
502 return __nodeIdMap.
begin();
505 template <
typename GUM_SCALAR >
508 return __nodeIdMap.
end();
511 template <
typename GUM_SCALAR >
514 return __nodeIdMap.
begin();
517 template <
typename GUM_SCALAR >
520 return __nodeIdMap.
end();
523 template <
typename GUM_SCALAR >
527 return __arrayMap[a].second->
begin();
533 template <
typename GUM_SCALAR >
537 return __arrayMap[a].second->
end();
543 template <
typename GUM_SCALAR >
547 return __arrayMap[a].second->
begin();
553 template <
typename GUM_SCALAR >
557 return __arrayMap[a].second->
end();
563 template <
typename GUM_SCALAR >
565 return __nameMap.
exists(name) || __arrayMap.exists(name);
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
aGrUM's Potential is a multi-dimensional array with tensor operators.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
void setName(const std::string &theValue)
sets the name of the variable
const PRMInstance< GUM_SCALAR > & getInstance(NodeId id) const
Fast access to the first instance in a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.
void variableName(const std::string &name) final
Tells the factory the current variable's name.
Unsafe Const Iterators for hashtablesHashTableConstIterator provides a fast but unsafe way to parse H...
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
void setVariableCPTImplementation(MultiDimAdressable *adressable) final
Defines the implementation to use for var's Potential.
const std::string & name() const
Returns the name of this object.
iterator begin()
Returns an iterator over the instances in this system.
void addParent(const std::string &var) final
Tells the factory for which variable we're declaring parents.
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 setVariable(const DiscreteVariable &var) final
Define a variable.
Unsafe Iterators for hashtablesHashTableIterator provides a fast but unsafe way to parse HashTables...
The generic class for storing (ordered) sequences of objects.
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
void addNetworkProperty(const std::string &propName, const std::string &propValue) final
Tells the factory to add a property to the current network.
void startParentsDeclaration(const std::string &var) final
Tells the factory that we're declaring parents for some variable.
Abstract class representing an element of PRM class.
void endParentsDeclaration() final
Tells the factory that we've finished declaring parents for some variable.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
PRMSystem(const std::string &name)
Default constructor.
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.
virtual Size domainSize() const =0
prm_type
Enumeration of the different types of objects handled by a PRM.
void inc()
Operator increment.
void startNetworkDeclaration() final
Tells the factory that we're in a network declaration.
virtual std::string label(Idx i) const =0
get the indice-th label. This method is pure virtual.
AggregateType agg_type() const
Returns the aggregate of *this.
virtual const Potential< GUM_SCALAR > & cpf() const =0
See gum::PRMClassElement::cpf().
void startVariableDeclaration() final
Tells the factory that we're in a variable declaration.
Base class for all oriented graphs.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Sequence< PRMInstance< GUM_SCALAR > *>::iterator array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
Set of pairs of elements with fast search for both elements.
NodeId endVariableDeclaration() final
Tells the factory that we're out of a variable declaration.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
std::pair< PRMClassElementContainer< GUM_SCALAR > *, Sequence< PRMInstance< GUM_SCALAR > *> *> model_pair
Typedef of the pair of a Class<GUM_SCALAR> and the sequence of it's instantiation.
Abstract base class for any element defined in a PRM.
Class for assigning/browsing values to tuples of discrete variables.
void setVariableCPT(const std::string &varName, MultiDimAdressable *table, bool redefineParents) final
Define a variable's CPT.
virtual void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
Sequence< PRMInstance< GUM_SCALAR > *>::const_iterator const_array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
<agrum/PRM/classElementContainer.h>
NodeId id() const
Returns the NodeId of this element in it's class DAG.
bool exists(const std::string &name) const
Retruns true either if name is an instance or an array in this PRMSystem.
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
Size size() const
Returns the number of PRMInstance in this PRMSystem.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const final
Default implementation of MultiDimContainer::set().
void setFirst()
Assign the first values to the tuple of the Instantiation.
Size Idx
Type for indexes.
void endNetworkDeclaration() final
Tells the factory that we're out of a network declaration.
const DiscreteVariable & variable(const std::string &name) const
Returns a constant reference on a variable given it's name.
void addModality(const std::string &name) final
Adds a modality to the current variable.
PRMAttribute is a member of a Class in a PRM.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
const iterator & end()
Returns a iterator at the end of the set of PRMInstance in this PRMSystem.
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
Idx label() const
Returns the label's index on which this aggregate applies.
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)
A factory class to ease BayesNet construction.
bool end() const
Returns true if the Instantiation reached the end.