aGrUM 3.1.1
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-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
48
49#ifndef GUM_SYSTEM_H
50#define GUM_SYSTEM_H
51
52#include <string>
53#include <utility>
54
58
59#include <string_view>
60
61namespace gum {
62 namespace prm {
63
71 template < GUM_Numeric GUM_SCALAR >
72 class PRMSystem: public PRMObject {
73 public:
74 // ========================================================================
76 // ========================================================================
78
80 explicit PRMSystem(std::string_view name);
81
83 ~PRMSystem() override;
84
86 // ========================================================================
88 // ========================================================================
90
92 const DiGraph& skeleton() const;
93
100
106 const PRMInstance< GUM_SCALAR >& get(NodeId id) const;
107
108 NodeId get(const PRMInstance< GUM_SCALAR >& i) const;
109
111 // ========================================================================
113 // ========================================================================
115
117 PRMObject::prm_type obj_type() const override;
118
120 Size size() const;
121
124 bool exists(std::string_view name) const;
125
129 bool isInstantiated(const PRMClass< GUM_SCALAR >& c) const;
130
132 bool isInstance(std::string_view name) const;
133
135 bool isArray(std::string_view name) const;
136
141 void groundedBN(BayesNetFactory< GUM_SCALAR >& factory) const;
142
144 void instantiate();
145
147 // ========================================================================
149 // ========================================================================
151
154 PRMInstance< GUM_SCALAR >& get(std::string_view name);
155
158 const PRMInstance< GUM_SCALAR >& get(std::string_view name) const;
159
162 const Set< PRMInstance< GUM_SCALAR >* >& get(const PRMClass< GUM_SCALAR >& type) const;
163
168
170 // ========================================================================
172 // ========================================================================
174
177 const Sequence< PRMInstance< GUM_SCALAR >* >& getArray(std::string_view name) const;
178
182
185 const PRMClassElementContainer< GUM_SCALAR >& getArrayType(std::string_view name) const;
186
193 NodeId add(std::string_view array, PRMInstance< GUM_SCALAR >* i);
194
201 NodeId add(std::string_view array, PRMInstance< GUM_SCALAR >& i);
202
207 void addArray(std::string_view array, PRMClassElementContainer< GUM_SCALAR >& type);
208
210 // ========================================================================
212 // ========================================================================
214
217
219 iterator begin();
220
223 const iterator& end();
224
227
229 const_iterator begin() const;
230
233 const const_iterator& end() const;
234
237
241 array_iterator begin(std::string_view a);
242
246 const array_iterator& end(std::string_view a);
247
250
254 const_array_iterator begin(std::string_view a) const;
255
259 const const_array_iterator& end(std::string_view a) const;
260
262
263 protected:
266
269
270 // ========================================================================
272 // ========================================================================
274
277
281
284
287
290 using model_pair = std::pair< PRMClassElementContainer< GUM_SCALAR >*,
292
296
298 // ========================================================================
300 // ========================================================================
302
308 void _groundRef_(const PRMInstance< GUM_SCALAR >& instance,
309 BayesNetFactory< GUM_SCALAR >& factory) const;
310
315 void _groundAttr_(const PRMInstance< GUM_SCALAR >& instance,
316 BayesNetFactory< GUM_SCALAR >& factory) const;
317
326 void _groundTensor_(const PRMInstance< GUM_SCALAR >& instance,
327 const PRMAttribute< GUM_SCALAR >& attr,
328 BayesNetFactory< GUM_SCALAR >& factory) const;
329
336 std::string_view name,
337 BayesNetFactory< GUM_SCALAR >& factory) const;
339 };
340
341
342#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
343 extern template class PRMSystem< double >;
344#endif
345
346
347 } /* namespace prm */
348
349} /* namespace gum */
350
352
353#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:132
The class for generic Hash Tables.
Definition hashTable.h:640
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:994
Representation of a set.
Definition set.h:129
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:77
An PRMInstance is a Bayesian network fragment defined by a Class and used in a PRMSystem.
Definition PRMInstance.h:79
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
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
Ground an aggregator with the given name in the grounded IBayesNet.
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
Method which copy node's Tensor of an PRMInstance to the grounded Bayesian network.
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
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: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
Method which ground PRMReferenceSlot of an PRMInstance and add arcs in the IBayesNet.
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.
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