proj home

Files   Classes   Functions   Hierarchy  

explorepdtest.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <cmath>
00003 #include <iomanip>
00004 using namespace std;
00005 
00006 #include <print.h>
00007 #include <commandline.h>
00008 
00009 #include <probsysequ01.h>
00010 #include <explorepd1.h>
00011 #include <lineoptimizergold.h>
00012 #include <exploreh.h>
00013 
00014 #include <explorepdtest.h>
00015 
00016 static double h0step=0.2;
00017 
00018 void explorepdtest01(int argc, char** argv)
00019 {
00020   cout << "explore 1st order partial derivative with the golden ratio line search" << endl;
00021   cout << "  k=3 lineiter=10 are defaults." << endl;
00022 
00023   typedef exploreh<probsysequ01,double*,double> exp2;
00024   typedef lineoptimizergold<probsysequ01&,double*,double*,double> lnmin;
00025 
00026   commandline cmd(argc,argv);
00027   uint lineiter(10);
00028   cmd.mapvar(lineiter,"lineiter");
00029   uint k(3);
00030   cmd.mapvar(k,"k");
00031 
00032   explorepd1< exp2, lnmin > w(2,lineiter,h0step);
00033 
00034   cmd.mapvar(w.linet0,"t0");
00035   cmd.mapvar(w.linet1,"t1");
00036 
00037   double x0[2] = { 0.5, 0.5 };
00038   w.reset(x0);
00039 
00040   for (uint i=0; i<k; ++i)
00041   {
00042 //cout << printvecfunc(w.xi,2) << endl;
00043     ++w;
00044 //    cout << SHOW(w.fn.counter) << endl;
00045   }
00046   cout << left << setw(4) << "k";
00047   cout << left << setw(15) << "fmin";
00048   cout << "function counter" << endl;
00049   cout << left << setw(4) << k;
00050   cout << left << setw(15) << scientific << w.fmin;
00051   cout << left << setw(4) << w.fn.counter << endl;
00052   //cout << scientific << SHOW(w.fmin) << endl;
00053   //cout << SHOW(w.fn.counter) << endl;
00054 
00055 /*
00056   long double y0((long double)0.2);
00057   long double y1((long double)2.0/(long double)3.0);
00058   long double dist = (y0-w.xi[0])*(y0-w.xi[0]) + (y1-w.xi[1])*(y1-w.xi[1]);
00059 
00060 
00061   cout << "Compare with true solution" << endl;
00062   cout << "fn-count, k, lineiter, distance" << endl;
00063   cout << w.fn.counter << "  ";
00064   cout << k << "  ";
00065   cout << lineiter << "  ";
00066   cout << scientific << dist << endl;
00067 */
00068 
00069 }
00070 
00071 
00072 void explorepdtest02(int argc, char** argv)
00073 {
00074   commandline cmd(argc,argv);
00075   uint k(3);
00076   cmd.mapvar(k,"k");
00077 
00078   exploreh<probsysequ01,double*,double> g(2,h0step,50000);
00079 
00080   double x0[2] = { 0.5, 0.5 };
00081 
00082   g.reset(x0);
00083 
00084   //g.print(cout);
00085 
00086   for (uint i=0; i<k; ++i)
00087   {
00088     ++g;
00089   }
00090 
00091   //cout << scientific << SHOW(g.fmin) << endl;
00092 
00093   //g.print(cout);
00094   //cout << SHOW(g.fn.counter) << endl;
00095 
00096 
00097   cout << left << setw(4) << "k";
00098   cout << left << setw(15) << "fmin";
00099   cout << "function counter" << endl;
00100   cout << left << setw(4) << k;
00101   cout << left << setw(15) << scientific << g.fmin;
00102   cout << left << setw(4) << g.fn.counter << endl;
00103 }
00104 
00105 
00106 
00107 

Generated on Fri Mar 4 00:49:29 2011 for Chelton Evans Source by  doxygen 1.5.8