ROL
ROL_Objective.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 #ifndef ROL_OBJECTIVE_H
45 #define ROL_OBJECTIVE_H
46 
47 #include "ROL_Vector.hpp"
48 #include "ROL_Types.hpp"
49 #include <iostream>
50 
74 namespace ROL {
75 
76 template <class Real>
77 class Objective {
78 public:
79 
80  virtual ~Objective() {}
81 
89  virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {}
90 
97  virtual Real value( const Vector<Real> &x, Real &tol ) = 0;
98 
112  virtual void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) ;
113 
121  virtual Real dirDeriv( const Vector<Real> &x, const Vector<Real> &d, Real &tol ) ;
122 
131  virtual void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol );
132 
141  virtual void invHessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {}
142 
151  virtual void precond( Vector<Real> &Pv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
152  Pv.set(v.dual());
153  }
154 
175  virtual std::vector<std::vector<Real> > checkGradient( const Vector<Real> &x,
176  const Vector<Real> &d,
177  const bool printToStream = true,
178  std::ostream & outStream = std::cout,
179  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
180  const int order = 1 ) {
181 
182  return checkGradient(x, x.dual(), d, printToStream, outStream, numSteps, order);
183 
184  }
185 
208  virtual std::vector<std::vector<Real> > checkGradient( const Vector<Real> &x,
209  const Vector<Real> &g,
210  const Vector<Real> &d,
211  const bool printToStream = true,
212  std::ostream & outStream = std::cout,
213  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
214  const int order = 1 );
215 
216 
237  virtual std::vector<std::vector<Real> > checkGradient( const Vector<Real> &x,
238  const Vector<Real> &d,
239  const std::vector<Real> &steps,
240  const bool printToStream = true,
241  std::ostream & outStream = std::cout,
242  const int order = 1 ) {
243 
244  return checkGradient(x, x.dual(), d, steps, printToStream, outStream, order);
245 
246  }
247 
248 
271  virtual std::vector<std::vector<Real> > checkGradient( const Vector<Real> &x,
272  const Vector<Real> &g,
273  const Vector<Real> &d,
274  const std::vector<Real> &steps,
275  const bool printToStream = true,
276  std::ostream & outStream = std::cout,
277  const int order = 1 );
278 
299  virtual std::vector<std::vector<Real> > checkHessVec( const Vector<Real> &x,
300  const Vector<Real> &v,
301  const bool printToStream = true,
302  std::ostream & outStream = std::cout,
303  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
304  const int order = 1 ) {
305 
306  return checkHessVec(x, x, v, printToStream, outStream, numSteps, order);
307 
308  }
309 
331  virtual std::vector<std::vector<Real> > checkHessVec( const Vector<Real> &x,
332  const Vector<Real> &hv,
333  const Vector<Real> &v,
334  const bool printToStream = true,
335  std::ostream & outStream = std::cout,
336  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
337  const int order = 1) ;
338 
339 
360  virtual std::vector<std::vector<Real> > checkHessVec( const Vector<Real> &x,
361  const Vector<Real> &v,
362  const std::vector<Real> &steps,
363  const bool printToStream = true,
364  std::ostream & outStream = std::cout,
365  const int order = 1 ) {
366 
367  return checkHessVec(x, x, v, steps, printToStream, outStream, order);
368 
369  }
370 
392  virtual std::vector<std::vector<Real> > checkHessVec( const Vector<Real> &x,
393  const Vector<Real> &hv,
394  const Vector<Real> &v,
395  const std::vector<Real> &steps,
396  const bool printToStream = true,
397  std::ostream & outStream = std::cout,
398  const int order = 1) ;
399 
400 
415  virtual std::vector<Real> checkHessSym( const Vector<Real> &x,
416  const Vector<Real> &v,
417  const Vector<Real> &w,
418  const bool printToStream = true,
419  std::ostream & outStream = std::cout ) {
420 
421  return checkHessSym(x, x, v, w, printToStream, outStream);
422 
423  }
424 
440  virtual std::vector<Real> checkHessSym( const Vector<Real> &x,
441  const Vector<Real> &hv,
442  const Vector<Real> &v,
443  const Vector<Real> &w,
444  const bool printToStream = true,
445  std::ostream & outStream = std::cout );
446 
447  // struct StepState (scalars, vectors) map?
448 
449  // getState
450 
451  // setState
452 
453 }; // class Step
454 
455 } // namespace ROL
456 
457 // include templated definitions
458 #include <ROL_ObjectiveDef.hpp>
459 
460 #endif
Provides the interface to evaluate objective functions.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Definition: ROL_Vector.hpp:211
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
virtual Real dirDeriv(const Vector< Real > &x, const Vector< Real > &d, Real &tol)
Compute directional derivative.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Contains definitions of custom data types in ROL.
virtual void precond(Vector< Real > &Pv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply preconditioner to vector.
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference gradient check with specified step sizes.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:72
virtual std::vector< std::vector< Real > > checkGradient(const Vector< Real > &x, const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference gradient check.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual void invHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply inverse Hessian approximation to vector.
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference Hessian-applied-to-vector check with specified step sizes.
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
Definition: ROL_Types.hpp:69
virtual std::vector< std::vector< Real > > checkHessVec(const Vector< Real > &x, const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Finite-difference Hessian-applied-to-vector check.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:194
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
virtual ~Objective()
virtual std::vector< Real > checkHessSym(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &w, const bool printToStream=true, std::ostream &outStream=std::cout)
Hessian symmetry check.