tstLBFGS.C

Test program for LBFGS optimization objects

1. Limited Memory BFGS method with More-Thuente Search on an NLF1

00001 
00009 #ifdef HAVE_CONFIG_H
00010 #include "OPT++_config.h"
00011 #endif
00012 
00013 #include <fstream>
00014 #ifdef HAVE_STD
00015 #include <cstdio>
00016 #else
00017 #include <stdio.h>
00018 #endif
00019 
00020 #include "OptLBFGS.h"
00021 #include "NLF.h"
00022 
00023 #include "tstfcn.h"
00024 
00025 using NEWMAT::ColumnVector;
00026 
00027 using namespace OPTPP;
00028 void update_model(int, int, ColumnVector) {}
00029 
00030 int main ()
00031 {
00032   int n = 2;
00033   
00034   static char *status_file = {"tstLBFGS.out"};
00035 
00036   //  Create a Nonlinear problem object
00037 
00038   NLF1 nlp(n,rosen,init_rosen);
00039   
00040   //  Build a LBFGS object and optimize 
00041 
00042   OptLBFGS objfcn(&nlp);   
00043   objfcn.setUpdateModel(update_model);
00044   if (!objfcn.setOutputFile(status_file, 0))
00045     cerr << "main: output file open failed" << endl;
00046   objfcn.setGradTol(1.e-6);
00047   objfcn.setMaxBacktrackIter(10);
00048   objfcn.setPrintFinalX(true);
00049   objfcn.optimize();
00050     
00051   objfcn.printStatus("Solution from LBFGS: More and Thuente's linesearch");
00052 
00053 #ifdef REG_TEST
00054   ColumnVector x_sol = nlp.getXc();
00055   double f_sol = nlp.getF();
00056   ostream* optout = objfcn.getOutputFile();
00057   if ((1.0 - x_sol(1) <= 1.e-2) && (1.0 - x_sol(2) <= 1.e-2) && (f_sol
00058                                                                  <=
00059                                                                  1.e-2))
00060     *optout << "LBFGS 1 PASSED" << endl;
00061   else
00062     *optout << "LBFGS 1 FAILED" << endl;
00063 #endif
00064 
00065   objfcn.cleanup();
00066 
00067 }

Bug Reports    OPT++ Developers    Copyright Information    GNU Lesser General Public License
Documentation, generated by , last revised August 30, 2006.