aGrUM 3.1.1
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-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_AGGREGATE_H
50#define GUM_AGGREGATE_H
51
52#include <memory>
53#include <string>
54
57
58#include <string_view>
59
60namespace gum {
61 namespace prm {
62
82 template < GUM_Numeric GUM_SCALAR >
83 class PRMAggregate: public PRMClassElement< GUM_SCALAR > {
84 friend class PRMClass< GUM_SCALAR >;
85
86 public:
87 // ========================================================================
89 // ========================================================================
91
105
114 static AggregateType str2enum(std::string_view str);
115
117 // ========================================================================
119 // ========================================================================
121
129 PRMAggregate(std::string_view name, AggregateType aggType, const PRMType& rvType);
130
139 PRMAggregate(std::string_view name, AggregateType aggType, const PRMType& rvType, Idx label);
140
142 ~PRMAggregate() override;
143
145 // ========================================================================
147 // ========================================================================
149
152
154 AggregateType agg_type() const;
155
161 Idx label() const;
162 const std::string& labelValue() const;
163
169 std::shared_ptr< Idx > sharedLabel() const;
170
176 void sharedLabel(std::shared_ptr< Idx > label);
177
181 void setLabel(Idx idx);
182 void setLabel(std::string_view label);
183
187 bool hasLabel() const;
188
192 bool isDecomposable() const;
193
195 void addParent(const PRMClassElement< GUM_SCALAR >& elt) override;
196
198 void addChild(const PRMClassElement< GUM_SCALAR >& elt) override;
199
201 PRMType& type() override;
202
204 const PRMType& type() const override;
205
211 virtual Tensor< GUM_SCALAR >& cpf();
212
218 const Tensor< GUM_SCALAR >& cpf() const override;
219
227
230
231 private:
232 // ========================================================================
234 // ========================================================================
236
239
242
244 // ========================================================================
246 // ========================================================================
248
251
255
259 std::shared_ptr< Idx > _label_;
260 // Idx* _label_;
261 std::string _label_value_;
262
264 };
265
266
267#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
268 extern template class PRMAggregate< double >;
269#endif
270
271 } /* namespace prm */
272} // namespace gum
273
275
276#endif /* GUM_AGGREGATE_H */
Inline implementation of gum::PRMAggregate.
Headers of gum::PRMScalarAttribute.
Headers of Class.
PRMAttribute< GUM_SCALAR > * getCastDescendant() const override
See gum::PRMClassElement::elt_type().
PRMType & type() override
See gum::PRMClassElement::type().
void addParent(const PRMClassElement< GUM_SCALAR > &elt) override
See gum::PRMClassElement::addParent_().
std::shared_ptr< Idx > sharedLabel() const
Returns the shared_ptr holding this Aggregate label.
void addChild(const PRMClassElement< GUM_SCALAR > &elt) override
See gum::PRMClassElement::addChild_().
PRMAggregate(std::string_view name, AggregateType aggType, const PRMType &rvType)
Default constructor.
AggregateType
The different type of aggregates we can have.
void setLabel(Idx idx)
Set the aggregator's label.
PRMAggregate< GUM_SCALAR > & operator=(const PRMAggregate< GUM_SCALAR > &source)
Copy operator. Don't use it.
bool hasLabel() const
Returns true if the label is defined.
~PRMAggregate() override
Destructor.
AggregateType _agg_type_
The AggregateType of this aggregate.
AggregateType agg_type() const
Returns the aggregate of *this.
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....
MultiDimImplementation< GUM_SCALAR > * buildImpl() const
Returns a pointer over an empty gum::MultiDimImplementation of the good type for this PRMAggregate.
virtual Tensor< GUM_SCALAR > & cpf()
Aggregates don't have Tensor until they are instantiated as PRMAttribute, so this will raise an Opera...
const std::string & labelValue() const
See gum::PRMClassElement::elt_type().
static AggregateType str2enum(std::string_view str)
Static method which returns the AggregateType given its string representation.
PRMType * _type_
The random variable type of this aggregate It is deleted with the aggregate.
PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const override
See gum::PRMClassElement::elt_type().
Idx label() const
Returns the label's index on which this aggregate applies.
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(std::string_view 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:77
const std::string & name() const
Returns the name of this object.
This is a decoration of the DiscreteVariable class.
Definition PRMType.h:78
Size Idx
Type for indexes.
Definition types.h:79
namespace for all probabilistic relational models entities
Definition agrum.h:68
gum is the global namespace for all aGrUM entities
Definition agrum.h:46