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  TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument,
143  ">>> ERROR (ROL::Objective): invHessVec not implemented!");
144  //hv.set(v.dual());
145  }
146 
155  virtual void precond( Vector<Real> &Pv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
156  Pv.set(v.dual());
157  }
158 
179  virtual std::vector<std::vector<Real> > checkGradient( const Vector<Real> &x,
180  const Vector<Real> &d,
181  const bool printToStream = true,
182  std::ostream & outStream = std::cout,
183  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
184  const int order = 1 ) {
185 
186  return checkGradient(x, x.dual(), d, printToStream, outStream, numSteps, order);
187 
188  }
189 
212  virtual std::vector<std::vector<Real> > checkGradient( const Vector<Real> &x,
213  const Vector<Real> &g,
214  const Vector<Real> &d,
215  const bool printToStream = true,
216  std::ostream & outStream = std::cout,
217  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
218  const int order = 1 );
219 
220 
241  virtual std::vector<std::vector<Real> > checkGradient( const Vector<Real> &x,
242  const Vector<Real> &d,
243  const std::vector<Real> &steps,
244  const bool printToStream = true,
245  std::ostream & outStream = std::cout,
246  const int order = 1 ) {
247 
248  return checkGradient(x, x.dual(), d, steps, printToStream, outStream, order);
249 
250  }
251 
252 
275  virtual std::vector<std::vector<Real> > checkGradient( const Vector<Real> &x,
276  const Vector<Real> &g,
277  const Vector<Real> &d,
278  const std::vector<Real> &steps,
279  const bool printToStream = true,
280  std::ostream & outStream = std::cout,
281  const int order = 1 );
282 
303  virtual std::vector<std::vector<Real> > checkHessVec( const Vector<Real> &x,
304  const Vector<Real> &v,
305  const bool printToStream = true,
306  std::ostream & outStream = std::cout,
307  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
308  const int order = 1 ) {
309 
310  return checkHessVec(x, x.dual(), v, printToStream, outStream, numSteps, order);
311 
312  }
313 
335  virtual std::vector<std::vector<Real> > checkHessVec( const Vector<Real> &x,
336  const Vector<Real> &hv,
337  const Vector<Real> &v,
338  const bool printToStream = true,
339  std::ostream & outStream = std::cout,
340  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
341  const int order = 1) ;
342 
343 
364  virtual std::vector<std::vector<Real> > checkHessVec( const Vector<Real> &x,
365  const Vector<Real> &v,
366  const std::vector<Real> &steps,
367  const bool printToStream = true,
368  std::ostream & outStream = std::cout,
369  const int order = 1 ) {
370 
371  return checkHessVec(x, x, v, steps, printToStream, outStream, order);
372 
373  }
374 
396  virtual std::vector<std::vector<Real> > checkHessVec( const Vector<Real> &x,
397  const Vector<Real> &hv,
398  const Vector<Real> &v,
399  const std::vector<Real> &steps,
400  const bool printToStream = true,
401  std::ostream & outStream = std::cout,
402  const int order = 1) ;
403 
404 
419  virtual std::vector<Real> checkHessSym( const Vector<Real> &x,
420  const Vector<Real> &v,
421  const Vector<Real> &w,
422  const bool printToStream = true,
423  std::ostream & outStream = std::cout ) {
424 
425  return checkHessSym(x, x, v, w, printToStream, outStream);
426 
427  }
428 
444  virtual std::vector<Real> checkHessSym( const Vector<Real> &x,
445  const Vector<Real> &hv,
446  const Vector<Real> &v,
447  const Vector<Real> &w,
448  const bool printToStream = true,
449  std::ostream & outStream = std::cout );
450 
451  // struct StepState (scalars, vectors) map?
452 
453  // getState
454 
455  // setState
456 
457 }; // class Step
458 
459 } // namespace ROL
460 
461 // include templated definitions
462 #include <ROL_ObjectiveDef.hpp>
463 
464 #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:213
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:74
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:70
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:196
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.