ProteoWizard
gaussfiltertest.cpp
Go to the documentation of this file.
1 //
2 // $Id: gaussfiltertest.cpp 5313 2013-12-17 18:06:54Z chambm $
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 
23 
28 namespace {
29  using namespace pwiz::util;
30 
31  void testGaussian()
32  {
33  std::vector<double> x;
34  std::vector<double> y;
35  double epsilon = 5e-5;
36  //generate x values
37  ralab::base::base::seq(-10.,10.,1.,x);
38  std::transform(x.begin(),x.end(),std::back_inserter(y),ralab::base::filter::utilities::Gauss<double>(0.,1.));
39  double result[21] ={ 7.694599e-23, 1.027977e-18, 5.052271e-15, 9.134720e-12, 6.075883e-09,
40  1.486720e-06, 1.338302e-04, 4.431848e-03, 5.399097e-02, 2.419707e-01,
41  3.989423e-01, 2.419707e-01, 5.399097e-02, 4.431848e-03, 1.338302e-04,
42  1.486720e-06, 6.075883e-09, 9.134720e-12, 5.052271e-15, 1.027977e-18,
43  7.694599e-23};
44 
45  unit_assert(std::equal(y.begin(),y.end(),result,ralab::base::resample::DaCompFunctor<double>(epsilon)));
46  double sumfilter = std::accumulate(y.begin(),y.end(),0.);
47  std::pair<double,double> tmp;
48  ralab::base::stats::scale(y.begin(),y.end(),tmp,true);
49  std::transform(y.begin(),y.end(),y.begin(),std::bind2nd(std::plus<double>(),( 1./x.size() ) ) );
50  sumfilter = std::accumulate(y.begin(),y.end(),0.);
51  unit_assert_equal(sumfilter,1.,epsilon);
52  }
53 
54  void testGauss_1deriv()
55  {
56  //code to compare goes here
57  std::vector<double> x;
58  std::vector<double> y;
59  double epsilon = 5e-5;
60  //generate x values
61  ralab::base::base::seq(-10.,10.,1.,x);
62  std::transform(x.begin(),x.end(),std::back_inserter(y),ralab::base::filter::utilities::Gauss_1deriv<double>(.0,1.));
63  double firstderiv[21] = {
64  7.694599e-22, 9.251796e-18, 4.041817e-14, 6.394304e-11, 3.645530e-08, 7.433598e-06, 5.353209e-04 , 1.329555e-02, 1.079819e-01, 2.419707e-01,
65  0.000000e+00, -2.419707e-01, -1.079819e-01, -1.329555e-02, -5.353209e-04, -7.433598e-06, -3.645530e-08, -6.394304e-11 -4.041817e-14 -9.251796e-18,
66  -7.694599e-22
67  };
68 
69  // std::vector<double> fristderivV(firstderiv,firstderiv+21);
70  unit_assert(std::equal(y.begin(),y.end(),firstderiv,ralab::base::resample::DaCompFunctor<double>(epsilon)));
71  std::pair<double,double> tmp;
72  ralab::base::stats::scale(y.begin(),y.end(),tmp,true);
73  double sumfilter = std::accumulate(y.begin(),y.end(),0.0);
74  unit_assert_equal(sumfilter,0.,epsilon);
76  sumfilter = std::accumulate(x.begin(),x.end(),0.0);
77  t;
78  }
79 
80  void testGetGaussian()
81  {
82  std::vector<double> xx;
84  unit_assert(xx.size() == 121);
85  unit_assert_equal(std::accumulate(xx.begin(),xx.end(),0.),1.,1e-6);
87  }
88 
89 } //end namespace
90 
91 
92 int main(int argc, char **argv) {
93  testGetGaussian();
94  testGauss_1deriv();
95  testGetGaussian();
96 }
const double epsilon
Definition: DiffTest.cpp:41
#define unit_assert_equal(x, y, epsilon)
Definition: unit.hpp:99
void seq(TReal from, TReal to, std::vector< TReal > &result)
generates the sequence from, from+/-1, ..., to (identical to from:to).
Definition: base.hpp:49
TReal getGaussianFilterQuantile(std::vector< TReal > &gauss, TReal fwhm=20, TReal quantile=0.01)
generate the gauss filter function for filtering of peaks with fwhm (full width at half max) ...
Definition: gaussfilter.hpp:59
int main(int argc, char **argv)
void scale(InputIterator begin, InputIterator end, std::pair< typename std::iterator_traits< InputIterator >::value_type, typename std::iterator_traits< InputIterator >::value_type > &scaled, bool center=true, bool scale=true)
scale centers and/or scales all values from begin in to end.
Definition: scale.hpp:77
TReal getGaussianFilter(std::vector< TReal > &gauss, TReal fwhm=20)
generate the gauss filter function for filtering of peaks with fwhm (full width at half max) ...
Definition: gaussfilter.hpp:40
KernelTraitsBase< Kernel >::space_type::abscissa_type x
TReal getGaussian1DerFilter(std::vector< TReal > &gauss1d, TReal fwhm=20)
generate first derivative Gauss
Definition: gaussfilter.hpp:87
KernelTraitsBase< Kernel >::space_type::ordinate_type y
First derivative of Gaussian.
Definition: gauss.hpp:71
#define unit_assert(x)
Definition: unit.hpp:85
Da Comparator - constant mass error.