ProteoWizard
Classes | Functions | Variables
ParametrizedFunctionTest.cpp File Reference
#include "DerivativeTest.hpp"
#include "TruncatedLorentzian.hpp"
#include "pwiz/utility/misc/unit.hpp"
#include "pwiz/utility/misc/Std.hpp"
#include <cstring>

Go to the source code of this file.

Classes

class  ParametrizedCosine
 

Functions

void testDifferenceQuotient ()
 
void testDerivatives ()
 
void testErrorFunction ()
 
void testErrorLorentzian ()
 
int main (int argc, char *argv[])
 

Variables

ostream * os_ = 0
 

Function Documentation

§ testDifferenceQuotient()

void testDifferenceQuotient ( )

Definition at line 38 of file ParametrizedFunctionTest.cpp.

References epsilon, os_, unit_assert_matrices_equal, and x.

Referenced by main().

39 {
40  if (os_) *os_ << "****************************************************\n";
41  if (os_) *os_ << "testDifferenceQuotient()\n";
42 
43  using namespace DerivativeTest;
44 
45  class TestFunction : public VectorFunction<double>
46  {
47  public:
48 
49  // f(x,y) = (x^2, xy, y^2)
50 
51  virtual unsigned int argumentCount() const {return 2;}
52  virtual unsigned int valueCount() const {return 3;}
53 
54  virtual ublas::vector<double> operator()(ublas::vector<double> x) const
55  {
56  if (x.size() != argumentCount())
57  throw logic_error("[TestFunction::()] Wrong argument count.");
58 
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);
63  return result;
64  }
65  };
66 
67 
68  TestFunction f;
69  ublas::vector<double> args(2);
70  args(0) = 5; args(1) = 7;
71  if (os_) *os_ << "f(5,7): " << f(args) << endl;
72 
73  if (os_) f.printDifferenceQuotientSequence(args, *os_);
74 
75  // f'(x,y) = ((2x, y, 0), (0, x, 2y))
76  // f'(5,7) = ((10, 7, 0), (0, 5, 14))
77 
78  ublas::matrix<double> d(2,3);
79  d(0,0) = 10;
80  d(0,1) = 7;
81  d(0,2) = 0;
82  d(1,0) = 0;
83  d(1,1) = 5;
84  d(1,2) = 14;
85 
86  const double delta = 1e-9;
87  const double epsilon = 1e-5;
88  unit_assert_matrices_equal(d, f.differenceQuotient(args,delta), epsilon);
89 }
const double epsilon
Definition: DiffTest.cpp:41
ostream * os_
KernelTraitsBase< Kernel >::space_type::abscissa_type x
#define unit_assert_matrices_equal(A, B, epsilon)
Definition: unit.hpp:135

§ testDerivatives()

void testDerivatives ( )

Definition at line 160 of file ParametrizedFunctionTest.cpp.

References os_.

Referenced by main().

161 {
162  if (os_) *os_ << "****************************************************\n";
163  if (os_) *os_ << "testDerivatives()\n";
164 
166 
167  ublas::vector<double> p(2);
168  p(0) = 5;
169  p(1) = M_PI/4;
170 
171  for (int i=0; i<8; i++)
173 }
ostream * os_
void testDerivatives()

§ testErrorFunction()

void testErrorFunction ( )

Definition at line 176 of file ParametrizedFunctionTest.cpp.

References os_.

Referenced by main().

177 {
178  if (os_) *os_ << "****************************************************\n";
179  if (os_) *os_ << "testErrorFunction()\n";
180 
182 
183  ublas::vector<double> p(2);
184  p(0) = 4;
185  p(1) = 30;
186 
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));
191 
192  ParametrizedCosine::ErrorFunction e(f, data);
193  if (os_) *os_ << "error: " << e(p) << endl;
194 
195  DerivativeTest::testDerivatives<double>(e, p, os_);
196 
197  if (os_) *os_ << "8*pi^2: " << 8*M_PI*M_PI << endl;
198 }
ostream * os_

§ testErrorLorentzian()

void testErrorLorentzian ( )

Definition at line 201 of file ParametrizedFunctionTest.cpp.

References AlphaI, AlphaR, os_, and Tau.

Referenced by main().

202 {
203  if (os_) *os_ << "****************************************************\n";
204  if (os_) *os_ << "testErrorLorentzian()\n";
205 
206  TruncatedLorentzian f(1);
207 
208  ublas::vector<double> p(4);
212  p(TruncatedLorentzian::F0) = 0;
213 
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));
218 
219  TruncatedLorentzian::ErrorFunction e(f, data);
220  if (os_) *os_ << "error: " << e(p) << endl;
221 
222  DerivativeTest::testDerivatives< complex<double> >(e, p, os_);
223 }
ostream * os_

§ main()

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

Definition at line 226 of file ParametrizedFunctionTest.cpp.

References os_, TEST_EPILOG, TEST_FAILED, TEST_PROLOG, testDerivatives(), testDifferenceQuotient(), testErrorFunction(), and testErrorLorentzian().

227 {
228  TEST_PROLOG(argc, argv)
229 
230  try
231  {
232  if (argc>1 && !strcmp(argv[1],"-v")) os_ = &cout;
233  if (os_) *os_ << "ParametrizedFunctionTest\n";
235  testDerivatives();
238  }
239  catch (exception& e)
240  {
241  TEST_FAILED(e.what())
242  }
243  catch (...)
244  {
245  TEST_FAILED("Caught unknown exception.")
246  }
247 
249 }
#define TEST_EPILOG
Definition: unit.hpp:182
void testErrorFunction()
void testDifferenceQuotient()
void testErrorLorentzian()
ostream * os_
void testDerivatives()
#define TEST_FAILED(x)
Definition: unit.hpp:176
#define TEST_PROLOG(argc, argv)
Definition: unit.hpp:174

Variable Documentation

§ os_

ostream* os_ = 0