ProteoWizard
determinebinwidth.hpp
Go to the documentation of this file.
1 //
2 // $Id: determinebinwidth.hpp 6090 2014-04-24 15:13:12Z witek96 $
3 //
4 //
5 // Original author: Witold Wolski <wewolski@gmail.com>
6 //
7 // Copyright : ETH Zurich
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 #ifndef DETERMINEBINWIDTH_H
22 #define DETERMINEBINWIDTH_H
23 
24 
25 #include <cmath>
26 #include <boost/assert.hpp>
27 #include <boost/range/algorithm_ext.hpp>
28 #include <boost/bind.hpp>
29 #include <algorithm>
30 
33 
34 
35 namespace ralab
36 {
37  namespace base
38  {
39  namespace resample
40  {
41  template<typename TReal>
42  struct SquareRoot{
43  TReal operator()(TReal x) const{
44  return(sqrt(x));
45  }
46  };
47 
48  struct SamplingWith{
49  std::vector<double> diff_;
50  std::vector<double> summ_;
51  std::vector<double> am_;
52 
53  //expects a sorted sequence
54  template<typename TRealI>
55  double operator()(TRealI begin, TRealI end)
56  {
57  //BOOST_ASSERT(!boost::range::is_sorted(begin,end));
58  typedef typename std::iterator_traits<TRealI>::value_type TReal;
59  std::size_t N = std::distance(begin,end);
60  double am;
61  if(N > 1){
62  diff_.resize(N-1);
63  summ_.resize(N-1);
64  am_.resize(N-1);
65  ralab::base::base::diff(begin,end,diff_.begin(),1);
66 
67  utilities::summ( begin , end, summ_.begin(),1);
68  //square the sum
69  //std::transform(summ_.begin(),summ_.end(),summ_.begin(),boost::bind(sqrt,_1));
70  std::transform(summ_.begin(),summ_.end(),summ_.begin(),SquareRoot<TReal>());
71  std::transform(diff_.begin(),diff_.end(),summ_.begin(),am_.begin(),std::divides<double>());
72  std::sort(am_.begin(),am_.end());
73  am = utilities::determine(am_.begin(),am_.end());
74  }else{
75  am = 0.;
76  }
77  return am;
78  }
79  };
80 
81  }
82  }
83 }
84 
85 
86 #endif // DETERMINEBINWIDTH_H
double operator()(TRealI begin, TRealI end)
OutputIterator diff(InputIterator begin, InputIterator end, OutputIterator destBegin, TN lag)
lagged differences
Definition: diff.hpp:58
OutputIterator summ(InputIterator begin, InputIterator end, OutputIterator destBegin, TN lag=1)
N
Definition: Chemistry.hpp:80
double determine(TRealI begin, TRealI end, double maxj=5.)
EQUISPACEINTERPOL Interpolation on a equidistantly spaced grid.
Definition: base.hpp:39
KernelTraitsBase< Kernel >::space_type::abscissa_type x