aGrUM  0.16.0
PRMAggregate.h
Go to the documentation of this file.
1 
30 #ifndef GUM_AGGREGATE_H
31 #define GUM_AGGREGATE_H
32 
33 #include <memory>
34 #include <string>
35 
39 
45 
46 
47 namespace gum {
48  namespace prm {
49 
69  template < typename GUM_SCALAR >
70  class PRMAggregate : public PRMClassElement< GUM_SCALAR > {
71  friend class PRMClass< GUM_SCALAR >;
72 
73  public:
74  // ========================================================================
76  // ========================================================================
78 
80  enum class AggregateType : char {
81  MIN,
82  MAX,
83  COUNT,
84  EXISTS,
85  FORALL,
86  OR,
87  AND,
88  AMPLITUDE,
89  MEDIAN
90  };
91 
100  static AggregateType str2enum(const std::string& str) {
101  if (toLower(str) == "min") {
102  return AggregateType::MIN;
103  } else if (toLower(str) == "max") {
104  return AggregateType::MAX;
105  } else if (toLower(str) == "count") {
106  return AggregateType::COUNT;
107  } else if (toLower(str) == "exists") {
108  return AggregateType::EXISTS;
109  } else if (toLower(str) == "or") {
110  return AggregateType::OR;
111  } else if (toLower(str) == "and") {
112  return AggregateType::AND;
113  } else if (toLower(str) == "forall") {
114  return AggregateType::FORALL;
115  } else if (toLower(str) == "amplitude") {
117  } else if (toLower(str) == "median") {
118  return AggregateType::MEDIAN;
119  } else {
120  std::string msg = "Unknown aggregate: ";
121  msg.append(str);
122  GUM_ERROR(NotFound, msg);
123  }
124  }
125 
127  // ========================================================================
129  // ========================================================================
131 
139  PRMAggregate(const std::string& name,
140  AggregateType aggType,
141  const PRMType& rvType);
142 
151  PRMAggregate(const std::string& name,
152  AggregateType aggType,
153  const PRMType& rvType,
154  Idx label);
155 
157  virtual ~PRMAggregate();
158 
160  // ========================================================================
162  // ========================================================================
164 
167  elt_type() const;
168 
170  AggregateType agg_type() const;
171 
177  Idx label() const;
178  const std::string& labelValue() const;
179 
185  std::shared_ptr< Idx > sharedLabel() const;
186 
192  void sharedLabel(std::shared_ptr< Idx > label);
193 
197  void setLabel(Idx idx);
198  void setLabel(const std::string& label);
199 
203  bool hasLabel() const;
204 
206  virtual void addParent(const PRMClassElement< GUM_SCALAR >& elt);
207 
209  virtual void addChild(const PRMClassElement< GUM_SCALAR >& elt);
210 
212  virtual PRMType& type();
213 
215  virtual const PRMType& type() const;
216 
222  virtual Potential< GUM_SCALAR >& cpf();
223 
229  virtual const Potential< GUM_SCALAR >& cpf() const;
230 
238 
241  private:
242  // ========================================================================
244  // ========================================================================
246 
249 
252  operator=(const PRMAggregate< GUM_SCALAR >& source);
253 
255  // ========================================================================
257  // ========================================================================
259 
262 
266 
270  std::shared_ptr< Idx > __label;
271  // Idx* __label;
272  std::string __label_value;
273 
275  };
276 
277 
278 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
279  extern template class PRMAggregate< double >;
280 #endif
281 
282  } /* namespace prm */
283 } // namespace gum
284 
286 
287 #endif /* GUM_AGGREGATE_H */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
virtual PRMClassElement< GUM_SCALAR >::ClassElementType elt_type() const
See gum::PRMClassElement::elt_type().
static AggregateType str2enum(const std::string &str)
Static method which returns the AggregateType given its string representation.
Definition: PRMAggregate.h:100
MultiDimImplementation< GUM_SCALAR > * buildImpl() const
Returns a pointer over an empty gum::MultiDimImplementation of the good type for this PRMAggregate...
const std::string & name() const
Returns the name of this object.
Definition: PRMObject_inl.h:35
AggregateType __agg_type
The AggregateType of this aggregate.
Definition: PRMAggregate.h:261
virtual ~PRMAggregate()
Destructor.
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::_addParent().
Abstract class representing an element of PRM class.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void setLabel(Idx idx)
Set the aggregator&#39;s label.
virtual PRMAttribute< GUM_SCALAR > * getCastDescendant() const
See gum::PRMClassElement::elt_type().
PRMAggregate< GUM_SCALAR > & operator=(const PRMAggregate< GUM_SCALAR > &source)
Copy operator. Don&#39;t use it.
std::shared_ptr< Idx > sharedLabel() const
Returns the shared_ptr holding this Aggregate label.
PRMAggregate(const std::string &name, AggregateType aggType, const PRMType &rvType)
Default constructor.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::string __label_value
The AggregateType of this aggregate.
Definition: PRMAggregate.h:272
virtual void addChild(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::_addChild().
const std::string & labelValue() const
See gum::PRMClassElement::elt_type().
std::string toLower(std::string str)
Returns the lowercase version of str.
AggregateType agg_type() const
Returns the aggregate of *this.
This is a decoration of the DiscreteVariable class.
Definition: PRMType.h:63
PRMType * __type
The random variable type of this aggregate It is deleted with the aggregate.
Definition: PRMAggregate.h:265
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::shared_ptr< Idx > __label
Some aggregators applies only on a given label. This attribute must have the concerned Idx...
Definition: PRMAggregate.h:270
virtual Potential< GUM_SCALAR > & cpf()
Aggregates don&#39;t have Potential until they are instantiated as PRMAttribute, so this will raise an Op...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
AggregateType
The different type of aggregates we can have.
Definition: PRMAggregate.h:80
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual PRMType & type()
See gum::PRMClassElement::type().
bool hasLabel() const
Returns true if the label is defined.
A PRMClass is an object of a PRM representing a fragment of a Bayesian Network which can be instantia...
Definition: PRMClass.h:66
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
Definition: types.h:53
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:61
Idx label() const
Returns the label&#39;s index on which this aggregate applies.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.