PlayaObjectiveBase.hpp
Go to the documentation of this file.
00001 #ifndef PLAYA_OBJECTIVE_BASE_H
00002 #define PLAYA_OBJECTIVE_BASE_H
00003 
00004 #include "PlayaDefs.hpp"
00005 #include "PlayaVectorDecl.hpp"
00006 #include "PlayaObjectWithVerbosity.hpp"
00007 
00008 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00009 #include "PlayaVectorImpl.hpp"
00010 #endif
00011 
00012 
00013 
00014 
00015 namespace Playa
00016 {
00017 /**
00018  * Base class for differentiable objective functions.
00019  * @author Paul Boggs and Kevin Long
00020  *
00021  */
00022 class ObjectiveBase : public ObjectWithVerbosity,
00023                       public Describable
00024 {
00025 public:
00026   /** */
00027   ObjectiveBase(int verb=0) : ObjectWithVerbosity(verb), contextString_() {;}
00028 
00029   /** virtual dtor */
00030   virtual ~ObjectiveBase(){;}
00031 
00032   /** evaluate objective function and gradient */
00033   virtual void  evalGrad(const Vector<double>& x, double& f, 
00034     Vector<double>& grad) const = 0;
00035 
00036   /** evaluate objective function without gradient. */
00037   virtual void  eval(const Vector<double>& x, double& f) const = 0 ;
00038 
00039   /** return an initial guess for the design vector  */
00040   virtual Vector<double> getInit() const = 0;
00041 
00042   /** return an initial approximation to the scale for the 
00043    * inverse of the Hessian */
00044   virtual double getInvHScale() const {return 1.0;}
00045 
00046   /** User-overrideable hook for any callbacks to be done at the 
00047    * end of each iteration. Default is a no-op.  */
00048   virtual void iterationCallback(const Vector<double>& x, int iter) const {;}
00049 
00050   /** User-overrideable hook for any callbacks to be done at the 
00051    * end of an optimization loop. Default is a no-op.  */
00052   virtual void finalCallback(const Vector<double>& x) const {;}
00053 
00054   /** 
00055    * Set a string describing the context in which the function is being called.
00056    * This is intended to aid in reading diagnostic output. 
00057    */
00058   void setContextString(const string& str) const {contextString_ = str;}
00059 
00060   /** 
00061    * Set a string describing the context in which the function is being called.
00062    * This is intended to aid in reading diagnostic output. 
00063    */
00064   const string& contextString() const {return contextString_;}
00065 
00066   /** 
00067    * Return the number of evaluations
00068    */
00069   virtual int numFuncEvals() const {return -1;}
00070 
00071   /** 
00072    *
00073    */
00074   virtual string description() const {return "ObjectiveBase";}
00075 
00076   /** Debugging utility to check the gradient 
00077    * by comparing to a finite difference 
00078    * gradient calculation. This is will be expensive. */
00079   bool fdCheck(const Vector<double>& x, double tol, int verbosity=0) const ;
00080 
00081 protected:
00082   /** */
00083   virtual double fdStep() const {return 1.0e-4;}
00084 
00085 
00086 private:
00087   mutable string contextString_;
00088 };
00089 
00090 }
00091 
00092 #endif

Site Contact