aGrUM  0.14.2
amplitude_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #include <sstream>
28 #include <vector>
29 
30 // to ease parser in IDEs
33 
34 namespace gum {
35 
36  namespace aggregator {
37  template < typename GUM_SCALAR >
39  MultiDimAggregator< GUM_SCALAR >() {
40  GUM_CONSTRUCTOR(Amplitude);
41  }
42 
43  template < typename GUM_SCALAR >
44  INLINE
46  MultiDimAggregator< GUM_SCALAR >(from) {
47  GUM_CONS_CPY(Amplitude);
48  }
49 
50  template < typename GUM_SCALAR >
52  GUM_DESTRUCTOR(Amplitude);
53  }
54 
55  template < typename GUM_SCALAR >
56  INLINE std::string Amplitude< GUM_SCALAR >::aggregatorName() const {
57  std::stringstream ss;
58  ss << "amplitude";
59  return ss.str();
60  }
61 
62  template < typename GUM_SCALAR >
65  return new Amplitude< GUM_SCALAR >();
66  }
67 
68  template < typename GUM_SCALAR >
70  // we assume that every (parent) variable has the same domainSize
71  if (i.nbrDim() < 2) return 0;
72 
73  Idx min = i.val(1);
74  Idx max = i.val(1);
75 
76  for (Idx j = 2; j < this->nbrDim(); j++) {
77  Idx m = i.val(j);
78  if (m < min) min = m;
79  if (m > max) max = m;
80  }
81  return max - min; // multiDimAggregator::get will truncate if needed.
82  }
83 
84  template < typename GUM_SCALAR >
86  Idx i1,
87  Idx i2,
88  bool& stop_iteration) const {
89  return 0;
90  }
91 
92  } // namespace aggregator
93 } // namespace gum
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
virtual Idx _fold(const DiscreteVariable &v, Idx i1, Idx i2, bool &stop_iteration) const
_fold is applied on value i1 for variable v. the actual result for precedent applications is i2...
Definition: amplitude_tpl.h:85
median aggregator
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Abstract base class for all multi dimensionnal containers.
<agrum/multidim/aggregators/multiDimAggregator.h>
Idx val(Idx i) const
Returns the current value of the variable at position i.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
This method creates a clone of this object, withouth its content (including variable), you must use this method if you want to ensure that the generated object has the same type than the object containing the called newFactory() For example :
Definition: amplitude_tpl.h:64
MultiDimAggregator.
virtual Idx nbrDim() const override
Returns the number of vars in the multidimensional container.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
Size Idx
Type for indexes.
Definition: types.h:50
amplitude aggregator
Definition: amplitude.h:52
virtual Idx _buildValue(const gum::Instantiation &i) const
by default, _buildValue uses a "fold" scheme and the user has to implement _neutralElt and _fold but ...
Definition: amplitude_tpl.h:69
virtual std::string aggregatorName() const
Definition: amplitude_tpl.h:56