aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
amplitude_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief amplitude aggregator
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27  */
28 
29 #include <sstream>
30 #include <vector>
31 
32 // to ease parser in IDEs
33 #include <agrum/tools/multidim/aggregators/amplitude.h>
34 #include <agrum/tools/multidim/aggregators/multiDimAggregator.h>
35 
36 namespace gum {
37 
38  namespace aggregator {
39  template < typename GUM_SCALAR >
40  INLINE Amplitude< GUM_SCALAR >::Amplitude() : MultiDimAggregator< GUM_SCALAR >() {
41  GUM_CONSTRUCTOR(Amplitude);
42  }
43 
44  template < typename GUM_SCALAR >
45  INLINE Amplitude< GUM_SCALAR >::Amplitude(const Amplitude< GUM_SCALAR >& from) :
46  MultiDimAggregator< GUM_SCALAR >(from) {
47  GUM_CONS_CPY(Amplitude);
48  }
49 
50  template < typename GUM_SCALAR >
51  INLINE Amplitude< GUM_SCALAR >::~Amplitude() {
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 >
63  INLINE MultiDimContainer< GUM_SCALAR >* Amplitude< GUM_SCALAR >::newFactory() const {
64  return new Amplitude< GUM_SCALAR >();
65  }
66 
67  template < typename GUM_SCALAR >
68  Idx Amplitude< GUM_SCALAR >::buildValue_(const gum::Instantiation& i) const {
69  // we assume that every (parent) variable has the same domainSize
70  if (i.nbrDim() < 2) return 0;
71 
72  Idx min = i.val(1);
73  Idx max = i.val(1);
74 
75  for (Idx j = 2; j < this->nbrDim(); j++) {
76  Idx m = i.val(j);
77  if (m < min) min = m;
78  if (m > max) max = m;
79  }
80  return max - min; // multiDimAggregator::get will truncate if needed.
81  }
82 
83  template < typename GUM_SCALAR >
84  INLINE Idx Amplitude< GUM_SCALAR >::fold_(const DiscreteVariable& v,
85  Idx i1,
86  Idx i2,
87  bool& stop_iteration) const {
88  return 0;
89  }
90 
91  } // namespace aggregator
92 } // namespace gum