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 
47 #include "ROL_TypeP_Algorithm.hpp"
50 #include "ROL_Types.hpp"
51 
56 namespace ROL {
57 namespace TypeP {
58 
64 };
65 
66 inline 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 
106 inline ETrustRegionP StringToETrustRegionP(std::string s) {
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 
116 template<typename Real>
118 private:
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_;
131  bool interpRad_;
132 
133  // ITERATION FLAGS/INFORMATION
135  int SPflag_;
136  int SPiter_;
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_;
153  int redlim_;
154  int explim_;
155  Real alpha_;
156  bool normAlpha_;
157  Real interpf_;
158  Real extrapf_;
159  Real qtol_;
162  Real gamma_;
163  int maxSize_;
164  bool useMin_;
165  bool useNMSP_;
167  int ncgType_;
168  Real etaNCG_;
169  Real desPar_;
170 
171  // Inexactness Parameters
172  std::vector<bool> useInexact_;
173  Real scale0_;
174  Real scale1_;
175  Real scale_;
176  Real omega_;
177  Real force_;
180  Real gtol_;
181 
182  bool initProx_;
183  Real t0_;
184 
185  mutable int nhess_;
186  unsigned verbosity_;
188 
192 
193  void initialize(Vector<Real> &x,
194  const Vector<Real> &g,
195  Real ftol,
196  Objective<Real> &sobj,
197  Objective<Real> &nobj,
198  Vector<Real> &px,
199  Vector<Real> &dg,
200  std::ostream &outStream = std::cout);
201 
202 public:
203  TrustRegionAlgorithm(ParameterList &list, const Ptr<Secant<Real>> &secant = nullPtr);
204 
206  void run( Vector<Real> &x,
207  const Vector<Real> &g,
208  Objective<Real> &sobj,
209  Objective<Real> &nobj,
210  std::ostream &outStream = std::cout) override;
211 
212  void writeHeader( std::ostream& os ) const override;
213 
214  void writeName( std::ostream& os ) const override;
215 
216  void writeOutput( std::ostream& os, bool write_header = false ) const override;
217 
218 private:
219 
220  Real computeValue(Real inTol,
221  Real &outTol,
222  Real pRed,
223  Real &fold,
224  int iter,
225  const Vector<Real> &x,
226  const Vector<Real> &xold,
227  Objective<Real> &obj);
228 
229  void computeGradient(const Vector<Real> &x,
230  Vector<Real> &g,
231  Vector<Real> &px,
232  Vector<Real> &dg,
233  Vector<Real> &pwa,
234  Real del,
235  Objective<Real> &sobj,
236  Objective<Real> &nobj,
237  bool accept,
238  Real &gtol,
239  Real &gnorm,
240  std::ostream &outStream = std::cout) const;
241 
242  // Compute the projected step s = P(x + alpha*w) - x
243  // Returns the norm of the projected step s
244  // s -- The projected step upon return
245  // w -- The direction vector w (unchanged)
246  // x -- The anchor vector x (unchanged)
247  // alpha -- The step size (unchanged)
248  // Real dgpstep(Vector<Real> &s, const Vector<Real> &w,
249  // const Vector<Real> &x, const Real alpha,
250  // std::ostream &outStream = std::cout) const;
251 
252  // Compute Cauchy point, i.e., the minimizer of q(P(x - alpha*g)-x)
253  // subject to the trust region constraint ||P(x - alpha*g)-x|| <= del
254  // s -- The Cauchy step upon return: Primal optimization space vector
255  // alpha -- The step length for the Cauchy point upon return
256  // x -- The anchor vector x (unchanged): Primal optimization space vector
257  // g -- The (dual) gradient vector g (unchanged): Primal optimization space vector
258  // del -- The trust region radius (unchanged)
259  // model -- Trust region model
260  // dwa -- Dual working array, stores Hessian applied to step
261  // dwa1 -- Dual working array
262  Real dcauchy(Vector<Real> &s,
263  Real &alpha,
264  Real &sval,
265  Real &nval,
266  const Vector<Real> &x,
267  const Vector<Real> &g,
268  Real del,
270  Objective<Real> &nobj,
271  Vector<Real> &px,
272  Vector<Real> &dwa,
273  Vector<Real> &dwa1,
274  std::ostream &outStream = std::cout);
275 
276  void dspg2(Vector<Real> &y,
277  Real &sval,
278  Real &nval,
279  Real &pRed,
280  Vector<Real> &gmod,
281  const Vector<Real> &x,
282  Real del,
283  TrustRegionModel_U<Real> &model,
284  Objective<Real> &nobj,
285  Vector<Real> &pwa,
286  Vector<Real> &pwa1,
287  Vector<Real> &pwa2,
288  Vector<Real> &dwa,
289  std::ostream &outStream = std::cout);
290 
291  void dspg(Vector<Real> &y,
292  Real &sval,
293  Real &nval,
294  Vector<Real> &gmod,
295  const Vector<Real> &x,
296  Real del,
297  TrustRegionModel_U<Real> &model,
298  Objective<Real> &nobj,
299  Vector<Real> &ymin,
300  Vector<Real> &pwa,
301  Vector<Real> &pwa1,
302  Vector<Real> &pwa2,
303  Vector<Real> &pwa3,
304  Vector<Real> &pwa4,
305  Vector<Real> &pwa5,
306  Vector<Real> &dwa,
307  std::ostream &outStream = std::cout);
308 
309  void dncg(Vector<Real> &y,
310  Real &sval,
311  Real &nval,
312  Vector<Real> &gmod,
313  const Vector<Real> &x,
314  Real del,
315  TrustRegionModel_U<Real> &model,
316  Objective<Real> &nobj,
317  Vector<Real> &s,
318  Vector<Real> &pwa1,
319  Vector<Real> &pwa2,
320  Vector<Real> &pwa3,
321  Vector<Real> &pwa4,
322  Vector<Real> &pwa5,
323  Vector<Real> &dwa,
324  std::ostream &outStream = std::cout);
325 
326 
327  void dprox(Vector<Real> &x,
328  const Vector<Real> &x0,
329  Real t,
330  Real del,
331  Objective<Real> &nobj,
332  Vector<Real> &y0,
333  Vector<Real> &y1,
334  Vector<Real> &yc,
335  Vector<Real> &pwa,
336  std::ostream &outStream = std::cout) const;
337 
338  void dbls(Real &alpha, Real &nval, Real &pred,
339  const Vector<Real> &y,
340  const Vector<Real> &s,
341  Real lambda, Real tmax,
342  Real kappa, Real gs,
343  Objective<Real> &nobj,
344  Vector<Real> &pwa);
345 
346 }; // class ROL::TypeP::TrustRegionAlgorithm
347 
348 } // namespace TypeP
349 } // namespace ROL
350 
352 
353 #endif
Real alpha_
Initial Cauchy point step length (default: 1.0)
Provides the interface to evaluate objective functions.
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)
Real computeValue(Real inTol, Real &outTol, Real pRed, Real &fold, int iter, const Vector< Real > &x, const Vector< Real > &xold, Objective< Real > &obj)
Real eps_
Safeguard for numerically evaluating ratio.
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)
Real mu0_
Sufficient decrease parameter (default: 1e-2)
TrustRegionAlgorithm(ParameterList &list, const Ptr< Secant< Real >> &secant=nullPtr)
Real tol2_
Relative tolerance for truncated CG (default: 1e-2)
int explim_
Maximum number of Cauchy point expansion steps (default: 10)
bool useSecantPrecond_
Flag to use secant as a preconditioner (default: false)
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)
Real eta2_
Radius increase threshold (default: 0.9)
int SPiter_
Subproblem solver iteration count.
EAlgorithmP & operator--(EAlgorithmP &type)
Real eta0_
Step acceptance threshold (default: 0.05)
Contains definitions of custom data types in ROL.
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:249
Ptr< TrustRegionModel_U< Real > > model_
Container for trust-region model.
std::string ETrustRegionPToString(ETrustRegionP alg)
bool writeHeader_
Flag to write header at every iteration.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
int redlim_
Maximum number of Cauchy point reduction steps (default: 10)
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 eta1_
Radius decrease threshold (default: 0.05)
void dbls(Real &alpha, Real &nval, Real &pred, const Vector< Real > &y, const Vector< Real > &s, Real lambda, Real tmax, Real kappa, Real gs, Objective< Real > &nobj, Vector< Real > &pwa)
ETRFlag
Enumation of flags used by trust-region solvers.
bool useSecantHessVec_
Flag to use secant as Hessian (default: false)
ETrustRegionP StringToETrustRegionP(std::string s)
Real TRsafe_
Safeguard size for numerically evaluating ratio (default: 1e2)
Provides the interface to evaluate trust-region model functions.
ESecant
Enumeration of secant update algorithms.
Definition: ROL_Types.hpp:486
Real tol1_
Absolute tolerance for truncated CG (default: 1e-4)
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...
Real extrapf_
Extrapolation rate for Cauchy point computation (default: 1e1)
Provides interface for and implements limited-memory secant operators.
Definition: ROL_Secant.hpp:79
Real gamma1_
Radius decrease rate (positive rho) (default: 0.25)
Real spexp_
Relative tolerance exponent for subproblem solve (default: 1, range: [1,2])
int SPflag_
Subproblem solver termination flag.
int isValidTrustRegionP(ETrustRegionP alg)
int nhess_
Number of Hessian applications.
ESecant esec_
Secant type (default: Limited-Memory BFGS)
void writeOutput(std::ostream &os, bool write_header=false) const override
Print iterate status.
unsigned verbosity_
Output level (default: 0)
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
TRUtils::ETRFlag TRflag_
Trust-region exit flag.
Real gamma0_
Radius decrease rate (negative rho) (default: 0.0625)
Real interpf_
Backtracking rate for Cauchy point computation (default: 1e-1)
Provides an interface to run the trust-region algorithm.
bool interpRad_
Interpolate the trust-region radius if ratio is negative (default: false)
Real delMax_
Maximum trust-region radius (default: ROL_INF)
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)
Real qtol_
Relative tolerance for computed decrease in Cauchy point computation (default: 1-8) ...
Real gamma2_
Radius increase rate (default: 2.5)
Provides an interface to run optimization algorithms to minimize composite optimization problems f+ph...
void writeName(std::ostream &os) const override
Print step name.
void 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, bool accept, Real &gtol, Real &gnorm, std::ostream &outStream=std::cout) const
void writeHeader(std::ostream &os) const override
Print iterate header.
int maxit_
Maximum number of CG iterations (default: 25)
EAlgorithmP & operator++(EAlgorithmP &type)
bool normAlpha_
Normalize initial Cauchy point step length (default: false)