aGrUM  0.16.0
PRMAggregate_tpl.h
Go to the documentation of this file.
1 
30 #include <climits>
31 
41 
42 namespace gum {
43  namespace prm {
44 
45  template < typename GUM_SCALAR >
47  AggregateType aggType,
48  const PRMType& rvType) :
49  PRMClassElement< GUM_SCALAR >(name),
50  __agg_type(aggType), __type(new PRMType(rvType)),
51  __label(std::shared_ptr< Idx >(new Idx(INT_MAX))) {
52  GUM_CONSTRUCTOR(PRMAggregate);
53  this->_safeName =
54  PRMObject::LEFT_CAST() + __type->name() + PRMObject::RIGHT_CAST() + name;
55  this->__type->variable().setName(name);
56  }
57 
58  template < typename GUM_SCALAR >
60  AggregateType aggType,
61  const PRMType& rvType,
62  Idx label) :
63  PRMClassElement< GUM_SCALAR >(name),
64  __agg_type(aggType), __type(new PRMType(rvType)),
65  __label(std::shared_ptr< Idx >(new Idx(label))) {
66  GUM_CONSTRUCTOR(PRMAggregate);
67  this->_safeName =
68  PRMObject::LEFT_CAST() + __type->name() + PRMObject::RIGHT_CAST() + name;
69  this->__type->variable().setName(name);
70  }
71 
72  template < typename GUM_SCALAR >
74  GUM_DESTRUCTOR(PRMAggregate);
75  delete __type;
76  }
77 
78  template < typename GUM_SCALAR >
80  const PRMAggregate< GUM_SCALAR >& source) :
81  PRMClassElement< GUM_SCALAR >(source) {
82  GUM_CONS_CPY(PRMAggregate);
83  GUM_ERROR(FatalError, "illegal call to gum::PRMAggregate copy constructor.");
84  }
85 
86  template < typename GUM_SCALAR >
89  GUM_ERROR(FatalError, "illegal call to gum::PRMAggregate copy operator.");
90  }
91 
92  template < typename GUM_SCALAR >
95  return this->prm_aggregate;
96  }
97 
98  template < typename GUM_SCALAR >
101  return __agg_type;
102  }
103 
104  template < typename GUM_SCALAR >
106  if (*__label != INT_MAX) return *__label;
107  GUM_ERROR(OperationNotAllowed, "no label defined for this aggregate");
108  }
109 
110  template < typename GUM_SCALAR >
111  INLINE const std::string& PRMAggregate< GUM_SCALAR >::labelValue() const {
112  return __label_value;
113  }
114 
115  template < typename GUM_SCALAR >
117  (*__label) = idx;
118  }
119 
120  template < typename GUM_SCALAR >
121  INLINE void PRMAggregate< GUM_SCALAR >::setLabel(const std::string& value) {
122  __label_value = value;
123  }
124 
125  template < typename GUM_SCALAR >
127  return *__label != INT_MAX;
128  }
129 
130  template < typename GUM_SCALAR >
132  return *__type;
133  }
134 
135  template < typename GUM_SCALAR >
137  return *__type;
138  }
139 
140  template < typename GUM_SCALAR >
142  GUM_ERROR(OperationNotAllowed, "This is an aggregate.");
143  }
144 
145  template < typename GUM_SCALAR >
147  GUM_ERROR(OperationNotAllowed, "This is an aggregate.");
148  }
149 
150  template < typename GUM_SCALAR >
153  switch (agg_type()) {
154  case AggregateType::MIN: {
155  return new aggregator::Min< GUM_SCALAR >();
156  }
157  case AggregateType::MAX: {
158  return new aggregator::Max< GUM_SCALAR >();
159  }
160  case AggregateType::OR: {
161  return new aggregator::Or< GUM_SCALAR >();
162  }
163  case AggregateType::AND: {
164  return new aggregator::And< GUM_SCALAR >();
165  }
166  case AggregateType::AMPLITUDE: {
168  }
169  case AggregateType::MEDIAN: {
171  }
172  case AggregateType::EXISTS: {
173  return new aggregator::Exists< GUM_SCALAR >(label());
174  }
175  case AggregateType::FORALL: {
176  return new aggregator::Forall< GUM_SCALAR >(label());
177  }
178  case AggregateType::COUNT: {
179  return new aggregator::Count< GUM_SCALAR >(label());
180  }
181  default: {
182  GUM_ERROR(OperationNotAllowed, "Unknown aggregator.");
183  }
184  }
185  return nullptr;
186  }
187 
188  // See gum::PRMClassElement<GUM_SCALAR>::_addParent().
189  template < typename GUM_SCALAR >
191  const PRMClassElement< GUM_SCALAR >& elt) {}
192 
193  // See gum::PRMClassElement<GUM_SCALAR>::_addChild().
194  template < typename GUM_SCALAR >
196  const PRMClassElement< GUM_SCALAR >& elt) {}
197 
198  template < typename GUM_SCALAR >
202 
203  try {
204  cast =
205  new PRMScalarAttribute< GUM_SCALAR >(this->name(), type().superType());
206  } catch (NotFound&) {
208  "this PRMAggregate can not have cast descendant");
209  }
210 
211  cast->addParent(*this);
212  const DiscreteVariable& my_var = type().variable();
213  DiscreteVariable& cast_var = cast->type().variable();
214  Instantiation inst(cast->cpf());
215 
216  for (inst.setFirst(); !inst.end(); inst.inc()) {
217  if (type().label_map()[inst.val(my_var)] == inst.val(cast_var)) {
218  cast->cpf().set(inst, 1);
219  } else {
220  cast->cpf().set(inst, 0);
221  }
222  }
223 
224  return cast;
225  }
226 
227  template < typename GUM_SCALAR >
228  INLINE std::shared_ptr< Idx > PRMAggregate< GUM_SCALAR >::sharedLabel() const {
229  return __label;
230  }
231 
232  template < typename GUM_SCALAR >
233  INLINE void
234  PRMAggregate< GUM_SCALAR >::sharedLabel(std::shared_ptr< Idx > label) {
235  this->__label = label;
236  }
237 
238  } /* namespace prm */
239 } /* namespace gum */
aGrUM&#39;s Potential is a multi-dimensional array with tensor operators.
Definition: potential.h:60
or aggregator
Definition: or.h:56
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
STL namespace.
Abstract class representing an element of PRM class.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Base class for discrete random variable.
virtual PRMType & type()
See gum::PRMClassElement::type().
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.
forall aggregator
Definition: forall.h:55
virtual const Potential< GUM_SCALAR > & cpf() const
See gum::PRMClassElement::cpf().
PRMAggregate(const std::string &name, AggregateType aggType, const PRMType &rvType)
Default constructor.
And aggregator.
Definition: and.h:55
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
exists aggregator
Definition: exists.h:54
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.
This is a decoration of the DiscreteVariable class.
Definition: PRMType.h:63
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
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
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.
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
Definition: types.h:53
max aggregator
Definition: max.h:54
PRMAttribute is a member of a Class in a PRM.
Definition: PRMAttribute.h:61
median aggregator
Definition: median.h:60
virtual void addParent(const PRMClassElement< GUM_SCALAR > &elt)
See gum::PRMClassElement::_addParent().
<agrum/PRM/elements/scalarAttribute.h>
amplitude aggregator
Definition: amplitude.h:55
min aggregator
Definition: min.h:53
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
ClassElementType
Returns true if obj_ptr is of type PRMReferenceSlot.
count aggregator
Definition: count.h:57