00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 #ifndef __RVLALG_LBFGSBT_H
00034 #define __RVLALG_LBFGSBT_H
00035 
00036 #include "table.hh"
00037 #include "lbfgsalg.hh"
00038 #include "lnsrchBT.hh"
00039 #include "uminstep.hh"
00040 
00041 
00042 namespace RVLUmin {
00043 
00044   using namespace RVLAlg;
00045   using RVL::Vector;
00046   using RVL::Functional;
00047   using RVL::FunctionalEvaluation;
00048   using RVL::Table;
00049   using RVL::RVLException;
00050 
00140   template<typename Scalar>
00141   class LBFGSBT: public Algorithm {
00142     
00143   private:
00144 
00145     
00146     Scalar ihs;        
00147     int mud;           
00148 
00149     
00150     int maxsamp;       
00151     bool disp;         
00152     Scalar sl1;        
00153     Scalar minsteptol; 
00154     Scalar eta1;       
00155     Scalar eta2;       
00156     Scalar gamma1;     
00157     Scalar gamma2;     
00158     Scalar maxfrac;    
00159 
00160     
00161     int maxits;        
00162     Scalar agradtol;   
00163     Scalar rgradtol;   
00164     
00165     ostream & str;
00166     FunctionalEvaluation<Scalar> fx;
00167     LBFGSDir<Scalar> dir;
00168     BacktrackingLineSearchAlg<Scalar> ls;
00169     GradientThresholdIterationTable<Scalar> ctbl;
00170 
00171     LBFGSBT();
00172     LBFGSBT(const LBFGSBT<Scalar> &);
00173 
00174   public:
00175 
00198     LBFGSBT(Functional<Scalar> const & f,
00199         Vector<Scalar> & x,
00200         Scalar _ihs,
00201         int _mud,
00202         int _maxsamp,
00203         bool _disp,
00204         Scalar _sl1,
00205         Scalar _eta1,
00206         Scalar _eta2,
00207         Scalar _gamma1,
00208         Scalar _gamma2,
00209         Scalar _maxfrac,
00210         Scalar _minsteptol,
00211         int _maxits,
00212         Scalar _agradtol,
00213         Scalar _rgradtol,
00214         ostream & _str = cout) 
00215       : ihs(_ihs), mud(_mud),
00216     maxsamp(_maxsamp),
00217     disp(_disp),
00218     sl1(_sl1),
00219     minsteptol(_minsteptol),
00220     eta1(_eta1),
00221     eta2(_eta2),
00222     gamma1(_gamma1),
00223     gamma2(_gamma2),
00224     maxfrac(_maxfrac),
00225     maxits(_maxits),
00226     agradtol(_agradtol),
00227     rgradtol(_rgradtol),
00228     str(_str),
00229     fx(f,x),
00230     dir(fx.getDomain(),ihs,mud,str),
00231     ls(maxsamp,disp,sl1,minsteptol,eta1,eta2,gamma1,gamma2,maxfrac,str),
00232     ctbl(fx,maxits,agradtol,rgradtol,str)
00233     { testRealOnly<Scalar>(); }
00234 
00236     LBFGSBT(Functional<Scalar> const & f,
00237         Vector<Scalar> & x,
00238         Table const & t,
00239         ostream & _str = cout)
00240       : ihs(getValueFromTable<Scalar>(t,"BFGS_InvHessianScale")),
00241     mud(getValueFromTable<int>(t,"BFGS_MaxUpdates")),
00242     maxsamp(getValueFromTable<int>(t,"LS_MaxSample")),
00243     disp(getValueFromTable<bool>(t,"DispFlag")),
00244     sl1(getValueFromTable<Scalar>(t,"LS_FirstStep")),
00245     minsteptol(getValueFromTable<Scalar>(t,"LS_MinStepTol")),
00246     eta1(getValueFromTable<Scalar>(t,"MinDecrease")),
00247     eta2(getValueFromTable<Scalar>(t,"GoodDecrease")),
00248     gamma1(getValueFromTable<Scalar>(t,"StepDecrFactor")),
00249     gamma2(getValueFromTable<Scalar>(t,"StepIncrFactor")),
00250     maxfrac(getValueFromTable<Scalar>(t,"LS_FractionOfMaxStep")),      
00251     maxits(getValueFromTable<int>(t,"MaxItn")),
00252     agradtol(getValueFromTable<Scalar>(t,"AbsGradTol")),
00253     rgradtol(getValueFromTable<Scalar>(t,"RelGradTol")),
00254     str(_str),
00255     fx(f,x),
00256     dir(fx.getDomain(),ihs,mud,str),
00257     ls(maxsamp,disp,sl1,minsteptol,eta1,eta2,gamma1,gamma2,maxfrac,str),
00258     ctbl(fx,maxits,agradtol,rgradtol,str)
00259     { testRealOnly<Scalar>(); }
00260     int getCount() { return ctbl.getCount(); }
00261 
00262     void run() {
00263       try {
00264     
00265     
00266     UMinStepLS<Scalar> step(fx,dir,ls,str);
00267     OrTerminator stop(step,ctbl);
00268     LoopAlg Umin(step, stop);
00269     Umin.run();
00270       }
00271 
00272       catch (RVLException & e) {
00273     e<<"\ncalled from LBFGSBT constructor\n";
00274     throw e;
00275       }
00276     }
00277 
00278     ~LBFGSBT() {}
00279 
00285     FunctionalEvaluation<Scalar> const & getFunctionalEvaluation() const { return fx; }
00286     
00287   };
00288 
00289 }
00290 #endif