aGrUM 3.1.1
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-2026 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-2026 *
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
41#pragma once
42
43
57
58namespace gum {
59 namespace prm {
60 template < GUM_Numeric GUM_SCALAR >
62 GUM_CONSTRUCTOR(PRMSystem);
63 }
64
65 template < GUM_Numeric GUM_SCALAR >
67 GUM_DESTRUCTOR(PRMSystem);
68
69 for (const auto& elt: *this)
70 delete elt.second;
71
72 for (const auto& elt: instanceMap_)
73 delete elt.second;
74
75 for (const auto& elt: arrayMap_)
76 delete elt.second.second;
77 }
78
79 template < GUM_Numeric GUM_SCALAR >
83 GUM_CONS_CPY(PRMSystem);
84 }
85
86 template < GUM_Numeric GUM_SCALAR >
88 if (nameMap_.exists(i->name())) {
90 "an Instance<GUM_SCALAR> with the same is already in this System");
91 }
93 NodeId id = skeleton_.addNode();
94 nodeIdMap_.insert(id, i);
95 nameMap_.insert(i->name(), i);
96
97 auto p_inst = instanceMap_.tryGet(&(i->type()));
98 if (!p_inst) {
99 instanceMap_.insert(&(i->type()), new Set< PRMInstance< GUM_SCALAR >* >());
100 p_inst = instanceMap_.tryGet(&(i->type()));
101 }
102 (*p_inst)->insert(i);
103
104 return id;
105 }
106
107 template < GUM_Numeric GUM_SCALAR >
109 factory.startNetworkDeclaration();
110 factory.addNetworkProperty("name", name());
111 factory.endNetworkDeclaration();
112
113 // Adding nodes
114 for (PRMSystem< GUM_SCALAR >::const_iterator iter = begin(); iter != end(); ++iter) {
115 _groundAttr_(*(iter.val()), factory);
116 }
118 // Adding arcs and filling CPTs
119 for (PRMSystem< GUM_SCALAR >::const_iterator iter = begin(); iter != end(); ++iter) {
120 _groundRef_(*(iter.val()), factory);
121 }
122 }
123
124 template < GUM_Numeric GUM_SCALAR >
126 BayesNetFactory< GUM_SCALAR >& factory) const {
127 for (const auto node: instance.type().containerDag()) {
128 // Working a Class<GUM_SCALAR> level because PRMAggregate<GUM_SCALAR>
129 // are
130 // instantiated as PRMAttribute<GUM_SCALAR> in an
131 // PRMInstance<GUM_SCALAR>
132 switch (instance.type().get(node).elt_type()) {
134 // TODO: make a special case for noisy-or
135 DiscreteVariable* var = instance.get(node).type().variable().clone();
136 var->setName(
137 std::format("{}.{}", instance.name(), instance.type().get(node).safeName()));
138 factory.setVariable(*var); // var is copied by the factory
139 delete var;
140 break;
142
144 _groundAgg_(instance.type().get(node),
145 std::format("{}.{}", instance.name(), instance.type().get(node).safeName()),
146 factory);
147 break;
148 }
149
150 default :
151 break;
152 /* Do nothing */
153 ;
154 }
155 }
156 }
157
158 template < GUM_Numeric GUM_SCALAR >
160 std::string_view 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 }
179 case VarType::INTEGER : {
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;
205 }
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()) {
215 break;
216 }
217
220 break;
221 }
222
225 break;
226 }
227
230 break;
231 }
232
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 < GUM_Numeric GUM_SCALAR >
271 BayesNetFactory< GUM_SCALAR >& factory) const {
272 for (const auto& elt: instance) {
274 std::format("{}.{}", instance.name(), elt.second->safeName()));
275
276 for (const auto par: instance.type().containerDag().parents(elt.second->id())) {
277 switch (instance.type().get(par).elt_type()) {
280 factory.addParent(
281 std::format("{}.{}", instance.name(), instance.get(par).safeName()));
282 break;
283 }
284
286 std::string parent_name
287 = static_cast< const PRMSlotChain< GUM_SCALAR >& >(instance.type().get(par))
288 .lastElt()
289 .safeName();
290
291 try {
292 for (const auto ref: instance.getInstances(par)) {
293 factory.addParent(std::format("{}.{}", ref->name(), parent_name));
294 }
295 } catch (NotFound const&) {
296 // No instances for this slotchain
297 }
298
299 break;
300 }
301
302 default :
303 break;
304 /* nothing to do by default */
305 }
306 }
307
309
310 // Checking if we need to ground the Tensor (only for class level
311 // attributes since
312 // aggregates Tensors are generated)
313 if (PRMClassElement< GUM_SCALAR >::isAttribute(instance.type().get(elt.second->safeName())))
314 _groundTensor_(instance, *elt.second, factory);
316 }
317
318 template < GUM_Numeric GUM_SCALAR >
320 const PRMAttribute< GUM_SCALAR >& attr,
321 BayesNetFactory< GUM_SCALAR >& factory) const {
323 std::string var_name = std::format("{}.{}", instance.name(), attr.safeName());
324 bijection.insert(&(attr.type().variable()), &(factory.variable(var_name)));
325
326 for (const auto parent: instance.type().containerDag().parents(attr.id())) {
327 switch (instance.type().get(parent).elt_type()) {
330 auto parent_name
331 = std::format("{}.{}", instance.name(), instance.get(parent).safeName());
332 bijection.insert(&(instance.get(parent).type().variable()),
333 &(factory.variable(parent_name)));
334 break;
336
339 = static_cast< const PRMSlotChain< GUM_SCALAR >& >(instance.type().get(parent));
340 auto parent_name = std::format("{}.{}",
341 instance.getInstance(sc.id()).name(),
342 sc.lastElt().safeName());
343 bijection.insert(
344 &(instance.getInstance(sc.id()).get(sc.lastElt().safeName()).type().variable()),
345 &(factory.variable(parent_name)));
346 break;
347 }
348
349 default : {
350 GUM_ERROR(FatalError, "invalid ClassElement<GUM_SCALAR> type as parent.")
351 break;
352 }
353 }
354 }
355
356 // Copy Tensor
357 // DO NOT USE MultiDimBijArray as they will wreck havok if you delete
358 // the prm befor its grounded BN (happens a lot in pyAgrum)
359 Tensor< GUM_SCALAR >* p = new Tensor< GUM_SCALAR >();
360 for (auto var: attr.cpf().variablesSequence()) {
361 p->add(*(bijection.second(var)));
362 }
363 Instantiation inst(attr.cpf()), jnst(*p);
364 for (inst.setFirst(), jnst.setFirst(); !(inst.end() || jnst.end()); inst.inc(), jnst.inc()) {
365 p->set(jnst, attr.cpf().get(inst));
366 }
367 GUM_ASSERT(inst.end() && jnst.end());
368 factory.setVariableCPT(var_name, p, false);
369 }
370
371 template < GUM_Numeric GUM_SCALAR >
373 return add(array, &i);
374 }
375
376 template < GUM_Numeric GUM_SCALAR >
378 return skeleton_;
379 }
380
381 template < GUM_Numeric GUM_SCALAR >
383 auto p = nodeIdMap_.tryGet(id);
384 if (!p) GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given id")
385 return *(*p);
386 }
387
388 template < GUM_Numeric GUM_SCALAR >
390 auto p = nodeIdMap_.tryGet(id);
391 if (!p) GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given id")
392 return *(*p);
393 }
394
395 template < GUM_Numeric GUM_SCALAR >
397 try {
398 return nodeIdMap_.keyByVal(const_cast< PRMInstance< GUM_SCALAR >* >(&i));
399 } catch (NotFound const&) {
400 GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given id")
401 }
402 }
403
404 template < GUM_Numeric GUM_SCALAR >
408
409 template < GUM_Numeric GUM_SCALAR >
411 return nodeIdMap_.size();
412 }
413
414 template < GUM_Numeric GUM_SCALAR >
416 return instanceMap_.exists(const_cast< PRMClass< GUM_SCALAR >* >(&c));
417 }
418
419 template < GUM_Numeric GUM_SCALAR >
420 bool PRMSystem< GUM_SCALAR >::isInstance(std::string_view name) const {
421 return nameMap_.exists(name);
422 }
423
424 template < GUM_Numeric GUM_SCALAR >
425 bool PRMSystem< GUM_SCALAR >::isArray(std::string_view name) const {
426 return arrayMap_.exists(name);
427 }
428
429 template < GUM_Numeric GUM_SCALAR >
431 for (auto iter = begin(); iter != end(); ++iter) {
432 (*(iter.val())).instantiate();
433 }
434 }
435
436 template < GUM_Numeric GUM_SCALAR >
438 auto p = nameMap_.tryGet(name);
439 if (!p) GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given name")
440 return *(*p);
441 }
442
443 template < GUM_Numeric GUM_SCALAR >
445 auto p = nameMap_.tryGet(name);
446 if (!p) GUM_ERROR(NotFound, "found no Instance<GUM_SCALAR> matching the given name")
447 return *(*p);
448 }
449
450 template < GUM_Numeric GUM_SCALAR >
452
454 auto p = instanceMap_.tryGet(const_cast< PRMClass< GUM_SCALAR >* >(&type));
455 if (!p) GUM_ERROR(NotFound, "the given Class<GUM_SCALAR> has no instantiation in this System")
456 return *(*p);
457 }
458
459 template < GUM_Numeric GUM_SCALAR >
461
462 PRMSystem< GUM_SCALAR >::getArray(std::string_view name) const {
463 auto p = arrayMap_.tryGet(name);
464 if (!p) GUM_ERROR(NotFound, "found no array matching the given name")
465 return *(p->second);
466 }
467
468 template < GUM_Numeric GUM_SCALAR >
471 auto p = arrayMap_.tryGet(name);
472 if (!p) GUM_ERROR(NotFound, "found no array matching the given name")
473 return *(p->first);
474 }
475
476 template < GUM_Numeric GUM_SCALAR >
479 auto p = arrayMap_.tryGet(name);
480 if (!p) GUM_ERROR(NotFound, "found no array matching the given name")
481 return *(p->first);
482 }
483
484 template < GUM_Numeric GUM_SCALAR >
486 auto p_arr = arrayMap_.tryGet(array);
487 if (!p_arr) GUM_ERROR(NotFound, "found no array matching the given name")
488 if (i->type().isSubTypeOf(*(p_arr->first))) {
489 NodeId id = add(i);
490 p_arr->second->insert(i);
491 return id;
492 } else {
494 "the given Instance<GUM_SCALAR> is of an incorrect "
495 "Class<GUM_SCALAR> type");
496 }
497 }
498
499 template < GUM_Numeric GUM_SCALAR >
500 void PRMSystem< GUM_SCALAR >::addArray(std::string_view array,
502 if (arrayMap_.exists(array)) {
503 GUM_ERROR(DuplicateElement, "an array '" << array << "' is already in this System")
504 }
505
506 arrayMap_.insert(
507 std::string{array},
509 }
510
511 template < GUM_Numeric GUM_SCALAR >
515
516 template < GUM_Numeric GUM_SCALAR >
520
521 template < GUM_Numeric GUM_SCALAR >
525
526 template < GUM_Numeric GUM_SCALAR >
528 return nodeIdMap_.end();
529 }
530
531 template < GUM_Numeric GUM_SCALAR >
533 PRMSystem< GUM_SCALAR >::begin(std::string_view a) {
534 auto p = arrayMap_.tryGet(a);
535 if (!p) GUM_ERROR(NotFound, "found no array matching the given name")
536 return p->second->begin();
537 }
538
539 template < GUM_Numeric GUM_SCALAR >
541 PRMSystem< GUM_SCALAR >::end(std::string_view a) {
542 auto p = arrayMap_.tryGet(a);
543 if (!p) GUM_ERROR(NotFound, "found no array matching the given name")
544 return p->second->end();
545 }
546
547 template < GUM_Numeric GUM_SCALAR >
549 PRMSystem< GUM_SCALAR >::begin(std::string_view a) const {
550 auto p = arrayMap_.tryGet(a);
551 if (!p) GUM_ERROR(NotFound, "found no array matching the given name")
552 return p->second->begin();
553 }
554
555 template < GUM_Numeric GUM_SCALAR >
557 PRMSystem< GUM_SCALAR >::end(std::string_view a) const {
558 auto p = arrayMap_.tryGet(a);
559 if (!p) GUM_ERROR(NotFound, "found no array matching the given name")
560 return p->second->end();
561 }
562
563 template < GUM_Numeric GUM_SCALAR >
564 bool PRMSystem< GUM_SCALAR >::exists(std::string_view name) const {
565 return nameMap_.exists(name) || arrayMap_.exists(name);
566 }
567 } /* namespace prm */
568} /* namespace gum */
Headers of gum::prm::PRMInstance<GUM_SCALAR>.
Headers of PRMSystem.
A factory class to ease BayesNet construction.
void endParentsDeclaration() final
Tells the factory that we've finished declaring parents for some variable.
void setVariableCPT(std::string_view varName, MultiDimAdressable *table, bool redefineParents) final
Define a variable's CPT.
void addModality(std::string_view name) final
Adds a modality to the current labelized variable.
void endNetworkDeclaration() final
Tells the factory that we're out of a network declaration.
const DiscreteVariable & variable(std::string_view name) const
Returns a constant reference on a variable given it's name.
void addParent(std::string_view var) final
Tells the factory for which variable we're declaring parents.
void setVariable(const DiscreteVariable &var) final
Define a variable.
void addMax(const long &max) override
Adds the max value of the current range variable.
void variableType(const VarType &type) override
Tells the factory the current variable's type.
void startNetworkDeclaration() final
Tells the factory that we're in a network declaration.
void startParentsDeclaration(std::string_view var) final
Tells the factory that we're declaring parents for some variable.
void addNetworkProperty(std::string_view propName, std::string_view propValue) final
Tells the factory to add a property to the current network.
void setVariableCPTImplementation(MultiDimAdressable *adressable) final
Defines the implementation to use for var's Tensor.
void addTick(const GUM_SCALAR &tick)
Adds a tick to the current Discretized variable.
void startVariableDeclaration() final
Tells the factory that we're in a variable declaration.
void addMin(const long &min) override
Adds the min value of the current range variable.
NodeId endVariableDeclaration() final
Tells the factory that we're out of a variable declaration.
void variableName(std::string_view name) final
Tells the factory the current variable's name.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
void insert(const T1 &first, const T2 &second)
Inserts a new association in the gum::Bijection.
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1640
Base class for all oriented graphs.
Definition diGraph.h:132
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
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:994
Representation of a set.
Definition set.h:129
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Definition tensor.h:85
void setName(std::string_view theValue)
sets the name of the variable
count aggregator
Definition count.h:76
exists aggregator
Definition exists.h:73
forall aggregator
Definition forall.h:74
max aggregator
Definition max.h:73
min aggregator
Definition min.h:72
PRMAttribute is a member of a Class in a PRM.
const Tensor< GUM_SCALAR > & cpf() const override=0
See gum::PRMClassElement::cpf().
PRMType & type() override=0
See gum::PRMClassElement::type().
<agrum/PRM/classElementContainer.h>
Abstract class representing an element of PRM class.
virtual PRMType & type()=0
Return a reference over the gum::PRMType of this class element.
static INLINE bool isAttribute(const PRMClassElement< GUM_SCALAR > &elt)
Returns true if obj_ptr is of type PRMAttribute.
NodeId id() const
Returns the NodeId of this element in it's class DAG.
const std::string & safeName() const
Returns the safe name of this PRMClassElement, if any.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
Definition PRMClass.h:77
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
Definition PRMInstance.h:79
const PRMInstance< GUM_SCALAR > & getInstance(NodeId id) const
Fast access to the first instance in a PRMReferenceSlot or PRMSlotChain<GUM_SCALAR>.
PRMAttribute< GUM_SCALAR > & get(NodeId id)
Getter on an PRMAttribute<GUM_SCALAR> of this PRMInstance<GUM_SCALAR>.
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.
PRMObject(std::string_view name)
Constructor.
Definition PRMObject.cpp:62
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:90
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...
PRMClassElementContainer< GUM_SCALAR > & getArrayType(std::string_view name)
Returns the type of the given array.
typename NodeProperty< PRMInstance< GUM_SCALAR > * >::const_iterator const_iterator
Constant Iterator over the PRMInstance of this PRMSystem.
Definition PRMSystem.h:226
PRMObject::prm_type obj_type() const override
Returns the PRM type of this object.
HashTable< PRMClass< GUM_SCALAR > *, Set< PRMInstance< GUM_SCALAR > * > * > instanceMap_
Mapping between a class and all it's PRMInstance in this system.
Definition PRMSystem.h:286
typename Sequence< PRMInstance< GUM_SCALAR > * >::iterator array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
Definition PRMSystem.h:236
void addArray(std::string_view array, PRMClassElementContainer< GUM_SCALAR > &type)
Add an array of instances in this system. If the array doesn't exists it is created.
const iterator & end()
Returns an iterator at the end of the set of PRMInstance in this PRMSystem.
void _groundAgg_(const PRMClassElement< GUM_SCALAR > &elt, std::string_view name, BayesNetFactory< GUM_SCALAR > &factory) const
typename Sequence< PRMInstance< GUM_SCALAR > * >::const_iterator const_array_iterator
Iterator over the PRMInstance in an array in this PRMSystem.
Definition PRMSystem.h:249
~PRMSystem() override
Destructor.
iterator begin()
Returns an iterator over the instances in this system.
DiGraph skeleton_
The relational skeleton of this PRMSystem.
Definition PRMSystem.h:276
bool exists(std::string_view name) const
Retruns true either if name is an instance or an array in this PRMSystem.
PRMSystem(std::string_view name)
Default constructor.
typename NodeProperty< PRMInstance< GUM_SCALAR > * >::iterator iterator
Iterator over the PRMInstance of this PRMSystem.
Definition PRMSystem.h:216
HashTable< std::string, PRMInstance< GUM_SCALAR > * > nameMap_
The mapping between PRMInstance and their names.
Definition PRMSystem.h:283
const Sequence< PRMInstance< GUM_SCALAR > * > & getArray(std::string_view name) const
Returns the sequence of instances of a given array.
void _groundTensor_(const PRMInstance< GUM_SCALAR > &instance, const PRMAttribute< GUM_SCALAR > &attr, BayesNetFactory< GUM_SCALAR > &factory) const
PRMInstance< GUM_SCALAR > & get(NodeId id)
Returns an PRMInstance given it's NodeId in the relational skeleton.
const DiGraph & skeleton() const
Returns the relation skeleton of this PRMSystem.
bool isInstantiated(const PRMClass< GUM_SCALAR > &c) const
Returns true if the given Class<GUM_SCALAR> has at least one PRMInstance in this PRMSystem.
Size size() const
Returns the number of PRMInstance in this PRMSystem.
void groundedBN(BayesNetFactory< GUM_SCALAR > &factory) const
Returns the grounded Bayesian network of this system.
bool isInstance(std::string_view name) const
Returns true if an PRMInstance with the given name exists.
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:290
NodeProperty< PRMInstance< GUM_SCALAR > * > nodeIdMap_
The mapping between PRMInstance and their NodeId in the relational skeleton of this PRMSystem.
Definition PRMSystem.h:280
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:295
void _groundRef_(const PRMInstance< GUM_SCALAR > &instance, BayesNetFactory< GUM_SCALAR > &factory) const
void instantiate()
Instantiate all the PRMInstance in this PRMSystem.
NodeId add(PRMInstance< GUM_SCALAR > *i)
Add an PRMInstance to this system.
bool isArray(std::string_view name) const
Returns true if an array with the given name exists.
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:65
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
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:62