ProteoWizard
Classes | Functions | Variables
MatchedFilterTest.cpp File Reference
#include "MatchedFilter.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <complex>
#include <cstring>
#include <typeinfo>

Go to the source code of this file.

Classes

struct  OneMinusAbs
 

Functions

void test_SampledData ()
 
complex< double > OneMinusAbsComplex (double d)
 
template<typename Kernel >
void test_createFilter (const Kernel &f)
 
template<typename Kernel >
void test_createFilters (const Kernel &f)
 
template<typename Kernel >
void test_compute (const Kernel &f)
 
template<typename Kernel >
void test_kernel (const Kernel &kernel)
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

◆ test_SampledData()

void test_SampledData ( )

Definition at line 38 of file MatchedFilterTest.cpp.

39{
40 if (os_) *os_ << "test_SampledData()\n";
41 using namespace MatchedFilter;
42
43 SampledData<DxD> sd;
44 sd.domain = make_pair(0.0, 2.0);
45 sd.samples.push_back(10);
46 sd.samples.push_back(11);
47 sd.samples.push_back(12);
48 sd.samples.push_back(13);
49 sd.samples.push_back(14);
50
51 if (os_) *os_ << sd << endl;
52
53 if (os_) *os_ << "domainWidth: " << sd.domainWidth() << endl;
54 unit_assert(sd.domainWidth() == 2.0);
55
56 if (os_) *os_ << "dx: " << sd.dx() << endl;
57 unit_assert(sd.dx() == .5);
58
59 for (unsigned int i=0; i<sd.samples.size(); i++)
60 {
61 if (os_) *os_ << "x(" << i << "): " << sd.x(i) << endl;
62 unit_assert(sd.x(i) == i * .5);
63 }
64
65 unsigned int count = 0;
66 for (double x=-.2; x<2.3; x+=.1, count++)
67 {
68 //if (os_) *os_ << "sampleIndex(" << x << "): " << sd.sampleIndex(x) << endl;
69 unit_assert(sd.sampleIndex(x) == count/5);
70 //if (os_) *os_ << "sample(" << x << "): " << sd.sample(x) << endl;
71 unit_assert(sd.sample(x) == 10 + count/5);
72 }
73}
KernelTraitsBase< Kernel >::space_type::abscissa_type x
ostream * os_
#define unit_assert(x)
Definition unit.hpp:85

References os_, unit_assert, and x.

Referenced by main().

◆ OneMinusAbsComplex()

complex< double > OneMinusAbsComplex ( double  d)

Definition at line 86 of file MatchedFilterTest.cpp.

87{
88 return (d>=-1 && d<=1) ? 1 - abs(d) : 0;
89}

Referenced by main().

◆ test_createFilter()

template<typename Kernel >
void test_createFilter ( const Kernel &  f)

Definition at line 93 of file MatchedFilterTest.cpp.

94{
95 using namespace MatchedFilter;
96
97 if (os_) *os_ << "test_createFilter() " << typeid(f).name() << endl;
98
99 int sampleRadius = 4;
100 double dx = .25;
101 double shift = 0;
102
103 typedef typename KernelTraits<Kernel>::filter_type filter_type;
104 typedef typename KernelTraits<Kernel>::abscissa_type abscissa_type;
105 typedef typename KernelTraits<Kernel>::ordinate_type ordinate_type;
106
107 filter_type filter = details::createFilter(f, sampleRadius, dx, shift);
108
109 if (os_)
110 {
111 copy(filter.begin(), filter.end(), ostream_iterator<ordinate_type>(*os_, " "));
112 *os_ << endl;
113 }
114
115 unit_assert((int)filter.size() == sampleRadius*2 + 1);
116 for (int i=-sampleRadius; i<=sampleRadius; ++i)
117 unit_assert(filter[sampleRadius+i] == f(i*dx - shift));
118
119 if (os_) *os_ << endl;
120}
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

References os_, and unit_assert.

Referenced by test_kernel().

◆ test_createFilters()

template<typename Kernel >
void test_createFilters ( const Kernel &  f)

Definition at line 124 of file MatchedFilterTest.cpp.

