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
57#include "ROL_TestProblem.hpp"
58
59namespace ROL {
60namespace ZOO {
61
64template<class Real>
65class Objective_Powell : public Objective<Real> {
66
67public:
69
70 Real value( const Vector<Real> &x, Real &tol ) {
71 ROL::Ptr<const std::vector<Real> > xp
72 = dynamic_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 ROL::Ptr<std::vector<Real> > gp
82 = dynamic_cast<DualScaledStdVector<Real>&>(g).getVector();
83 ROL::Ptr<const std::vector<Real> > xp
84 = dynamic_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 ROL::Ptr<std::vector<Real> > hvp
100 = dynamic_cast<DualScaledStdVector<Real>&>(hv).getVector();
101 ROL::Ptr<const std::vector<Real> > vp
102 = dynamic_cast<const PrimalScaledStdVector<Real>&>(v).getVector();
103 ROL::Ptr<const std::vector<Real> > xp
104 = dynamic_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 + f12*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 ROL::Ptr<std::vector<Real> > hvp
134 = dynamic_cast<PrimalScaledStdVector<Real>&>(hv).getVector();
135 ROL::Ptr<const std::vector<Real> > vp
136 = dynamic_cast<const DualScaledStdVector<Real>&>(v).getVector();
137 ROL::Ptr<const std::vector<Real> > xp
138 = dynamic_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
167template<class Real>
168class getPowell : public TestProblem<Real> {
169private:
170 ROL::Ptr<std::vector<Real> > scale_;
171
172public:
173 getPowell(void) {
174 // Get problem scaling
175 scale_ = ROL::makePtr<std::vector<Real>>(2,0.0);
176 (*scale_)[0] = 1.e10; (*scale_)[1] = 1.e-2;
177 }
178
179 Ptr<Objective<Real>> getObjective(void) const {
180 // Instantiate Objective Function
181 return ROL::makePtr<Objective_Powell<Real>>();
182 }
183
184 Ptr<Vector<Real>> getInitialGuess(void) const {
185 // Problem dimension
186 int n = 2;
187 // Get Initial Guess
188 ROL::Ptr<std::vector<Real> > x0p = ROL::makePtr<std::vector<Real>>(n,0.0);
189 (*x0p)[0] = 0.0; (*x0p)[1] = 1.0;
190 return ROL::makePtr<PrimalScaledStdVector<Real>>(x0p,scale_);
191 }
192
193 Ptr<Vector<Real>> getSolution(const int i = 0) const {
194 // Problem dimension
195 int n = 2;
196 // Get Solution: (*xp)[0] = 1.0981770261368074e-05;
197 ROL::Ptr<std::vector<Real> > xp = ROL::makePtr<std::vector<Real>>(n,0.0);
198 (*xp)[0] = 1.098e-05; (*xp)[1] = 9.106;
199 return ROL::makePtr<PrimalScaledStdVector<Real>>(xp,scale_);
200 }
201};
202
203} // End ZOO Namespace
204} // End ROL Namespace
205
206#endif
Contains definitions of test objective functions.
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
Provides the interface to evaluate objective functions.
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Provides the std::vector implementation of the ROL::Vector interface that handles scalings in the inn...
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
Powell's badly scaled function.
Definition: ROL_Powell.hpp:65
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Definition: ROL_Powell.hpp:70
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
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
Definition: ROL_Powell.hpp:80
Ptr< Objective< Real > > getObjective(void) const
Definition: ROL_Powell.hpp:179
ROL::Ptr< std::vector< Real > > scale_
Definition: ROL_Powell.hpp:170
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition: ROL_Powell.hpp:193
Ptr< Vector< Real > > getInitialGuess(void) const
Definition: ROL_Powell.hpp:184