ROL
ROL_Powell.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 
49 #ifndef USE_HESSVEC
50 #define USE_HESSVEC 1
51 #endif
52 
53 #ifndef ROL_POWELL_HPP
54 #define ROL_POWELL_HPP
55 
56 #include "ROL_ScaledStdVector.hpp"
57 #include "ROL_Objective.hpp"
58 
59 namespace ROL {
60 namespace ZOO {
61 
64 template<class Real>
65 class Objective_Powell : public Objective<Real> {
66 
67 public:
69 
70  Real value( const Vector<Real> &x, Real &tol ) {
71  Teuchos::RCP<const std::vector<Real> > xp
72  = Teuchos::dyn_cast<const PrimalScaledStdVector<Real> >(x).getVector();
73 
74  Real f1 = 1.e4*(*xp)[0]*(*xp)[1] - 1.0;
75  Real f2 = std::exp(-(*xp)[0]) + std::exp(-(*xp)[1]) - 1.0001;
76 
77  return f1*f1+f2*f2;
78  }
79 
80  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
81  Teuchos::RCP<std::vector<Real> > gp
82  = Teuchos::dyn_cast<DualScaledStdVector<Real> >(g).getVector();
83  Teuchos::RCP<const std::vector<Real> > xp
84  = Teuchos::dyn_cast<const PrimalScaledStdVector<Real> >(x).getVector();
85 
86  Real f1 = 1.e4*(*xp)[0]*(*xp)[1] - 1.0;
87  Real f2 = std::exp(-(*xp)[0]) + std::exp(-(*xp)[1]) - 1.0001;
88 
89  Real f11 = 1.e4*(*xp)[1];
90  Real f12 = 1.e4*(*xp)[0];
91  Real f21 = -std::exp(-(*xp)[0]);
92  Real f22 = -std::exp(-(*xp)[1]);
93 
94  (*gp)[0] = 2.0*(f11*f1 + f21*f2);
95  (*gp)[1] = 2.0*(f12*f1 + f22*f2);
96  }
97 #if USE_HESSVEC
98  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
99  Teuchos::RCP<std::vector<Real> > hvp
100  = Teuchos::dyn_cast<DualScaledStdVector<Real> >(hv).getVector();
101  Teuchos::RCP<const std::vector<Real> > vp
102  = Teuchos::dyn_cast<const PrimalScaledStdVector<Real> >(v).getVector();
103  Teuchos::RCP<const std::vector<Real> > xp
104  = Teuchos::dyn_cast<const PrimalScaledStdVector<Real> >(x).getVector();
105 
106  Real f1 = 1.e4*(*xp)[0]*(*xp)[1] - 1.0;
107  Real f2 = std::exp(-(*xp)[0]) + std::exp(-(*xp)[1]) - 1.0001;
108 
109  Real f11 = 1.e4*(*xp)[1];
110  Real f12 = 1.e4*(*xp)[0];
111  Real f21 = -std::exp(-(*xp)[0]);
112  Real f22 = -std::exp(-(*xp)[1]);
113 
114  Real f111 = 0.0;
115  Real f112 = 1.e4;
116  Real f121 = 1.e4;
117  Real f122 = 0.0;
118  Real f211 = std::exp(-(*xp)[0]);
119  Real f212 = 0.0;
120  Real f221 = 0.0;
121  Real f222 = std::exp(-(*xp)[1]);
122 
123  Real h11 = 2.0*(f111*f1 + f11*f11) + 2.0*(f211*f2 + f21*f21);
124  Real h12 = 2.0*(f112*f1 + f11*f12) + 2.0*(f212*f2 + f21*f22);
125  Real h21 = 2.0*(f121*f1 + f21*f11) + 2.0*(f221*f2 + f22*f21);
126  Real h22 = 2.0*(f122*f1 + f12*f12) + 2.0*(f222*f2 + f22*f22);
127 
128  (*hvp)[0] = h11*(*vp)[0] + h12*(*vp)[1];
129  (*hvp)[1] = h21*(*vp)[0] + h22*(*vp)[1];
130  }
131 #endif
132  void invHessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
133  Teuchos::RCP<std::vector<Real> > hvp
134  = Teuchos::dyn_cast<PrimalScaledStdVector<Real> >(hv).getVector();
135  Teuchos::RCP<const std::vector<Real> > vp
136  = Teuchos::dyn_cast<const DualScaledStdVector<Real> >(v).getVector();
137  Teuchos::RCP<const std::vector<Real> > xp
138  = Teuchos::dyn_cast<const PrimalScaledStdVector<Real> >(x).getVector();
139 
140  Real f1 = 1.e4*(*xp)[0]*(*xp)[1] - 1.0;
141  Real f2 = std::exp(-(*xp)[0]) + std::exp(-(*xp)[1]) - 1.0001;
142 
143  Real f11 = 1.e4*(*xp)[1];
144  Real f12 = 1.e4*(*xp)[0];
145  Real f21 = -std::exp(-(*xp)[0]);
146  Real f22 = -std::exp(-(*xp)[1]);
147 
148  Real f111 = 0.0;
149  Real f112 = 1.e4;
150  Real f121 = 1.e4;
151  Real f122 = 0.0;
152  Real f211 = std::exp(-(*xp)[0]);
153  Real f212 = 0.0;
154  Real f221 = 0.0;
155  Real f222 = std::exp(-(*xp)[1]);
156 
157  Real h11 = 2.0*(f111*f1 + f11*f11) + 2.0*(f211*f2 + f21*f21);
158  Real h12 = 2.0*(f112*f1 + f11*f12) + 2.0*(f212*f2 + f21*f22);
159  Real h21 = 2.0*(f121*f1 + f21*f11) + 2.0*(f221*f2 + f22*f21);
160  Real h22 = 2.0*(f122*f1 + f12*f12) + 2.0*(f222*f2 + f22*f22);
161 
162  (*hvp)[0] = (1.0/(h11*h22-h12*h21))*( h22*(*vp)[0] - h21*(*vp)[1]);
163  (*hvp)[1] = (1.0/(h11*h22-h12*h21))*(-h12*(*vp)[0] + h11*(*vp)[1]);
164  }
165 };
166 
167 template<class Real>
168 void getPowell( Teuchos::RCP<Objective<Real> > &obj,
169  Teuchos::RCP<Vector<Real> > &x0,
170  Teuchos::RCP<Vector<Real> > &x ) {
171  // Problem dimension
172  int n = 2;
173 
174  // Get problem scaling
175  Teuchos::RCP<std::vector<Real> > scale = Teuchos::rcp(new std::vector<Real>(n,0.0));
176  (*scale)[0] = 1.e10; (*scale)[1] = 1.e-2;
177 
178  // Get Initial Guess
179  Teuchos::RCP<std::vector<Real> > x0p = Teuchos::rcp(new std::vector<Real>(n,0.0));
180  (*x0p)[0] = 0.0; (*x0p)[1] = 1.0;
181  x0 = Teuchos::rcp(new PrimalScaledStdVector<Real>(x0p,scale));
182 
183  // Get Solution: (*xp)[0] = 1.0981770261368074e-05;
184  Teuchos::RCP<std::vector<Real> > xp = Teuchos::rcp(new std::vector<Real>(n,0.0));
185  (*xp)[0] = 1.098e-05; (*xp)[1] = 9.106;
186  x = Teuchos::rcp(new PrimalScaledStdVector<Real>(xp,scale));
187 
188  // Instantiate Objective Function
189  obj = Teuchos::rcp(new Objective_Powell<Real>);
190 }
191 
192 } // End ZOO Namespace
193 } // End ROL Namespace
194 
195 #endif
Provides the interface to evaluate objective functions.
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_Powell.hpp:70
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
Powell&#39;s badly scaled function.
Definition: ROL_Powell.hpp:65
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void getPowell(Teuchos::RCP< Objective< Real > > &obj, Teuchos::RCP< Vector< Real > > &x0, Teuchos::RCP< Vector< Real > > &x)
Definition: ROL_Powell.hpp:168
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_Powell.hpp:80
void invHessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply inverse Hessian approximation to vector.
Definition: ROL_Powell.hpp:132