31 using namespace pwiz::math;
32 using namespace pwiz::util;
40 if (
os_) *
os_ <<
"test_SampledData()\n";
41 using namespace MatchedFilter;
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);
51 if (
os_) *
os_ << sd << endl;
53 if (
os_) *
os_ <<
"domainWidth: " << sd.domainWidth() << endl;
56 if (
os_) *
os_ <<
"dx: " << sd.dx() << endl;
59 for (
unsigned int i=0; i<sd.samples.size(); i++)
61 if (
os_) *
os_ <<
"x(" << i <<
"): " << sd.x(i) << endl;
65 unsigned int count = 0;
66 for (
double x=-.2;
x<2.3;
x+=.1, count++)
81 double operator()(
double d)
const {
return (d>=-1 && d<=1) ? 1 - abs(d) : 0;}
88 return (d>=-1 && d<=1) ? 1 - abs(d) : 0;
92 template <
typename Kernel>
95 using namespace MatchedFilter;
97 if (
os_) *
os_ <<
"test_createFilter() " <<
typeid(f).name() << endl;
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;
111 copy(filter.begin(), filter.end(), ostream_iterator<ordinate_type>(*
os_,
" "));
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));
123 template <
typename Kernel>
126 using namespace MatchedFilter;
128 if (
os_) *
os_ <<
"test_createFilters() " <<
typeid(f).name() << endl;
130 int sampleRadius = 2;
131 int subsampleFactor = 4;
134 typedef typename KernelTraits<Kernel>::filter_type filter_type;
135 typedef typename KernelTraits<Kernel>::ordinate_type ordinate_type;
142 unit_assert((
int)filters.size() == subsampleFactor);
144 for (
typename vector<filter_type>::const_iterator it=filters.begin(); it!=filters.end(); ++it)
148 copy(it->begin(), it->end(), ostream_iterator<ordinate_type>(*
os_,
" "));
153 unit_assert((
int)it->size() == sampleRadius*2 + 1);
157 for (
typename filter_type::const_iterator jt=it->begin(); jt!=it->end(); ++jt)
158 sum +=
norm(complex<double>(*jt));
166 template <
typename Kernel>
169 using namespace MatchedFilter;
171 if (
os_) *
os_ <<
"test_compute() " <<
typeid(f).name() << endl;
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.;
178 if (
os_) *
os_ <<
"data: " << data << endl;
180 int sampleRadius = 2;
181 int sampleFactor = 4;
183 typedef typename KernelTraits<Kernel>::correlation_data_type CorrelationData;
185 CorrelationData correlationData =
188 if (
os_) *
os_ <<
"correlationData: " << correlationData << endl;
191 unit_assert(abs(correlationData.samples[20].dot - 1.) < 1
e-12);
195 template <
typename Kernel>
198 if (
os_) *
os_ <<
"***************************************************************\n";
199 if (
os_) *
os_ <<
"test_kernel() " <<
typeid(kernel).name() << endl;
200 if (
os_) *
os_ <<
"***************************************************************\n";
209 int main(
int argc,
char* argv[])
215 if (argc>1 && !strcmp(argv[1],
"-v"))
os_ = &cout;
216 if (
os_) *
os_ <<
"MatchedFilterTest\n";