125{
126 using namespace MatchedFilter;
127
128 if (os_) *os_ << "test_createFilters() " << typeid(f).name() << endl;
129
130 int sampleRadius = 2;
131 int subsampleFactor = 4;
132 double dx = 1;
133
134 typedef typename KernelTraits<Kernel>::filter_type filter_type;
135 typedef typename KernelTraits<Kernel>::ordinate_type ordinate_type;
136 vector<filter_type> filters = details::createFilters(f,
137 sampleRadius,
138 subsampleFactor,
139 dx);
140
141 // verify filter count
142 unit_assert((int)filters.size() == subsampleFactor);
143
144 for (typename vector<filter_type>::const_iterator it=filters.begin(); it!=filters.end(); ++it)
145 {
146 if (os_)
147 {
148 copy(it->begin(), it->end(), ostream_iterator<ordinate_type>(*os_, " "));
149 *os_ << endl;
150 }
151
152 // verify filter size
153 unit_assert((int)it->size() == sampleRadius*2 + 1);
154
155 // verify filter normalization
156 double sum = 0;
157 for (typename filter_type::const_iterator jt=it->begin(); jt!=it->end(); ++jt)
158 sum += norm(complex<double>(*jt));
159 unit_assert_equal(sum, 1, 1e-14);
160 }
161
162 if (os_) *os_ << endl;
163}
#define unit_assert_equal(x, y, epsilon)
Definition unit.hpp:99

References os_, unit_assert, and unit_assert_equal.

Referenced by test_kernel().

◆ test_compute()

template<typename Kernel >
void test_compute ( const Kernel &  f)

Definition at line 167 of file MatchedFilterTest.cpp.

168{
169 using namespace MatchedFilter;
170
171 if (os_) *os_ << "test_compute() " << typeid(f).name() << endl;
172
173 typename KernelTraits<Kernel>::sampled_data_type data;
174 data.domain = make_pair(0, 10);
175 data.samples.resize(11);
176 data.samples[5] = 1.;
177
178 if (os_) *os_ << "data: " << data << endl;
179
180 int sampleRadius = 2;
181 int sampleFactor = 4;
182
183 typedef typename KernelTraits<Kernel>::correlation_data_type CorrelationData;
184
185 CorrelationData correlationData =
186 computeCorrelationData(data, f, sampleRadius, sampleFactor);
187
188 if (os_) *os_ << "correlationData: " << correlationData << endl;
189
190 unit_assert(correlationData.samples.size() == 41);
191 unit_assert(abs(correlationData.samples[20].dot - 1.) < 1e-12);
192}
KernelTraits< Kernel >::correlation_data_type computeCorrelationData(const typename KernelTraits< Kernel >::sampled_data_type &data, const Kernel &kernel, int sampleRadius, int subsampleFactor)

References os_, and unit_assert.

Referenced by test_kernel().

◆ test_kernel()

template<typename Kernel >
void test_kernel ( const Kernel &  kernel)

Definition at line 196 of file MatchedFilterTest.cpp.

197{
198 if (os_) *os_ << "***************************************************************\n";
199 if (os_) *os_ << "test_kernel() " << typeid(kernel).name() << endl;
200 if (os_) *os_ << "***************************************************************\n";
201 if (os_) *os_ << endl;
202
203 test_createFilter(kernel);
204 test_createFilters(kernel);
205 test_compute(kernel);
206}
void test_createFilter(const Kernel &f)
void test_createFilters(const Kernel &f)
void test_compute(const Kernel &f)

References os_, test_compute(), test_createFilter(), and test_createFilters().

Referenced by main().

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 209 of file MatchedFilterTest.cpp.

210{
211 TEST_PROLOG(argc, argv)
212
213 try
214 {
215 if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
216 if (os_) *os_ << "MatchedFilterTest\n";
217
221
222 }
223 catch (exception& e)
224 {
225 TEST_FAILED(e.what())
226 }
227 catch (...)
228 {
229 TEST_FAILED("Caught unknown exception.")
230 }
231
233}
void test_SampledData()
complex< double > OneMinusAbsComplex(double d)
void test_kernel(const Kernel &kernel)
#define TEST_EPILOG
Definition unit.hpp:183
#define TEST_FAILED(x)
Definition unit.hpp:177
#define TEST_PROLOG(argc, argv)
Definition unit.hpp:175

References OneMinusAbsComplex(), os_, TEST_EPILOG, TEST_FAILED, test_kernel(), TEST_PROLOG, and test_SampledData().

Variable Documentation

◆ os_

ostream* os_ = 0