53 #include "ROL_Elementwise_Function.hpp"
54 #include "ROL_Elementwise_Reduce.hpp"
72 Real
apply(
const Real &x,
const Real &y)
const {
73 const Real
zero(0), one(1);
74 return (x >
zero && y <
zero) ? -x/y : -one;
80 Real
apply(
const Real &x,
const Real &y)
const {
81 const Real
zero(0), one(1);
82 return (x >
zero && y >
zero) ? x/y : -one;
88 void reduce(
const Real &input, Real &output)
const {
90 output = (input<output && input>
zero) ? input : output;
92 void reduce(
const volatile Real &input, Real
volatile &output )
const {
94 output = (input<output && input>
zero) ? input : output;
97 return ROL_INF<Real>();
100 return Elementwise::REDUCE_MIN;
106 void reduce(
const Real &input, Real &output)
const {
108 output = (input>output && input>
zero) ? input : output;
110 void reduce(
const volatile Real &input, Real
volatile &output )
const {
112 output = (input>output && input>
zero) ? input : output;
115 return static_cast<Real>(0);
118 return Elementwise::REDUCE_MAX;
127 Real em4(1e-4), em2(1e-2);
128 maxit_ = parlist.sublist(
"General").sublist(
"Krylov").get(
"Iteration Limit",20);
129 tol1_ = parlist.sublist(
"General").sublist(
"Krylov").get(
"Absolute Tolerance",em4);
130 tol2_ = parlist.sublist(
"General").sublist(
"Krylov").get(
"Relative Tolerance",em2);
132 verbosity_ = parlist.sublist(
"General").get(
"Print Verbosity", 0);
148 const Real
zero(0), half(0.5), one(1);
149 Real tol0 = std::sqrt(ROL_EPSILON<Real>());
150 Real gfnorm(0), gfnormf(0), tol(0), stol(0);
155 x_->set(*model.getIterate());
157 model.getBoundConstraint()->project(*
x_);
160 s.
set(*
x_); s.
axpy(-one,*model.getIterate());
162 g_->plus(*model.getGradient());
163 model.getBoundConstraint()->pruneActive(*
g_,*
x_,
zero);
166 std::cout << std::endl;
167 std::cout <<
" Computation of Cauchy point" << std::endl;
168 std::cout <<
" Step length (alpha): " <<
alpha_ << std::endl;
169 std::cout <<
" Step length (alpha*g): " << snorm << std::endl;
170 std::cout <<
" Norm of Cauchy point: " <<
x_->norm() << std::endl;
171 std::cout <<
" Norm of free gradient components: " << gfnorm << std::endl;
178 for (
int i = 0; i < dim; ++i) {
180 int flagCG = 0, iterCG = 0;
188 std::cout << std::endl;
189 std::cout <<
" Computation of CG step" << std::endl;
190 std::cout <<
" Number of faces: " << dim << std::endl;
191 std::cout <<
" Current face (i): " << i << std::endl;
192 std::cout <<
" CG step length: " << snorm << std::endl;
193 std::cout <<
" Number of CG iterations: " << iterCG << std::endl;
194 std::cout <<
" CG flag: " << flagCG << std::endl;
195 std::cout <<
" Total number of iterations: " << iter << std::endl;
201 std::cout <<
" Step length (beta*s): " << snorm << std::endl;
202 std::cout <<
" Iterate length: " <<
x_->norm() << std::endl;
206 s.
set(*
x_); s.
axpy(-one,*model.getIterate());
208 g_->plus(*model.getGradient());
209 model.getBoundConstraint()->pruneActive(*
g_,*
x_,
zero);
210 gfnormf =
g_->norm();
212 std::cout << std::endl;
213 std::cout <<
" Update model gradient" << std::endl;
214 std::cout <<
" Step length: " << s.
norm() << std::endl;
215 std::cout <<
" Norm of free gradient components: " << gfnormf << std::endl;
216 std::cout << std::endl;
220 if (gfnormf <=
tol2_*gfnorm) {
224 else if (iter >=
maxit_) {
228 else if (flagCG == 2) {
232 else if (flagCG == 3) {
244 gs = s.
dot(model.getGradient()->dual());
245 q = half * s.
dot(
dwa1_->dual()) + gs;
263 s.
axpy(static_cast<Real>(-1),x);
277 Real &bpmin, Real &bpmax,
279 const Real
zero(0), one(1);
280 bpmin = one; bpmax =
zero;
281 Real lbpmin = one, lbpmax =
zero, ubpmin = one, ubpmax =
zero;
302 bpmin = std::min(lbpmin,ubpmin);
303 bpmax = std::max(lbpmax,ubpmax);
309 std::cout << std::endl;
310 std::cout <<
" Computation of break points" << std::endl;
311 std::cout <<
" Minimum break point: " << bpmin << std::endl;
312 std::cout <<
" Maximum break point: " << bpmax << std::endl;
331 const Real half(0.5), one(1), mu0(0.01), interpf(0.1), extrapf(10);
333 Real tol = std::sqrt(ROL_EPSILON<Real>());
335 Real q(0), gs(0), bpmin(0), bpmax(0), snorm(0);
338 dbreakpt(x,pwa1,model,bpmin,bpmax,pwa2);
340 snorm =
dgpstep(s,g,x,-alpha,model);
347 q = half * s.
dot(dwa.
dual()) + gs;
348 interp = (q > mu0*gs);
355 snorm =
dgpstep(s,g,x,-alpha,model);
359 q = half * s.
dot(dwa.
dual()) + gs;
360 search = (q > mu0*gs);
367 while (search && alpha <= bpmax) {
369 snorm =
dgpstep(s,g,x,-alpha,model);
373 q = half * s.
dot(dwa.
dual()) + gs;
384 snorm =
dgpstep(s,g,x,-alpha,model);
400 const Real half(0.5), one(1), mu0(0.01), interpf(0.5);
401 Real tol = std::sqrt(ROL_EPSILON<Real>());
402 Real beta(1), snorm(0), q(0), gs(0), bpmin(0), bpmax(0);
405 dbreakpt(x,s,model,bpmin,bpmax,pwa);
408 while (search && beta > bpmin) {
410 snorm =
dgpstep(pwa,s,x,beta,model);
413 q = half * s.
dot(dwa.
dual()) + gs;
421 if (beta < one && beta < bpmin) {
424 snorm =
dgpstep(pwa,s,x,beta,model);
428 std::cout << std::endl;
429 std::cout <<
" Projected search" << std::endl;
430 std::cout <<
" Step length (beta): " << beta << std::endl;
442 Real
dtrqsol(
const Real xtx,
const Real ptp,
const Real ptx,
const Real del) {
445 Real rad = ptx*ptx + ptp*(dsq-xtx);
446 rad = std::sqrt(std::max(rad,
zero));
449 sigma = (dsq-xtx)/(ptx+rad);
451 else if (rad >
zero) {
452 sigma = (rad-ptx)/ptp;
478 const Real tol,
const Real stol,
const int itermax,
481 Real tol0 = std::sqrt(ROL_EPSILON<Real>());
482 const Real
zero(0), one(1), two(2);
483 Real rho(0), tnorm(0), rnorm(0), rnorm0(0), kappa(0), beta(0), sigma(0), alpha(0), rtr(0);
484 Real sMs(0), pMp(0), sMp(0);
493 rnorm0 = std::sqrt(rho);
494 if ( rnorm0 ==
zero ) {
501 for (iter = 0; iter < itermax; ++iter) {
506 alpha = (kappa>
zero) ? rho/kappa :
zero;
507 sigma =
dtrqsol(sMs,pMp,sMp,del);
509 if (kappa <= zero || alpha >= sigma) {
511 iflag = (kappa<=
zero) ? 2 : 3;
520 rnorm = std::sqrt(rtr);
522 if (rnorm <= stol || tnorm <= tol) {
534 sMs = sMs + two*alpha*sMp + alpha*alpha*pMp;
535 sMp = beta*(sMp + alpha*pMp);
536 pMp = rho + beta*beta*pMp;
539 if (iter == itermax) {