yat  0.21pre
UnityScaler.h
1 #ifndef _theplu_yat_normalizer_unity_scaler_
2 #define _theplu_yat_normalizer_unity_scaler_
3 
4 // $Id: UnityScaler.h 4164 2022-03-13 22:47:56Z peter $
5 
6 /*
7  Copyright (C) 2020, 2022 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 #include <numeric>
31 
32 namespace theplu {
33 namespace yat {
34 namespace normalizer {
35 
37  namespace detail {
38  class UnityScalerFactor
39  {
40  public:
41  // return the inverse of the sum of range [first, last)
42  template<typename Iterator>
43  double operator()(Iterator first, Iterator last) const
44  {
45  using traits = typename utility::weighted_iterator_traits<Iterator>;
46  return calculate(first, last, typename traits::type());
47  }
48 
49  private:
50 
51  template<typename Iterator>
52  double calculate(Iterator first, Iterator last,
53  utility::unweighted_iterator_tag tag) const
54  {
55  return 1.0 / std::accumulate(utility::data_iterator(first),
56  utility::data_iterator(last),
57  0.0);
58  }
59 
60 
61  template<typename Iterator>
62  double calculate(Iterator first, Iterator last,
63  utility::weighted_iterator_tag tag) const
64  {
65  statistics::AveragerWeighted averager;
66  add(averager, first, last);
67  return 1.0 / averager.sum_wx();
68  }
69  };
70  }
72 
73 
88  using UnityScaler =
90 
91 }}} // end of namespace normalizer, yat and thep
92 #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:89
Definition: RangeNormalizer.h:64

Generated on Wed Jan 25 2023 03:34:29 for yat by  doxygen 1.8.14