ProteoWizard
filterutilstest.cpp
Go to the documentation of this file.
1 //
2 // $Id: filterutilstest.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 //
22 
23 
28 
29 namespace {
30 using namespace pwiz::util;
31  /*! \brief test filter function */
32  void filterTest()
33  {
34  double epsilon = 0.000001;
35  epsilon;
36  std::vector<double> data;
37  ralab::base::base::seq(-500., 500., .1, data);
38  std::vector<double> y;
39  std::transform(data.begin(), data.end(), std::back_inserter(y), static_cast<double(*)(double)>(sin) );
40 
41  std::vector<double> filt3(21,1./21.); // mean filter
42  double sumfilt = std::accumulate(filt3.begin(), filt3.end(), 0.0 );
43  unit_assert_equal(sumfilt, 1.0,epsilon );
44 
45  std::vector<double> result;
47  y,
48  filt3,
49  result
50  );
51 
53  y,
54  filt3,
55  result,
56  true
57  );
58 
59  result.resize(y.size());
60 
62  y.begin(),
63  y.end(),
64  filt3.begin(),
65  filt3.size(),
66  result.begin(),
67  true
68  );
69 
70  }
71 
72  /*! \brief Evaluate data extension */
73  void testExtendData()
74  {
75  std::vector<int> tmp, res;
77  std::vector<int>::iterator it = ralab::base::filter::utilities::prepareData(tmp.begin(),tmp.end(), 5, res);
78  res.resize(std::distance(res.begin(),it));
79  double ref[] = { 4, 5, 1, 2, 3, 4 ,5, 1, 2};
80 
81  /*std::copy(res.begin(),res.end(),std::ostream_iterator<int>(std::cout," "));
82  std::cout << std::endl;
83  */
84  bool iseq = std::equal(res.begin(),res.end(),ref);
85  unit_assert(iseq);
86 
87  it = ralab::base::filter::utilities::prepareData(tmp.begin(),tmp.end(), 5, res, true);
88  res.resize(std::distance(res.begin(),it));
89 
90  double ref2[] = {2, 1, 1, 2, 3, 4, 5, 5, 4};
91  iseq = std::equal(res.begin(),res.end(),ref2);
92  unit_assert(iseq);
93  }
94 
95 }//end namespace
96 
97 
98 int main(int argc, char **argv) {
99  filterTest();
100  testExtendData();
101 }
102 
103 
104 
105 
106 
TContainer::iterator prepareData(TIterator dataBeg, TIterator dataEnd, size_t fsize, TContainer &res, bool mirror=false)
Example Sequence : 1 2 3 4 5; width 5 and mirror false: 4 5 1 2 3 4 5 1 2, if mirror true than: 2 1 1...
Definition: preparedata.hpp:40
const double epsilon
Definition: DiffTest.cpp:41
void filter_sequence(TIterator dataBeg, TIterator dataEnd, TFilterIterator filterBeg, size_t fsize, TOutputIterator resBeg, bool circular=false, uint32_t sides=2)
Definition: filter.hpp:49
#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
int main(int argc, char **argv)
KernelTraitsBase< Kernel >::space_type::ordinate_type y
#define unit_assert(x)
Definition: unit.hpp:85
void filter(const TContainer &data, const TContainer &filter, TContainer &result, bool circular=false, uint32_t sides=2)
Applies linear convolution (filtering) to a univariate time series.
Definition: filter.hpp:112