yat  0.18.2pre
UnityScaler.h
1 #ifndef _theplu_yat_normalizer_unity_scaler_
2 #define _theplu_yat_normalizer_unity_scaler_
3 
4 // $Id: UnityScaler.h 3957 2020-07-26 11:44:32Z peter $
5 
6 /*
7  Copyright (C) 2020 Peter Johansson
8 
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10 
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15 
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 #include "RangeNormalizer.h"
26 #include "yat/statistics/AveragerWeighted.h"
27 #include "yat/utility/DataIterator.h"
28 
29 #include <functional>
30 
31 namespace theplu {
32 namespace yat {
33 namespace normalizer {
34 
36  namespace detail {
37  class UnityScalerFactor
38  {
39  public:
40  // return the inverse of the sum of range [first, last)
41  template<typename Iterator>
42  double operator()(Iterator first, Iterator last) const
43  {
44  using traits = typename utility::weighted_iterator_traits<Iterator>;
45  return calculate(first, last, typename traits::type());
46  }
47 
48  private:
49 
50  template<typename Iterator>
51  double calculate(Iterator first, Iterator last,
52  utility::unweighted_iterator_tag tag) const
53  {
54  return 1.0 / std::accumulate(utility::data_iterator(first),
55  utility::data_iterator(last),
56  0.0);
57  }
58 
59 
60  template<typename Iterator>
61  double calculate(Iterator first, Iterator last,
62  utility::weighted_iterator_tag tag) const
63  {
64  statistics::AveragerWeighted averager;
65  add(averager, first, last);
66  return 1.0 / averager.sum_wx();
67  }
68  };
69  }
71 
72 
87  using UnityScaler =
89 
90 }}} // end of namespace normalizer, yat and thep
91 #endif
The Department of Theoretical Physics namespace as we define it.
void add(T &o, ForwardIterator first, ForwardIterator last, const classifier::Target &target)
Definition: utility.h:320
RangeNormalizer< detail::UnityScalerFactor, std::multiplies< double > > UnityScaler
Scale a range to unity.
Definition: UnityScaler.h:88
Definition: RangeNormalizer.h:64

Generated on Tue Sep 7 2021 17:32:32 for yat by  doxygen 1.8.14