LBFGSBT.hh

Go to the documentation of this file.
00001 /*************************************************************************
00002 
00003 Copyright Rice University, 2011.
00004 All rights reserved.
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the "Software"),
00008 to deal in the Software without restriction, including without limitation
00009 the rights to use, copy, modify, merge, publish, distribute, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, provided that the above copyright notice(s) and this
00012 permission notice appear in all copies of the Software and that both the
00013 above copyright notice(s) and this permission notice appear in supporting
00014 documentation.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
00019 RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
00020 NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
00021 DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
00022 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
00023 ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
00024 THIS SOFTWARE.
00025 
00026 Except as contained in this notice, the name of a copyright holder shall
00027 not be used in advertising or otherwise to promote the sale, use or other
00028 dealings in this Software without prior written authorization of the
00029 copyright holder.
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     // parameters for LBFGSDir
00146     Scalar ihs;        // inverse Hessian scale
00147     int mud;           // max updates
00148 
00149     // parameters for BT line search
00150     int maxsamp;       // max function evaluations
00151     bool disp;         // display flag 
00152     Scalar sl1;        // length of first step
00153     Scalar minsteptol; // minimum permitted step length (fraction of prev step)
00154     Scalar eta1;       // First GA scale: min acceptable decrease
00155     Scalar eta2;       // Second GA scale: good decrease
00156     Scalar gamma1;     // First BT factor: shrink step if decrease not acceptable
00157     Scalar gamma2;     // Second BT factor: expand step if decrease good
00158     Scalar maxfrac;    // fraction of max step to attempt
00159 
00160     // parameters for loop alg
00161     int maxits;        // max number of LBFGS steps
00162     Scalar agradtol;   // absolute gradient stopping threshhold
00163     Scalar rgradtol;   // relative gradient stopping threshhold (to initial)
00164     // also uses disp
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     // put together alg, terminator, and loopalg.
00265     // note that BFGS update rule is also a terminator
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

Generated on 5 Jan 2017 for RvlUmin by  doxygen 1.4.7