/************************************************************************* Copyright Rice University, 2004. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder. **************************************************************************/ #ifndef __RVLALG_UMIN_CHOOSER_H #define __RVLALG_UMIN_CHOOSER_H #include "umintable.hh" #include "lbfgsalg.hh" #include "lnsrchBT.hh" #include "uminstep.hh" //#include "TRalg.hh" under construction /** "Chooser" class for UMin methods - closed handle to StateAlg */ namespace RVLUmin { using namespace RVLAlg; using RVL::Vector; using RVL::Functional; using RVL::FunctionalEvaluation; template class UMinMethod: public StateAlg< Vector > { private: Functional const & f; Vector & x; UMinTable & t; mutable int count; ostream & str; UMinMethod(); UMinMethod(const UMinMethod &); public: UMinMethod(Functional const & _f, Vector & _x, UMinTable & _t, ostream & _str = cout) : f(_f), x(_x), t(_t), str(_str), count(0) {} void run() { try { string upd; // check that update type is specified if (t.getValue("UpdateAlg",upd)) { RVLException e; e<<"Error: UMinMethod constructor\n"; e<<"update method not specified (key UpdatedAlg)\n"; throw e; } if (upd == "LBFGS") { // BFGS update rule - also a terminator LBFGSDir dir(f.getDomain(), getValFromTable(t,"InvHessianScale"), getValFromTable(t,"MaxUpdates"), str); // for LBFGS must specify line search method // if (t.getValue("LineSearchAlg",lns)) { // RVLException e; // e<<"Error: UMinMethod constructor\n"; // e<<"line search method not specified (key LineSearchAlg) for LBFGS update\n"; // throw e; // } //if (lns == "DS") { // meth = new UMinLBFGS_DS(f,x,t,str); // } //else // if (lns == "BT") { BacktrackingLineSearchAlg ls(getValFromTable(t,"MaxSample"), getValFromTable(t,"DispFlag"), str, getValFromTable(t,"FirstStep"), getValFromTable(t,"FcnDecreaseTol"), getValFromTable(t,"StepReductionFactor"), getValFromTable(t,"FractionOfMaxStep") ); FunctionalEvaluation fx(f,x); CountingIterationTable stop1(fx, getValFromTable(t,"MaxItn"), getValFromTable(t,"AbsGradTol"), getValFromTable(t,"RelGradTol"), getValFromTable(t,"DispFlag"), str); OrTerminator stop(dir,stop1); UMinStepLS step(fx,dir,ls,str); LoopAlg Umin(step, stop); Umin.run(); count=stop1.getCount(); } else if (upd == "TRCG") { RVLException e; e<<"Error UMinMethod constructor\n"; e<<"TRCG currently not available\n"; throw e; /* cout << "Update = TRCG!" << endl; dir = new TRCGDir(f.getDomain(), NULL, getValFromTable(t,"InvHessianScale"), getValFromTable(t,"MaxUpdates")); meth = new UMinAlgTR (f,x, *dir, getValFromTable(t,"MaxItn"), getValFromTable(t,"GradTol"), getValFromTable(t,"DispFlag"), str); */ } else { RVLException e; e<<"Error: UMinMethod constructor\n"; e<<"UpdateAlg = "< & getState() { return x; } Vector const & getState() const { return x; } int getCount() const { return count; } }; } #endif