aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
PRMSystem_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
56
57namespace gum {
58 namespace prm {
59 template < typename GUM_SCALAR >
61 GUM_CONSTRUCTOR(PRMSystem);
62 }
63
64 template < typename GUM_SCALAR >
66 GUM_DESTRUCTOR(PRMSystem);
67
68 for (const auto& elt: *this)
69 delete elt.second;
70
71 for (const auto& elt: instanceMap_)
72 delete elt.second;
73
74 for (const auto& elt: arrayMap_)
75 delete elt.second.second;
76 }
77
78 template < typename GUM_SCALAR >
82 GUM_CONS_CPY(PRMSystem);
83 }
84
85 template < typename GUM_SCALAR >
87 if (nameMap_.exists(i->name())) {
89 "an Instance<GUM_SCALAR> with the same is already in this System");
90 }
91
92 NodeId id = skeleton_.addNode();
93 nodeIdMap_.insert(id, i);
94 nameMap_.insert(i->name(), i);
95
96 try {
97 instanceMap_[&(i->type())]->insert(i);
98 } catch (NotFound const&) {
99 instanceMap_.insert(&(i->type()), new Set< PRMInstance< GUM_SCALAR >* >());
100 instanceMap_[&(i->type())]->insert(i);
101 }
102
103 return id;
104 }
105
106 template < typename GUM_SCALAR >
108 factory.startNetworkDeclaration();
109 factory.addNetworkProperty("name", name());
110 factory.endNetworkDeclaration();
111
112 // Adding nodes
113 for (PRMSystem< GUM_SCALAR >::const_iterator iter = begin(); iter != end(); ++iter) {
114 _groundAttr_(*(iter.val()), factory);
116
117 // Adding arcs and filling CPTs
118 for (PRMSystem< GUM_SCALAR >::const_iterator iter = begin(); iter != end(); ++iter) {
119 _groundRef_(*(iter.val()), factory);
120 }
121 }
123 template < typename GUM_SCALAR >
125 BayesNetFactory< GUM_SCALAR >& factory) const {
126 for (const auto node: instance.type().containerDag()) {
127 // Working a Class<GUM_SCALAR> level because PRMAggregate<GUM_SCALAR>
128 // are
129 // instantiated as PRMAttribute<GUM_SCALAR> in an
130 // PRMInstance<GUM_SCALAR>
131 switch (instance.type().get(node).elt_type()) {
133 // TODO: make a special case for noisy-or
134 std::stringstream elt_name;
135 elt_name << instance.name() << "." << instance.type().get(node).safeName();
136 DiscreteVariable* var = instance.get(node).type().variable().clone();
137 var->setName(elt_name.str());
138 factory.setVariable(*var); // var is copied by the factory
139 delete var;
140 break;
141 }
144 std::stringstream elt_name;
145 elt_name << instance.name() << "." << instance.type().get(node).safeName();
146 _groundAgg_(instance.type().get(node), elt_name.str(), factory);
147 break;
148 }
149
150 default :
151 break;
152 /* Do nothing */
153 ;
154 }
155 }
156 }
157
158 template < typename GUM_SCALAR >
160 const std::string& name,
161 BayesNetFactory< GUM_SCALAR >& factory) const {
162 factory.startVariableDeclaration();
163 factory.variableName(name);
164
165 const DiscreteVariable& agg_var = elt.type().variable();
166
167 VarType var_type = agg_var.varType();
168
169 factory.variableType(var_type);
170
171 switch (var_type) {
172 case VarType::LABELIZED : {
173 const auto l = static_cast< const LabelizedVariable& >(agg_var);
174 for (Idx i = 0; i < l.domainSize(); ++i) {
175 factory.addModality(l.label(i));
176 }
177 break;
178 }
180 const auto l = static_cast< const IntegerVariable& >(agg_var);
181 for (Idx i = 0; i < l.domainSize(); ++i) {
182 factory.addModality(l.label(i));
183 }
184 break;
185 }
186 case VarType::NUMERICAL : {
187 const auto l = static_cast< const NumericalDiscreteVariable& >(agg_var);
188 for (Idx i = 0; i < l.domainSize(); ++i) {
189 factory.addModality(l.label(i));
190 }
191 break;
192 }
193 case VarType::DISCRETIZED : {
194 const auto d = static_cast< const DiscretizedVariable< double >& >(agg_var);
195 for (Idx i = 0; i < d.domainSize(); ++i) {
196 factory.addTick(d.tick(i));
197 }
198 break;
199 }
200 case VarType::RANGE : {
201 const auto r = static_cast< const RangeVariable& >(agg_var);
202 factory.addMin(r.minVal());
203 factory.addMax(r.maxVal());
204 break;
206 case VarType::CONTINUOUS : {
208 "PRM aggregator grounding does not support yet continuous variables");
209 }
210 }
211
212 switch (auto& agg = static_cast< const PRMAggregate< GUM_SCALAR >& >(elt); agg.agg_type()) {
214 factory.setVariableCPTImplementation(new aggregator::Min< GUM_SCALAR >());
215 break;
216 }
220 break;
222
225 break;
226 }
227
230 break;
231 }
232
234 factory.setVariableCPTImplementation(new aggregator::Count< GUM_SCALAR >(agg.label()));
235 break;
236 }
237
239 factory.setVariableCPTImplementation(new aggregator::Median< GUM_SCALAR >());
240 break;
241 }
242
244 factory.setVariableCPTImplementation(new aggregator::Amplitude< GUM_SCALAR >());
245 break;
246 }
247
249 factory.setVariableCPTImplementation(new aggregator::Or< GUM_SCALAR >());
250 break;
251 }
252
254 factory.setVariableCPTImplementation(new aggregator::And< GUM_SCALAR >());
255 break;
256 }
257
259 factory.setVariableCPTImplementation(new aggregator::Sum< GUM_SCALAR >());
260 break;
261 }
262
263 default : GUM_ERROR(OperationNotAllowed, "Aggregator not handled yet for " << agg.name())
264 }
265
266 factory.endVariableDeclaration();
267 }
268
269 template < typename GUM_SCALAR >
271 BayesNetFactory< GUM_SCALAR >& factory) const {
272 for (const auto& elt: instance) {
273 std::stringstream elt_name;
274 elt_name << instance.name() << "." << elt.second->safeName();
275 factory.startParentsDeclaration(elt_name.str());
276
277 for (const auto par: instance.type().containerDag().parents(elt.second->id())) {
278 switch (instance.type().get(par).elt_type()) {
281 std::stringstream parent_name;
282 parent_name << instance.name() << "." << instance.get(par).safeName();
283 factory.addParent(parent_name.str());
284 break;
285 }
286
288 std::string parent_name
289 = static_cast< const PRMSlotChain< GUM_SCALAR >& >(instance.type().get(par))
290 .lastElt()
291 .safeName();
292
293 try {
294 for (const auto ref: instance.getInstances(par)) {
295 std::stringstream sBuff;
296 sBuff << ref->name() << "." << parent_name;
297 factory.addParent(sBuff.str());
298 }
299 } catch (NotFound const&) {
300 // No instances for this slotchain
301 }
302
303 break;
304 }
305
306 default :
307 break;
308 /* nothing to do by default */
309 }
310 }
311
312 factory.endParentsDeclaration();
314 // Checking if we need to ground the Tensor (only for class level
315 // attributes since
316 // aggregates Tensors are generated)
317 if (PRMClassElement< GUM_SCALAR >::isAttribute(instance.type().get(elt.second->safeName())))
318 _groundTensor_(instance, *elt.second, factory);
319 }
320 }
321
322 template < typename GUM_SCALAR >
325 BayesNetFactory< GUM_SCALAR >& factory) const {
327 std::stringstream var_name;
328 var_name << instance.name() << "." << attr.safeName();
329 bijection.insert(&(attr.type().variable()), &(factory.variable(var_name.str())));
330
331 for (const auto parent: instance.type().containerDag().parents(attr.id())) {
332 switch (instance.type().get(parent).elt_type()) {
335 std::stringstream parent_name;
336 parent_name << instance.name() << "." << instance.get(parent).safeName();
337 bijection.insert(&(instance.get(parent).type().variable()),
338 &(factory.variable(parent_name.str())));
339 break;
340 }
341
343 std::stringstream parent_name;
345 = static_cast< const PRMSlotChain< GUM_SCALAR >& >(instance.type().get(parent));
346 parent_name << instance.getInstance(sc.id()).name() << "." << sc.lastElt().safeName();
347 bijection.insert(
348 &(instance.getInstance(sc.id()).get(sc.lastElt().safeName()).type().variable()),
349 &(factory.variable(parent_name.str())));
350 break;
351 }
352
353 default : {
354 GUM_ERROR(FatalError, "invalid ClassElement<GUM_SCALAR> type as parent.")
355 break;
356 }
357 }
358 }
359
360 // Copy Tensor
361 // DO NOT USE MultiDimBijArray as they will wreck havok if you delete
362 // the prm befor its grounded BN (happens a lot in pyAgrum)
363 Tensor< GUM_SCALAR >* p = new Tensor< GUM_SCALAR >();
364 for (auto var: attr.cpf().variablesSequence()) {
365 p->add(*(bijection.second(var)));
366 }
367 Instantiation inst(attr.cpf()), jnst(*p);
368 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end()); inst.inc(), jnst.inc()) {
369 p->set(jnst, attr.cpf().get(inst));
370 }
371 GUM_ASSERT(inst.end() && jnst.end());
372 factory.setVariableCPT(var_name.str(), p, false);
373 }
374
375 template < typename GUM_SCALAR >
376 INLINE NodeId PRMSystem< GUM_SCALAR >::add(const std::string& array,
378 return add(array, &i);
379 }
380
381 template < typename GUM_SCALAR >
383 return skeleton_;
384 }
385
386 template < typename GUM_SCALAR >
388 try {
389 return *(nodeIdMap_[id]);
390 } catch (NotFound const&) {
391 GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given id")
392 }
393 }
394
395 template < typename GUM_SCALAR >
397 try {
398 return *(nodeIdMap_[id]);
399 } catch (NotFound const&) {
400 GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given id")
401 }
402 }
403
404 template < typename GUM_SCALAR >
406 try {
407 return nodeIdMap_.keyByVal(const_cast< PRMInstance< GUM_SCALAR >* >(&i));
408 } catch (NotFound const&) {
409 GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given id")
410 }
411 }
412
413 template < typename GUM_SCALAR >
417
418 template < typename GUM_SCALAR >
420 return nodeIdMap_.size();
421 }
422
423 template < typename GUM_SCALAR >
425 return instanceMap_.exists(const_cast< PRMClass< GUM_SCALAR >* >(&c));
426 }
427
428 template < typename GUM_SCALAR >
429 INLINE bool PRMSystem< GUM_SCALAR >::isInstance(const std::string& name) const {
430 return nameMap_.exists(name);
431 }
432
433 template < typename GUM_SCALAR >
434 INLINE bool PRMSystem< GUM_SCALAR >::isArray(const std::string& name) const {
435 return arrayMap_.exists(name);
436 }
437
438 template < typename GUM_SCALAR >
440 for (auto iter = begin(); iter != end(); ++iter) {
441 (*(iter.val())).instantiate();
442 }
443 }
444
445 template < typename GUM_SCALAR >
447 try {
448 return *(nameMap_[name]);
449 } catch (NotFound const&) {
450 GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given name")
451 }
452 }
453
454 template < typename GUM_SCALAR >
455 INLINE const PRMInstance< GUM_SCALAR >&
456 PRMSystem< GUM_SCALAR >::get(const std::string& name) const {
457 try {
458 return *(nameMap_[name]);
459 } catch (NotFound const&) {
460 GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given name")
461 }
462 }
463
464 template < typename GUM_SCALAR >
465 INLINE const Set< PRMInstance< GUM_SCALAR >* >&
466
468 try {
469 return *(instanceMap_[const_cast< PRMClass< GUM_SCALAR >* >(&type)]);
470 } catch (NotFound const&) {
471 GUM_ERROR(NotFound, "the given Class<GUM_SCALAR> has no instantiation in this System");
472 }
473 }
474
475 template < typename GUM_SCALAR >
477
478 PRMSystem< GUM_SCALAR >::getArray(const std::string& name) const {
479 try {
480 return *(arrayMap_[name].second);
481 } catch (NotFound const&) { GUM_ERROR(NotFound, "found no array matching the given name") }
482 }
483
484 template < typename GUM_SCALAR >
487 try {
488 return *(arrayMap_[name].first);
489 } catch (NotFound const&) { GUM_ERROR(NotFound, "found no array matching the given name") }
490 }
491
492 template < typename GUM_SCALAR >
494 PRMSystem< GUM_SCALAR >::getArrayType(const std::string& name) const {
495 try {
496 return *(arrayMap_[name].first);
497 } catch (NotFound const&) { GUM_ERROR(NotFound, "found no array matching the given name") }
498 }
499
500 template < typename GUM_SCALAR >
501 INLINE NodeId PRMSystem< GUM_SCALAR >::add(const std::string& array,
503 try {
504 if (i->type().isSubTypeOf(*(arrayMap_[array].first))) {
505 NodeId id = add(i);
506 arrayMap_[array].second->insert(i);
507 return id;
508 } else {
510 "the given Instance<GUM_SCALAR> is of an incorrect "
511 "Class<GUM_SCALAR> type");
512 }
513 } catch (NotFound const&) { GUM_ERROR(NotFound, "found no array matching the given name") }
514 }
515
516 template < typename GUM_SCALAR >
517 INLINE void PRMSystem< GUM_SCALAR >::addArray(const std::string& array,
519 if (arrayMap_.exists(array)) {
520 GUM_ERROR(DuplicateElement, "an array '" << array << "' is already in this System")
521 }
522
523 arrayMap_.insert(
524 array,
526 }
527
528 template < typename GUM_SCALAR >
532
533 template < typename GUM_SCALAR >
535 return nodeIdMap_.end();
536 }
537
538 template < typename GUM_SCALAR >
540 return nodeIdMap_.begin();
541 }
542
543 template < typename GUM_SCALAR >
544 INLINE const typename PRMSystem< GUM_SCALAR >::const_iterator&
546 return nodeIdMap_.end();
547 }
548
549 template < typename GUM_SCALAR >
551 PRMSystem< GUM_SCALAR >::begin(const std::string& a) {
552 try {
553 return arrayMap_[a].second->begin();
554 } catch (NotFound const&) { GUM_ERROR(NotFound, "found no array matching the given name") }
555 }
556
557 template < typename GUM_SCALAR >
558 INLINE const typename PRMSystem< GUM_SCALAR >::array_iterator&
559 PRMSystem< GUM_SCALAR >::end(const std::string& a) {
560 try {
561 return arrayMap_[a].second->end();
562 } catch (NotFound const&) { GUM_ERROR(NotFound, "found no array matching the given name") }
563 }
564
565 template < typename GUM_SCALAR >
567 PRMSystem< GUM_SCALAR >::begin(const std::string& a) const {
568 try {
569 return arrayMap_[a].second->begin();
570 } catch (NotFound const&) { GUM_ERROR(NotFound, "found no array matching the given name") }
571 }
572
573 template < typename GUM_SCALAR >
575 PRMSystem< GUM_SCALAR >::end(const std::string& a) const {
576 try {
577 return arrayMap_[a].second->end();
578 } catch (NotFound const&) { GUM_ERROR(NotFound, "found no array matching the given name") }
579 }
580
581 template < typename GUM_SCALAR >
582 INLINE bool PRMSystem< GUM_SCALAR >::exists(const std::string& name) const {
583 return nameMap_.exists(name) || arrayMap_.exists(name);
584 }
585 } /* namespace prm */
586} /* namespace gum */
Headers of gum::prm::PRMInstance<GUM_SCALAR>.
Headers of PRMSystem.
A factory class to ease BayesNet construction.
void addTick(const GUM_SCALAR &tick)
Adds a tick to the current Discretized variable.
const DiscreteVariable & variable(const std::string &name) const
Returns a constant reference on a variable given it's name.
void startParentsDeclaration(const std::string &var) final
Tells the factory that we're declaring parents for some variable.
void startNetworkDeclaration() final
Tells the factory that we're in a network declaration.
void variableType(const VarType &type)
Tells the factory the current variable's type.
void addModality(const std::string &name) final
Adds a modality to the current labelized variable.
void setVariableCPT(const std::string &varName, MultiDimAdressable *table, bool redefineParents) final
Define a variable's CPT.
void addMin(const long &min)
Adds the min value of the current range variable.
void setVariableCPTImplementation(MultiDimAdressable *adressable) final
Defines the implementation to use for var's Tensor.
void endNetworkDeclaration() final
Tells the factory that we're out of a network declaration.
NodeId endVariableDeclaration() final
Tells the factory that we're out of a variable declaration.
void setVariable(const DiscreteVariable &var) final
Define a variable.
void startVariableDeclaration() final
Tells the factory that we're in a variable declaration.
void addNetworkProperty(const std::string &propName, const std::string &propValue) final
Tells the factory to add a property to the current network.
void variableName(const std::string &name) final
Tells the factory the current variable's name.
void endParentsDeclaration() final
Tells the factory that we've finished declaring parents for some variable.
void addParent(const std::string &var) final
Tells the factory for which variable we're declaring parents.
void addMax(const long &max)
Adds the max value of the current range variable.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
Base class for all oriented graphs.
Definition diGraph.h:130
Base class for discrete random variable.
VarType varType() const override=0
returns the varType of variable
Exception : a similar element already exists.
Exception : fatal (unknown ?) error.
class IntegerVariable
class LabelizedVariable
virtual void add(const DiscreteVariable &v) final
Adds a new var to the variables of the multidimensional matrix.
Exception : the element we looked for cannot be found.
Exception : there is something wrong with an implementation.
class NumericalDiscreteVariable
Defines an aggregate in a PRM.
Exception : wrong subtype or subclass.
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:972
Representation of a set.
Definition set.h:131
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Definition tensor.h:85
void setName(const std::string &theValue)
sets the name of the variable
exists aggregator
Definition exists.h:73
forall aggregator
Definition forall.h:74
max aggregator
Definition max.h:73
PRMAttribute is a member of a Class in a PRM.
virtual const Tensor< GUM_SCALAR > & cpf() const =0
See gum::PRMClassElement::cpf().
virtual PRMType & type()=0
See gum::PRMClassElement::type().
<agrum/PRM/classElementContainer.h>
Abstract class representing an element of PRM class.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
Definition PRMClass.h:75
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
Definition PRMInstance.h:79
PRMClass< GUM_SCALAR > & type()
Returns the type of this instance.
const Set< PRMInstance< GUM_SCALAR > * > & getInstances(NodeId id) const
Returns the Set of PRMInstance<GUM_SCALAR> referenced by id.
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>.
const std::string & name() const
Returns the name of this object.
prm_type
Enumeration of the different types of objects handled by a PRM.
Definition PRMObject.h:88
PRMObject(const std::string &name)
Constructor.
Definition PRMObject.cpp:62
A PRMSlotChain represents a sequence of gum::prm::PRMClassElement<GUM_SCALAR> where the n-1 first gum...
PRMClassElement< GUM_SCALAR > & lastElt()
Returns the last element of the slot chain, typically this is an gum::PRMAttribute or a gum::PRMAggre...
typename NodeProperty< PRMInstance< GUM_SCALAR > * >::const_iterator const_iterator
Constant Iterator over the PRMInstance of this PRMSystem.
Definition PRMSystem.h:224
bool isInstantiated(const PRMClass< GUM_SCALAR > &c) const
Returns true if the given Class<GUM_SCALAR> has at least one PRMInstance in this PRMSystem.
HashTable< PRMClass< GUM_SCALAR > *, Set< PRMInstance< GUM_SCALAR > * > * > instanceMap_
Mapping between a class and all it's PRMInstance in this system.
Definition PRMSystem.h:284
typename Sequence< PRMInstance< GUM_SCALAR > * >::iterator array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
Definition PRMSystem.h:234
const DiGraph & skeleton() const
Returns the relation skeleton of this PRMSystem.
iterator begin()
Returns an iterator over the instances in this system.
typename Sequence< PRMInstance< GUM_SCALAR > * >::const_iterator const_array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
Definition PRMSystem.h:247
PRMInstance< GUM_SCALAR > & get(NodeId id)
Returns an PRMInstance given it's NodeId in the relational skeleton.
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
const iterator & end()
Returns a iterator at the end of the set of PRMInstance in this PRMSystem.
PRMSystem(const std::string &name)
Default constructor.
Size size() const
Returns the number of PRMInstance in this PRMSystem.
bool isInstance(const std::string &name) const
Returns true if an PRMInstance with the given name exists.
void addArray(const std::string &array, PRMClassElementContainer< GUM_SCALAR > &type)
Add an array of instances in this system. If the array doesn't exists it is created.
bool exists(const std::string &name) const
Retruns true either if name is an instance or an array in this PRMSystem.
DiGraph skeleton_
The relational skeleton of this PRMSystem.
Definition PRMSystem.h:274
typename NodeProperty< PRMInstance< GUM_SCALAR > * >::iterator iterator
Iterator over the PRMInstance of this PRMSystem.
Definition PRMSystem.h:214
const Sequence< PRMInstance< GUM_SCALAR > * > & getArray(const std::string &name) const
Returns the sequence of instances of a given array.
HashTable< std::string, PRMInstance< double > * > nameMap_
Definition PRMSystem.h:281
void _groundTensor_(const PRMInstance< double > &instance, const PRMAttribute< double > &attr, BayesNetFactory< double > &factory) const
bool isArray(const std::string &name) const
Returns true if an array with the given name exists.
virtual ~PRMSystem()
Destructor.
void groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian network of this system.
std::pair< PRMClassElementContainer< GUM_SCALAR > *, Sequence< PRMInstance< GUM_SCALAR > * > * > model_pair
Type for the pair of a Class<GUM_SCALAR> and the sequence of it's instantiation.
Definition PRMSystem.h:288
NodeProperty< PRMInstance< GUM_SCALAR > * > nodeIdMap_
The mapping between PRMInstance and their NodeId in the relational skeleton of this PRMSystem.
Definition PRMSystem.h:278
HashTable< std::string, model_pair > arrayMap_
Mapping between arrays and their name. The first element of the pair is the type of the array.
Definition PRMSystem.h:293
void _groundRef_(const PRMInstance< double > &instance, BayesNetFactory< double > &factory) const
void _groundAgg_(const PRMClassElement< double > &elt, const std::string &name, BayesNetFactory< double > &factory) const
NodeId add(PRMInstance< GUM_SCALAR > *i)
Add an PRMInstance to this system.
PRMClassElementContainer< GUM_SCALAR > & getArrayType(const std::string &name)
Returns the type of the given array.
virtual PRMObject::prm_type obj_type() const
Returns the PRM type of this object.
void _groundAttr_(const PRMInstance< GUM_SCALAR > &instance, BayesNetFactory< GUM_SCALAR > &factory) const
Method which ground Atttributes and Aggregators of an PRMInstance.
DiscreteVariable & variable()
Return a reference on the DiscreteVariable contained in this.
Definition PRMType_inl.h:64
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
exists aggregator
forall aggregator
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
max aggregator
min aggregator
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
VarType
Definition variable.h:60