39 template <
typename GUM_SCALAR >
44 template <
typename GUM_SCALAR >
48 for (
const auto& elt : *
this)
51 for (
const auto& elt : __instanceMap)
54 for (
const auto& elt : __arrayMap)
55 delete elt.second.second;
58 template <
typename GUM_SCALAR >
60 if (__nameMap.exists(i->
name())) {
63 "an Instance<GUM_SCALAR> with the same is already in this System");
66 NodeId id = __skeleton.addNode();
67 __nodeIdMap.insert(
id, i);
68 __nameMap.insert(i->
name(), i);
71 __instanceMap[&(i->
type())]->insert(i);
73 __instanceMap.insert(&(i->
type()),
75 __instanceMap[&(i->
type())]->insert(i);
81 template <
typename GUM_SCALAR >
91 __groundAttr(*(iter.val()), factory);
97 __groundRef(*(iter.val()), factory);
101 template <
typename GUM_SCALAR >
105 for (
const auto node : instance.
type().containerDag()) {
110 switch (instance.
type().get(node).elt_type()) {
113 std::stringstream elt_name;
114 elt_name << instance.
name() <<
"." 115 << instance.
type().get(node).safeName();
124 std::stringstream elt_name;
125 elt_name << instance.
name() <<
"." 126 << instance.
type().get(node).safeName();
127 __groundAgg(instance.
type().get(node), elt_name.str(), factory);
138 template <
typename GUM_SCALAR >
141 const std::string& name,
217 template <
typename GUM_SCALAR >
221 for (
const auto& elt : instance) {
222 std::stringstream elt_name;
223 elt_name << instance.
name() <<
"." << elt.second->safeName();
226 for (
const auto par :
227 instance.type().containerDag().parents(elt.second->id())) {
228 switch (instance.type().get(par).elt_type()) {
231 std::stringstream parent_name;
232 parent_name << instance.
name() <<
"." 233 << instance.get(par).safeName();
239 std::string parent_name =
241 instance.type().get(par))
245 for (
const auto ref : instance.getInstances(par)) {
246 std::stringstream sBuff;
247 sBuff << ref->name() <<
"." << parent_name;
266 instance.type().get(elt.second->safeName())))
267 __groundPotential(instance, *elt.second, factory);
271 template <
typename GUM_SCALAR >
277 std::stringstream var_name;
280 &(factory.
variable(var_name.str())));
282 for (
const auto parent : instance.
type().containerDag().parents(attr.
id())) {
283 switch (instance.
type().get(parent).elt_type()) {
286 std::stringstream parent_name;
287 parent_name << instance.
name() <<
"." 288 << instance.
get(parent).safeName();
289 bijection.
insert(&(instance.
get(parent).type().variable()),
290 &(factory.
variable(parent_name.str())));
295 std::stringstream parent_name;
298 instance.
type().get(parent));
305 &(factory.
variable(parent_name.str())));
311 "invalid ClassElement<GUM_SCALAR> type as parent.");
321 for (
auto var : attr.
cpf().variablesSequence()) {
325 for (inst.
setFirst(), jnst.setFirst(); !(inst.
end() || jnst.end());
326 inst.
inc(), jnst.inc()) {
327 p->
set(jnst, attr.
cpf().get(inst));
329 GUM_ASSERT(inst.
end() && jnst.end());
333 template <
typename GUM_SCALAR >
336 return add(array, &i);
339 template <
typename GUM_SCALAR >
344 template <
typename GUM_SCALAR >
347 return *(__nodeIdMap[id]);
353 template <
typename GUM_SCALAR >
357 return *(__nodeIdMap[id]);
363 template <
typename GUM_SCALAR >
373 template <
typename GUM_SCALAR >
375 return PRMObject::prm_type::SYSTEM;
378 template <
typename GUM_SCALAR >
380 return __nodeIdMap.
size();
383 template <
typename GUM_SCALAR >
389 template <
typename GUM_SCALAR >
392 return __nameMap.
exists(name);
395 template <
typename GUM_SCALAR >
397 return __arrayMap.
exists(name);
400 template <
typename GUM_SCALAR >
402 for (
auto iter = begin(); iter != end(); ++iter) {
407 template <
typename GUM_SCALAR >
411 return *(__nameMap[name]);
414 "found no Instance<GUM_SCALAR> matching the given name");
418 template <
typename GUM_SCALAR >
422 return *(__nameMap[name]);
425 "found no Instance<GUM_SCALAR> matching the given name");
429 template <
typename GUM_SCALAR >
437 "the given Class<GUM_SCALAR> has no instantiation in this System");
441 template <
typename GUM_SCALAR >
445 return *(__arrayMap[name].second);
451 template <
typename GUM_SCALAR >
455 return *(__arrayMap[name].first);
461 template <
typename GUM_SCALAR >
465 return *(__arrayMap[name].first);
471 template <
typename GUM_SCALAR >
475 if (i->
type().isSubTypeOf(*(__arrayMap[array].first))) {
477 __arrayMap[array].second->insert(i);
481 "the given Instance<GUM_SCALAR> is of an incorrect " 482 "Class<GUM_SCALAR> type");
489 template <
typename GUM_SCALAR >
492 if (__arrayMap.exists(array)) {
494 "an array '" << array <<
"' is already in this System");
497 __arrayMap.insert(array,
502 template <
typename GUM_SCALAR >
505 return __nodeIdMap.
begin();
508 template <
typename GUM_SCALAR >
511 return __nodeIdMap.
end();
514 template <
typename GUM_SCALAR >
517 return __nodeIdMap.
begin();
520 template <
typename GUM_SCALAR >
523 return __nodeIdMap.
end();
526 template <
typename GUM_SCALAR >
530 return __arrayMap[a].second->
begin();
536 template <
typename GUM_SCALAR >
540 return __arrayMap[a].second->
end();
546 template <
typename GUM_SCALAR >
550 return __arrayMap[a].second->
begin();
556 template <
typename GUM_SCALAR >
560 return __arrayMap[a].second->
end();
566 template <
typename GUM_SCALAR >
568 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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Base class for all oriented graphs.
A PRMSystem is a container of PRMInstance and describe a relational skeleton.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.