aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
PRMAggregate.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_AGGREGATE_H
50#define GUM_AGGREGATE_H
51
52#include <memory>
53#include <string>
54
57
58namespace gum {
59 namespace prm {
60
80 template < typename GUM_SCALAR >
81 class PRMAggregate: public PRMClassElement< GUM_SCALAR > {
82 friend class PRMClass< GUM_SCALAR >;
83
84 public:
85 // ========================================================================
87 // ========================================================================
89
103
112 static AggregateType str2enum(const std::string& str) {
113 if (toLower(str) == "min") {
114 return AggregateType::MIN;
115 } else if (toLower(str) == "max") {
116 return AggregateType::MAX;
117 } else if (toLower(str) == "count") {
119 } else if (toLower(str) == "exists") {
121 } else if (toLower(str) == "or") {
122 return AggregateType::OR;
123 } else if (toLower(str) == "and") {
124 return AggregateType::AND;
125 } else if (toLower(str) == "forall") {
127 } else if (toLower(str) == "amplitude") {
129 } else if (toLower(str) == "median") {
131 } else if (toLower(str) == "sum") {
132 return AggregateType::SUM;
133 } else {
134 std::string msg = "Unknown aggregate: ";
135 msg.append(str);
136 GUM_ERROR(NotFound, msg)
137 }
138 }
139
141 // ========================================================================
143 // ========================================================================
145
153 PRMAggregate(const std::string& name, AggregateType aggType, const PRMType& rvType);
154
163 PRMAggregate(const std::string& name,
164 AggregateType aggType,
165 const PRMType& rvType,
166 Idx label);
167
169 virtual ~PRMAggregate();
170
172 // ========================================================================
174 // ========================================================================
176
179
181 AggregateType agg_type() const;
182
188 Idx label() const;
189 const std::string& labelValue() const;
190
196 std::shared_ptr< Idx > sharedLabel() const;
197
203 void sharedLabel(std::shared_ptr< Idx > label);
204
208 void setLabel(Idx idx);
209 void setLabel(const std::string& label);
210
214 bool hasLabel() const;
215
219 bool isDecomposable() const;
220
222 virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt);
223
225 virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt);
226
228 virtual PRMType& type();
229
231 virtual const PRMType& type() const;
232
238 virtual Tensor< GUM_SCALAR >& cpf();
239
245 virtual const Tensor< GUM_SCALAR >& cpf() const;
246
254
257
258 private:
259 // ========================================================================
261 // ========================================================================
263
266
269
271 // ========================================================================
273 // ========================================================================
275
278
282
286 std::shared_ptr< Idx > _label_;
287 // Idx* _label_;
288 std::string _label_value_;
289
291 };
292
293
294#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
295 extern template class PRMAggregate< double >;
296#endif
297
298 } /* namespace prm */
299} // namespace gum
300
302
303#endif /* GUM_AGGREGATE_H */
Inline implementation of gum::PRMAggregate.
Headers of gum::PRMScalarAttribute.
Headers of Class.
<agrum/base/multidim/multiDimImplementation.h>
Exception : the element we looked for cannot be found.
Idx label() const
Returns the label's index on which this aggregate applies.
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::addParent_().
virtual void addChild(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::addChild_().
virtual PRMType & type()
See gum::PRMClassElement::type().
AggregateType
The different type of aggregates we can have.
PRMAggregate< GUM_SCALAR > & operator=(const PRMAggregate< GUM_SCALAR > &source)
Copy operator. Don't use it.
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const
See gum::PRMClassElement::elt_type().
PRMAggregate(const std::string &name, AggregateType aggType, const PRMType &rvType)
Default constructor.
static AggregateType str2enum(const std::string &str)
Static method which returns the AggregateType given its string representation.
AggregateType agg_type() const
Returns the aggregate of *this.
AggregateType _agg_type_
The AggregateType of this aggregate.
bool hasLabel() const
Returns true if the label is defined.
std::shared_ptr< Idx > sharedLabel() const
Returns the shared_ptr holding this Aggregate label.
void setLabel(Idx idx)
Set the aggregator's label.
std::string _label_value_
The AggregateType of this aggregate.
std::shared_ptr< Idx > _label_
Some aggregators applies only on a given label. This attribute must have the concerned Idx....
virtual Tensor< GUM_SCALAR > & cpf()
Aggregates don't have Tensor until they are instantiated as PRMAttribute, so this will raise an Opera...
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const
See gum::PRMClassElement::elt_type().
MultiDimImplementation< GUM_SCALAR > * buildImpl() const
Returns a pointer over an empty gum::MultiDimImplementation of the good type for this PRMAggregate.
PRMType * _type_
The random variable type of this aggregate It is deleted with the aggregate.
virtual ~PRMAggregate()
Destructor.
const std::string & labelValue() const
See gum::PRMClassElement::elt_type().
bool isDecomposable() const
Returns true if the aggregator is decomposable.
PRMAttribute is a member of a Class in a PRM.
Abstract class representing an element of PRM class.
PRMClassElement(const std::string &name)
Default constructor of a PRMClassElement.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
A PRMClass is an object of a PRM representing a fragment of a Bayesian network which can be instantia...
Definition PRMClass.h:75
const std::string & name() const
Returns the name of this object.
This is a decoration of the DiscreteVariable class.
Definition PRMType.h:78
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
Size Idx
Type for indexes.
Definition types.h:79
std::string toLower(std::string str)
Returns the lowercase version of str.
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46