ROL
ROL_TypeP_TrustRegionAlgorithm.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_TYPEP_TRUSTREGIONALGORITHM_HPP
45#define ROL_TYPEP_TRUSTREGIONALGORITHM_HPP
46
50#include "ROL_Types.hpp"
51
55
56namespace ROL {
57namespace TypeP {
58
65
66inline std::string ETrustRegionPToString(ETrustRegionP alg) {
67 std::string retString;
68 switch(alg) {
69 case TRUSTREGION_P_SPG: retString = "SPG"; break;
70 case TRUSTREGION_P_SPG2: retString = "Simplified SPG"; break;
71 case TRUSTREGION_P_NCG: retString = "NCG"; break;
72 case TRUSTREGION_P_LAST: retString = "Last Type (Dummy)"; break;
73 default: retString = "INVALID ETrustRegionP";
74 }
75 return retString;
76}
77
79 return( (alg == TRUSTREGION_P_SPG) ||
80 (alg == TRUSTREGION_P_SPG2) ||
81 (alg == TRUSTREGION_P_NCG) ||
82 (alg == TRUSTREGION_P_LAST)
83 );
84}
85
87 return type = static_cast<ETrustRegionP>(type+1);
88}
89
91 ETrustRegionP oldval = type;
92 ++type;
93 return oldval;
94}
95
97 return type = static_cast<ETrustRegionP>(type-1);
98}
99
101 ETrustRegionP oldval = type;
102 --type;
103 return oldval;
104}
105
107 s = removeStringFormat(s);
108 for ( ETrustRegionP alg = TRUSTREGION_P_SPG; alg < TRUSTREGION_P_LAST; alg++ ) {
109 if ( !s.compare(removeStringFormat(ETrustRegionPToString(alg))) ) {
110 return alg;
111 }
112 }
113 return TRUSTREGION_P_SPG;
114}
115
116template<typename Real>
118private:
119 Ptr<TrustRegionModel_U<Real>> model_;
120
121 // TRUST REGION PARAMETERS
122 Real delMax_;
123 Real eta0_;
124 Real eta1_;
125 Real eta2_;
126 Real gamma0_;
127 Real gamma1_;
128 Real gamma2_;
129 Real TRsafe_;
130 Real eps_;
132
133 // ITERATION FLAGS/INFORMATION
137
138 // SECANT INFORMATION
142
143 // TRUNCATED CG INFORMATION
144 Real tol1_;
145 Real tol2_;
146 int maxit_;
147
148 // ALGORITHM SPECIFIC PARAMETERS
149 bool useNM_;
151 Real mu0_;
152 Real spexp_;
155 Real alpha_;
157 Real interpf_;
158 Real extrapf_;
159 Real qtol_;
162 Real gamma_;
168 Real etaNCG_;
170
171 // Inexactness Parameters
172 std::vector<bool> useInexact_;
175 Real scale_;
176 Real omega_;
177 Real force_;
180
182 Real t0_;
183
184 mutable int nhess_;
185 unsigned verbosity_;
187
188 using TypeP::Algorithm<Real>::state_;
189 using TypeP::Algorithm<Real>::status_;
190 using TypeP::Algorithm<Real>::pgstep;
191
192 void initialize(Vector<Real> &x,
193 const Vector<Real> &g,
194 Real ftol,
195 Objective<Real> &sobj,
196 Objective<Real> &nobj,
197 Vector<Real> &px,
198 Vector<Real> &dg,
199 std::ostream &outStream = std::cout);
200
201public:
202 TrustRegionAlgorithm(ParameterList &list, const Ptr<Secant<Real>> &secant = nullPtr);
203
204 using TypeP::Algorithm<Real>::run;
205 void run( Vector<Real> &x,
206 const Vector<Real> &g,
207 Objective<Real> &sobj,
208 Objective<Real> &nobj,
209 std::ostream &outStream = std::cout) override;
210
211 void writeHeader( std::ostream& os ) const override;
212
213 void writeName( std::ostream& os ) const override;
214
215 void writeOutput( std::ostream& os, bool write_header = false ) const override;
216
217private:
218
219 Real computeValue(Real inTol,
220 Real &outTol,
221 Real pRed,
222 Real &fold,
223 int iter,
224 const Vector<Real> &x,
225 const Vector<Real> &xold,
226 Objective<Real> &obj);
227
228 Real computeGradient(const Vector<Real> &x,
229 Vector<Real> &g,
230 Vector<Real> &px,
231 Vector<Real> &dg,
232 Vector<Real> &pwa,
233 Real del,
234 Objective<Real> &sobj,
235 Objective<Real> &nobj,
236 std::ostream &outStream = std::cout) const;
237
238 // Compute the projected step s = P(x + alpha*w) - x
239 // Returns the norm of the projected step s
240 // s -- The projected step upon return
241 // w -- The direction vector w (unchanged)
242 // x -- The anchor vector x (unchanged)
243 // alpha -- The step size (unchanged)
244 // Real dgpstep(Vector<Real> &s, const Vector<Real> &w,
245 // const Vector<Real> &x, const Real alpha,
246 // std::ostream &outStream = std::cout) const;
247
248 // Compute Cauchy point, i.e., the minimizer of q(P(x - alpha*g)-x)
249 // subject to the trust region constraint ||P(x - alpha*g)-x|| <= del
250 // s -- The Cauchy step upon return: Primal optimization space vector
251 // alpha -- The step length for the Cauchy point upon return
252 // x -- The anchor vector x (unchanged): Primal optimization space vector
253 // g -- The (dual) gradient vector g (unchanged): Primal optimization space vector
254 // del -- The trust region radius (unchanged)
255 // model -- Trust region model
256 // dwa -- Dual working array, stores Hessian applied to step
257 // dwa1 -- Dual working array
258 Real dcauchy(Vector<Real> &s,
259 Real &alpha,
260 Real &sval,
261 Real &nval,
262 const Vector<Real> &x,
263 const Vector<Real> &g,
264 Real del,
266 Objective<Real> &nobj,
267 Vector<Real> &px,
268 Vector<Real> &dwa,
269 Vector<Real> &dwa1,
270 std::ostream &outStream = std::cout);
271
272 void dspg2(Vector<Real> &y,
273 Real &sval,
274 Real &nval,
275 Real &pRed,
276 Vector<Real> &gmod,
277 const Vector<Real> &x,
278 Real del,
280 Objective<Real> &nobj,
281 Vector<Real> &pwa,
282 Vector<Real> &pwa1,
283 Vector<Real> &pwa2,
284 Vector<Real> &dwa,
285 std::ostream &outStream = std::cout);
286
287 void dspg(Vector<Real> &y,
288 Real &sval,
289 Real &nval,
290 Vector<Real> &gmod,
291 const Vector<Real> &x,
292 Real del,
294 Objective<Real> &nobj,
295 Vector<Real> &ymin,
296 Vector<Real> &pwa,
297 Vector<Real> &pwa1,
298 Vector<Real> &pwa2,
299 Vector<Real> &pwa3,
300 Vector<Real> &pwa4,
301 Vector<Real> &pwa5,
302 Vector<Real> &dwa,
303 std::ostream &outStream = std::cout);
304
305 void dncg(Vector<Real> &y,
306 Real &sval,
307 Real &nval,
308 Vector<Real> &gmod,
309 const Vector<Real> &x,
310 Real del,
312 Objective<Real> &nobj,
313 Vector<Real> &s,
314 Vector<Real> &pwa1,
315 Vector<Real> &pwa2,
316 Vector<Real> &pwa3,
317 Vector<Real> &pwa4,
318 Vector<Real> &pwa5,
319 Vector<Real> &dwa,
320 std::ostream &outStream = std::cout);
321
322
323 void dprox(Vector<Real> &x,
324 const Vector<Real> &x0,
325 Real t,
326 Real del,
327 Objective<Real> &nobj,
328 Vector<Real> &y0,
329 Vector<Real> &y1,
330 Vector<Real> &yc,
331 Vector<Real> &pwa,
332 std::ostream &outStream = std::cout) const;
333
334}; // class ROL::TypeP::TrustRegionAlgorithm
335
336} // namespace TypeP
337} // namespace ROL
338
340
341#endif
Contains definitions of custom data types in ROL.
Provides the interface to evaluate objective functions.
Provides interface for and implements limited-memory secant operators.
Provides the interface to evaluate trust-region model functions.
Provides an interface to run optimization algorithms to minimize composite optimization problems f+ph...
void pgstep(Vector< Real > &pgiter, Vector< Real > &pgstep, Objective< Real > &nobj, const Vector< Real > &x, const Vector< Real > &dg, Real t, Real &tol) const
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
TRUtils::ETRFlag TRflag_
Trust-region exit flag.
void dncg(Vector< Real > &y, Real &sval, Real &nval, Vector< Real > &gmod, const Vector< Real > &x, Real del, TrustRegionModel_U< Real > &model, Objective< Real > &nobj, Vector< Real > &s, Vector< Real > &pwa1, Vector< Real > &pwa2, Vector< Real > &pwa3, Vector< Real > &pwa4, Vector< Real > &pwa5, Vector< Real > &dwa, std::ostream &outStream=std::cout)
unsigned verbosity_
Output level (default: 0).
TrustRegionAlgorithm(ParameterList &list, const Ptr< Secant< Real > > &secant=nullPtr)
ESecant esec_
Secant type (default: Limited-Memory BFGS).
Real gamma1_
Radius decrease rate (positive rho) (default: 0.25).
void dprox(Vector< Real > &x, const Vector< Real > &x0, Real t, Real del, Objective< Real > &nobj, Vector< Real > &y0, Vector< Real > &y1, Vector< Real > &yc, Vector< Real > &pwa, std::ostream &outStream=std::cout) const
void dspg(Vector< Real > &y, Real &sval, Real &nval, Vector< Real > &gmod, const Vector< Real > &x, Real del, TrustRegionModel_U< Real > &model, Objective< Real > &nobj, Vector< Real > &ymin, Vector< Real > &pwa, Vector< Real > &pwa1, Vector< Real > &pwa2, Vector< Real > &pwa3, Vector< Real > &pwa4, Vector< Real > &pwa5, Vector< Real > &dwa, std::ostream &outStream=std::cout)
void initialize(Vector< Real > &x, const Vector< Real > &g, Real ftol, Objective< Real > &sobj, Objective< Real > &nobj, Vector< Real > &px, Vector< Real > &dg, std::ostream &outStream=std::cout)
void writeName(std::ostream &os) const override
Print step name.
Real gamma0_
Radius decrease rate (negative rho) (default: 0.0625).
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
bool interpRad_
Interpolate the trust-region radius if ratio is negative (default: false).
int SPiter_
Subproblem solver iteration count.
int explim_
Maximum number of Cauchy point expansion steps (default: 10).
Real computeValue(Real inTol, Real &outTol, Real pRed, Real &fold, int iter, const Vector< Real > &x, const Vector< Real > &xold, Objective< Real > &obj)
Real tol1_
Absolute tolerance for truncated CG (default: 1e-4).
Real mu0_
Sufficient decrease parameter (default: 1e-2).
Real qtol_
Relative tolerance for computed decrease in Cauchy point computation (default: 1-8).
Real interpf_
Backtracking rate for Cauchy point computation (default: 1e-1).
Real delMax_
Maximum trust-region radius (default: ROL_INF).
Real alpha_
Initial Cauchy point step length (default: 1.0).
Real dcauchy(Vector< Real > &s, Real &alpha, Real &sval, Real &nval, const Vector< Real > &x, const Vector< Real > &g, Real del, TrustRegionModel_U< Real > &model, Objective< Real > &nobj, Vector< Real > &px, Vector< Real > &dwa, Vector< Real > &dwa1, std::ostream &outStream=std::cout)
Real computeGradient(const Vector< Real > &x, Vector< Real > &g, Vector< Real > &px, Vector< Real > &dg, Vector< Real > &pwa, Real del, Objective< Real > &sobj, Objective< Real > &nobj, std::ostream &outStream=std::cout) const
bool normAlpha_
Normalize initial Cauchy point step length (default: false).
Real TRsafe_
Safeguard size for numerically evaluating ratio (default: 1e2).
Real extrapf_
Extrapolation rate for Cauchy point computation (default: 1e1).
Real eta2_
Radius increase threshold (default: 0.9).
void writeHeader(std::ostream &os) const override
Print iterate header.
Ptr< TrustRegionModel_U< Real > > model_
Container for trust-region model.
Real eps_
Safeguard for numerically evaluating ratio.
int redlim_
Maximum number of Cauchy point reduction steps (default: 10).
void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, std::ostream &outStream=std::cout) override
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
bool writeHeader_
Flag to write header at every iteration.
Real tol2_
Relative tolerance for truncated CG (default: 1e-2).
Real spexp_
Relative tolerance exponent for subproblem solve (default: 1, range: [1,2]).
Real eta1_
Radius decrease threshold (default: 0.05).
int SPflag_
Subproblem solver termination flag.
bool useSecantHessVec_
Flag to use secant as Hessian (default: false).
Real eta0_
Step acceptance threshold (default: 0.05).
int maxit_
Maximum number of CG iterations (default: 25).
bool useSecantPrecond_
Flag to use secant as a preconditioner (default: false).
Real gamma2_
Radius increase rate (default: 2.5).
int nhess_
Number of Hessian applications.
void dspg2(Vector< Real > &y, Real &sval, Real &nval, Real &pRed, Vector< Real > &gmod, const Vector< Real > &x, Real del, TrustRegionModel_U< Real > &model, Objective< Real > &nobj, Vector< Real > &pwa, Vector< Real > &pwa1, Vector< Real > &pwa2, Vector< Real > &dwa, std::ostream &outStream=std::cout)
Defines the linear algebra or vector space interface.
ETrustRegionP StringToETrustRegionP(std::string s)
std::string ETrustRegionPToString(ETrustRegionP alg)
EAlgorithmP & operator--(EAlgorithmP &type)
EAlgorithmP & operator++(EAlgorithmP &type)
int isValidTrustRegionP(ETrustRegionP alg)
std::string removeStringFormat(std::string s)