proj home

Files   Classes   Functions   Hierarchy  

minimizecomparetest.cpp

Go to the documentation of this file.
00001 
00002 //#include <cassert>
00003 ;
00004 #include <iostream>
00005 using namespace std;
00006 
00007 #include <commandline.h>
00008 #include <print.h>
00009 #include <random.h>
00010 
00011 #include <minimizecomparetest.h>
00012 
00013 #include <exploreh.h>
00014 #include <leastsqrs.h>
00015 //#include <probparab.h>
00016 #include <probsysequ01.h>
00017 #include <patternsearch.h>
00018 #include <patternsearchD2.h>
00019 #include <explorequad.h>
00020 #include <explorerand.h>
00021 #include <exploreline.h>
00022 #include <lineoptimizergold.h>
00023 // #includ <powell02.h>
00024 #include <probrosenbrock.h>
00025 //#include <linepathd1.h>
00026 #include <lineoptimizergold2.h>
00027 
00028 
00029 void minimizecomparetest01(int argc, char** argv)
00030 {
00031   cout << "Testing optimizers for a 2 variable non-linear system" << endl << endl;
00032 
00033   commandline cmd(argc,argv);
00034 
00035   uint counter(200);
00036   cmd.mapvar(counter,"counter");
00037 
00038   uint dim=1; 
00039   cmd.mapvar(dim,"dim" );
00040 
00041   uintc n(2);
00042   double x0[n] = { 0.5, 0.5 };
00043 
00044 
00045   cout << "exploreh" << endl;
00046   exploreh<probsysequ01,double*,double> g1(n,0.2,50000);
00047   for ( g1.reset(x0); g1.fn.counter<counter; )
00048     ++g1;
00049   //cout << printvecfunc(g1.xi,n) << endl;
00050   cout << "g1.xi[]=" << print(g1.xi,g1.xi+n) << endl;
00051   cout << SHOW(g1.fn.counter) << endl;
00052   cout << SHOW(g1.fmin) << endl;
00053 
00054   cout << "patternsearch" << endl;
00055   typedef exploreh<probsysequ01,double*,double> e1;
00056   e1 f2(n,0.2,5000);
00057   patternsearch< e1 & > g2(f2,0.2);
00058 
00059   for ( g2.reset(x0); g2.exp.fn.counter<counter; )
00060     ++g2;
00061   //cout << printvecfunc(g2.exp.xi,n) << endl;
00062   cout << "g2.exp.xi[]=" << print(g2.exp.xi,g2.exp.xi+n) << endl;
00063   cout << SHOW(f2.fn.counter) << endl;
00064   cout << SHOW(f2.fmin) << endl;
00065 
00066   cout << "pattern with explorequad  " <<  SHOW(dim) << endl;
00067   typedef explorequad< exploreh<probsysequ01,double*,double> > eh2;
00068   eh2 f3(n,0.2,5000);
00069   patternsearchD2< eh2 & > g3(f3,dim,0.2);
00070   for ( g3.reset(x0); f3.fn.counter<counter; )
00071     ++g3;
00072   //cout << printvecfunc(g3.exp.xi,n) << endl;
00073   cout << "g3.exp.xi[]=" << print(g3.exp.xi,g3.exp.xi+n) << endl;
00074   cout << SHOW(f3.fn.counter) << endl;
00075   cout << SHOW(f3.fmin) << endl;
00076 
00077   cout << "pattern  " << SHOW(dim) << endl;
00078   f2.fn.counter=0;
00079   patternsearchD2< e1 & > g4(f2,dim,0.2);
00080   for ( g4.reset(x0); f2.fn.counter<counter; )
00081     ++g4;
00082   //cout << printvecfunc(g4.exp.xi,n) << endl;
00083   cout << "g4.exp.xi[]=" << print(g4.exp.xi,g4.exp.xi+n) << endl;
00084   cout << SHOW(f2.fn.counter) << endl;
00085   cout << SHOW(f2.fmin) << endl;
00086 
00087   cout << "explorerand" << endl;
00088   explorerand< exploreh<probsysequ01,double*,double>, random00<> > g5(n,0.2,50000);
00089   for ( g5.reset(x0); g5.fn.counter<counter; )
00090     ++g5;
00091   //cout << printvecfunc(g5.xi,n) << endl;
00092   cout << "g5.exp.xi[]=" << print(g5.xi,g5.xi+n) << endl;
00093   cout << SHOW(g5.fn.counter) << endl;
00094   cout << SHOW(g5.fmin) << endl;
00095 
00096 }
00097 
00098 template< typename T >
00099 long double const solutiondistance01(T & w)
00100 {
00101   long double y0(0.2);
00102   long double y1((double)2.0/(double)3.0);
00103   return (w.xi[0]-y0)*(w.xi[0]-y0) + (w.xi[1]-y1)*(w.xi[1]-y1);
00104 }
00105 
00106 void minimizecomparetest02(int argc, char** argv)
00107 {
00108   cout << "Testing optimizers for a 2 variable non-linear system" << endl << endl;
00109 
00110   commandline cmd(argc,argv);
00111 
00112   uint counter(200);
00113   cmd.mapvar(counter,"counter");
00114 
00115   uint dim=1; 
00116   cmd.mapvar(dim,"dim" );
00117 
00118   uintc n(2);
00119   double x0[n] = { 0.5, 0.5 };
00120 
00121   exploreh<probsysequ01,double*,double> g1(n,0.2,50000);
00122   for ( g1.reset(x0); g1.fn.counter<counter; )
00123     ++g1;
00124   cout << "exploreh              " << g1.fn.counter << " " << scientific;
00125   cout << g1.fmin << " " << solutiondistance01(g1) << endl;
00126 
00127 //  cout << "patternsearch" << endl;
00128   typedef exploreh<probsysequ01,double*,double> e1;
00129   e1 f2(n,0.2,5000);
00130   patternsearch< e1 & > g2(f2,0.2);
00131 
00132   for ( g2.reset(x0); g2.exp.fn.counter<counter; )
00133     ++g2;
00134   cout << "patternsearch         " << g2.exp.fn.counter << " " << scientific;
00135   cout << g2.exp.fmin << " " << solutiondistance01(g2.exp) << endl;
00136 
00137 
00138   typedef explorequad< exploreh<probsysequ01,double*,double> > eh2;
00139   eh2 f3(n,0.2,5000);
00140   patternsearchD2< eh2 & > g3(f3,dim,0.2);
00141   for ( g3.reset(x0); f3.fn.counter<counter; )
00142     ++g3;
00143   cout << "patternD(expquad) D=" << dim << " ";
00144   cout << g3.exp.fn.counter << " " << scientific;
00145   cout << g3.exp.fmin << " " << solutiondistance01(g3.exp) << endl;
00146 
00147   f2.fn.counter=0;
00148   patternsearchD2< e1 & > g4(f2,dim,0.2);
00149   for ( g4.reset(x0); f2.fn.counter<counter; )
00150     ++g4;
00151   cout << "patternD(exph) D=" << dim << "    ";
00152   cout << g4.exp.fn.counter << " " << scientific;
00153   cout << g4.exp.fmin << " " << solutiondistance01(g4.exp) << endl;
00154 
00155   explorerand< exploreh<probsysequ01,double*,double>, random00<> > g5(n,0.2,50000);
00156   for ( g5.reset(x0); g5.fn.counter<counter; )
00157     ++g5;
00158   cout << "explorerand           ";
00159   cout << g5.fn.counter << " " << scientific;
00160   cout << g5.fmin << " " << solutiondistance01(g5) << endl;
00161 
00162   uint lineiter(10);
00163   cmd.mapvar(lineiter,"lineiter");
00164 
00165   typedef exploreh<probsysequ01,double*,double> exp2;
00166   typedef lineoptimizergold<probsysequ01,double*,double*,double> lnmin;
00167 
00168   exploreline< exp2, lnmin > g6(2,lineiter);
00169 
00170   cmd.mapvar(g6.linet0,"t0");
00171   cmd.mapvar(g6.linet1,"t1");
00172   for ( g6.reset(x0); g6.fn.counter<counter; )
00173     ++g6;
00174   cout << "exp(linegold) i=" << lineiter << "  ";
00175   cout << g6.fn.counter << " " << scientific;
00176   cout << g6.fmin << " " << solutiondistance01(g6) << endl;
00177 
00178 
00179 
00180 
00181 
00182   //typedef exploreh<probrosenbrock01,double*,double> e3;
00183   //typedef lineoptimizergold<probrosenbrock01,double*,double*,double> lnmin3;
00184   //exploreline< e3, lnmin3 > g7(2,lineiter);
00185 
00186   typedef lineoptimizergold<probsysequ01,double*,double*,double> lnmin2;
00187   exploreline< eh2, lnmin > g7(2,lineiter);
00188 
00189   cmd.mapvar(g7.linet0,"t0");
00190   cmd.mapvar(g7.linet1,"t1");
00191   for ( g7.reset(x0); g7.fn.counter<counter; )
00192     ++g7;
00193   cout << "expquad(linegold) i=" << lineiter << "  ";
00194   cout << g7.fn.counter << " " << scientific;
00195   cout << g7.fmin << " " << solutiondistance01(g7) << endl;
00196 
00197 
00198 //  powell02< exp2, lnmin > g8(2,lineiter);
00199 //  for ( g8.reset(x0); g8.exp.fn.counter<counter; )
00200 //    ++g8;
00201 //  cout << "powell02(linegold) i=" << lineiter << "  ";
00202 //  cout << g8.exp.fn.counter << " " << scientific;
00203 //  cout << g8.exp.fmin << " " << solutiondistance01(g8.exp) << endl;
00204 
00205 
00206   
00207 
00208 
00209 }
00210 
00211 
00212 void minimizecomparetest03(int argc, char** argv)
00213 {
00214   cout << "Testing minimizers with the 2D Rosenbrock function." << endl;
00215 
00216 /*
00217   commandline cmd(argc,argv);
00218 
00219 
00220   uint counter(200);
00221   cmd.mapvar(counter,"counter");
00222 
00223   uint dim=1; 
00224   cmd.mapvar(dim,"dim" );
00225 
00226   uint lineiter=15;
00227   cmd.mapvar(lineiter,"lineiter");
00228 
00229   uintc n(2);
00230   double x0[n] = { 0.0, 0.0 };
00231 
00232   typedef linepathd1< probrosenbrock01&,double*,double*,double > lpath;
00233   typedef lineoptimizergold2<lpath,double> lnmin; 
00234   typedef exploreh<probrosenbrock01,double*,double> exp2;
00235   powell02< exp2, lnmin > g8(2,lineiter);
00236 */
00237 
00238 /*
00239   for ( g8.reset(x0); g8.exp.fn.counter<counter; )
00240     ++g8;
00241   cout << "powell02(linegold2) i=" << lineiter << "  ";
00242   cout << g8.exp.fn.counter << " " << scientific;
00243   cout << g8.exp.fmin << " " << solutiondistance01(g8.exp) << endl;
00244 */
00245 
00246 
00247 
00248 }
00249 
00250 

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