aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
PRMSystem.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
41
48
49#ifndef GUM_SYSTEM_H
50#define GUM_SYSTEM_H
51
52#include <string>
53#include <utility>
54
58
59namespace gum {
60 namespace prm {
61
69 template < typename GUM_SCALAR >
70 class PRMSystem: public PRMObject {
71 public:
72 // ========================================================================
74 // ========================================================================
76
78 explicit PRMSystem(const std::string& name);
79
81 virtual ~PRMSystem();
82
84 // ========================================================================
86 // ========================================================================
88
90 const DiGraph& skeleton() const;
91
98
104 const PRMInstance< GUM_SCALAR >& get(NodeId id) const;
105
106 NodeId get(const PRMInstance< GUM_SCALAR >& i) const;
107
109 // ========================================================================
111 // ========================================================================
113
115 virtual PRMObject::prm_type obj_type() const;
116
118 Size size() const;
119
122 bool exists(const std::string& name) const;
123
127 bool isInstantiated(const PRMClass< GUM_SCALAR >& c) const;
128
130 bool isInstance(const std::string& name) const;
131
133 bool isArray(const std::string& name) const;
134
139 void groundedBN(BayesNetFactory< GUM_SCALAR >& factory) const;
140
142 void instantiate();
143
145 // ========================================================================
147 // ========================================================================
149
152 PRMInstance< GUM_SCALAR >& get(const std::string& name);
153
156 const PRMInstance< GUM_SCALAR >& get(const std::string& name) const;
157
160 const Set< PRMInstance< GUM_SCALAR >* >& get(const PRMClass< GUM_SCALAR >& type) const;
161
166
168 // ========================================================================
170 // ========================================================================
172
175 const Sequence< PRMInstance< GUM_SCALAR >* >& getArray(const std::string& name) const;
176
180
183 const PRMClassElementContainer< GUM_SCALAR >& getArrayType(const std::string& name) const;
184
191 NodeId add(const std::string& array, PRMInstance< GUM_SCALAR >* i);
192
199 NodeId add(const std::string& array, PRMInstance< GUM_SCALAR >& i);
200
205 void addArray(const std::string& array, PRMClassElementContainer< GUM_SCALAR >& type);
206
208 // ========================================================================
210 // ========================================================================
212
215
217 iterator begin();
218
221 const iterator& end();
222
225
227 const_iterator begin() const;
228
231 const const_iterator& end() const;
232
235
239 array_iterator begin(const std::string& a);
240
244 const array_iterator& end(const std::string& a);
245
248
252 const_array_iterator begin(const std::string& a) const;
253
257 const const_array_iterator& end(const std::string& a) const;
258
260
261 protected:
264
267
268 // ========================================================================
270 // ========================================================================
272
275
279
282
285
288 using model_pair = std::pair< PRMClassElementContainer< GUM_SCALAR >*,
290
294
296 // ========================================================================
298 // ========================================================================
300
306 void _groundRef_(const PRMInstance< GUM_SCALAR >& instance,
307 BayesNetFactory< GUM_SCALAR >& factory) const;
308
313 void _groundAttr_(const PRMInstance< GUM_SCALAR >& instance,
314 BayesNetFactory< GUM_SCALAR >& factory) const;
315
324 void _groundTensor_(const PRMInstance< GUM_SCALAR >& instance,
325 const PRMAttribute< GUM_SCALAR >& attr,
326 BayesNetFactory< GUM_SCALAR >& factory) const;
327
334 const std::string& name,
335 BayesNetFactory< GUM_SCALAR >& factory) const;
337 };
338
339
340#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
341 extern template class PRMSystem< double >;
342#endif
343
344
345 } /* namespace prm */
346
347} /* namespace gum */
348
350
351#endif // GUM_SYSTEM_H
Headers of the BayesNetFactory class.
Headers of gum::prm::PRMInstance<GUM_SCALAR>.
Inline implementation of PRMSystem.
A factory class to ease BayesNet construction.
Base class for all oriented graphs.
Definition diGraph.h:130
The class for generic Hash Tables.
Definition hashTable.h:637
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:972
Representation of a set.
Definition set.h:131
PRMAttribute is a member of a Class in a PRM.
<agrum/PRM/classElementContainer.h>
Abstract class representing an element of PRM class.
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
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
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< GUM_SCALAR > * > nameMap_
The mapping between PRMInstance and their names.
Definition PRMSystem.h:281
void _groundTensor_(const PRMInstance< GUM_SCALAR > &instance, const PRMAttribute< GUM_SCALAR > &attr, BayesNetFactory< GUM_SCALAR > &factory) const
Method which copy node's Tensor of an PRMInstance to the grounded Bayesian network.
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
PRMSystem< GUM_SCALAR > & operator=(const PRMSystem< GUM_SCALAR > &from)=delete
Copy operator. Don't use it.
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< GUM_SCALAR > &instance, BayesNetFactory< GUM_SCALAR > &factory) const
Method which ground PRMReferenceSlot of an PRMInstance and add arcs in the IBayesNet.
void _groundAgg_(const PRMClassElement< GUM_SCALAR > &elt, const std::string &name, BayesNetFactory< GUM_SCALAR > &factory) const
Ground an aggregator with the given name in the grounded IBayesNet.
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.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Base class for integer discrete random variables.
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46