31 using namespace pwiz::util;
32 using namespace pwiz::frequency;
40 if (
os_) *
os_ <<
"****************************************************\n";
41 if (
os_) *
os_ <<
"testDifferenceQuotient()\n";
43 using namespace DerivativeTest;
45 class TestFunction :
public VectorFunction<double>
51 virtual unsigned int argumentCount()
const {
return 2;}
52 virtual unsigned int valueCount()
const {
return 3;}
54 virtual ublas::vector<double> operator()(ublas::vector<double>
x)
const
56 if (x.size() != argumentCount())
57 throw logic_error(
"[TestFunction::()] Wrong argument count.");
59 ublas::vector<double> result(3);
60 result(0) =
x(0)*
x(0);
61 result(1) =
x(0)*
x(1);
62 result(2) =
x(1)*
x(1);
69 ublas::vector<double> args(2);
70 args(0) = 5; args(1) = 7;
71 if (
os_) *
os_ <<
"f(5,7): " << f(args) << endl;
73 if (
os_) f.printDifferenceQuotientSequence(args, *
os_);
78 ublas::matrix<double> d(2,3);
86 const double delta = 1
e-9;
100 virtual double operator()(
double x,
const ublas::vector<double>& p)
const
107 virtual ublas::vector<double> dp(
double x,
const ublas::vector<double>& p)
const
110 ublas::vector<double> v(2);
112 v(1) = -A_*x_*sinBx_;
117 virtual ublas::matrix<double> dp2(
double x,
const ublas::vector<double>& p)
const
120 ublas::matrix<double> m(2,2);
122 m(1,0) = m(0,1) = -x_*sinBx_;
123 m(1,1) = -A_*x_*x_*cosBx_;
130 void preprocess(
double x,
const ublas::vector<double>& p)
const
133 if (p.size() != parameterCount())
134 throw logic_error(
"[Parabola] Wrong parameter size.");
137 if (x!=x_ || p(0)!=A_ || p(1)!=B_)
162 if (
os_) *
os_ <<
"****************************************************\n";
163 if (
os_) *
os_ <<
"testDerivatives()\n";
167 ublas::vector<double> p(2);
171 for (
int i=0; i<8; i++)
178 if (
os_) *
os_ <<
"****************************************************\n";
179 if (
os_) *
os_ <<
"testErrorFunction()\n";
183 ublas::vector<double> p(2);
187 ParametrizedCosine::ErrorFunction::Data data;
188 typedef ParametrizedCosine::ErrorFunction::Datum
Datum;
189 data.push_back(Datum(0,3));
190 data.push_back(Datum(M_PI/2,0));
192 ParametrizedCosine::ErrorFunction
e(f, data);
193 if (
os_) *
os_ <<
"error: " <<
e(p) << endl;
195 DerivativeTest::testDerivatives<double>(
e, p,
os_);
197 if (
os_) *
os_ <<
"8*pi^2: " << 8*M_PI*M_PI << endl;
203 if (
os_) *
os_ <<
"****************************************************\n";
204 if (
os_) *
os_ <<
"testErrorLorentzian()\n";
208 ublas::vector<double> p(4);
212 p(TruncatedLorentzian::F0) = 0;
214 TruncatedLorentzian::ErrorFunction::Data data;
215 typedef TruncatedLorentzian::ErrorFunction::Datum
Datum;
216 data.push_back(Datum(0,3));
217 data.push_back(Datum(M_PI/2,0));
219 TruncatedLorentzian::ErrorFunction
e(f, data);
220 if (
os_) *
os_ <<
"error: " <<
e(p) << endl;
222 DerivativeTest::testDerivatives< complex<double> >(
e, p,
os_);
226 int main(
int argc,
char* argv[])
232 if (argc>1 && !strcmp(argv[1],
"-v"))
os_ = &cout;
233 if (
os_) *
os_ <<
"ParametrizedFunctionTest\n";