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) {
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
void dbreakpt(const Vector< Real > &x, const Vector< Real > &s, TrustRegionModel< Real > &model, Real &bpmin, Real &bpmax, Vector< Real > &pwa)
Provides interface for truncated CG trust-region subproblem solver.
virtual void scale(const Real alpha)=0
Compute where .
Real apply(const Real &x, const Real &y) const
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual int dimension() const
Return dimension of the vector space.
virtual void plus(const Vector &x)=0
Compute , where .
void run(Vector< Real > &s, Real &snorm, int &iflag, int &iter, const Real del, TrustRegionModel< Real > &model)
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Ptr< Vector< Real > > dwa2_
virtual Real reduce(const Elementwise::ReductionOp< Real > &r) const
virtual void applyBinary(const Elementwise::BinaryFunction< Real > &f, const Vector &x)
virtual void initialize(const Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g)
LinMore(ROL::ParameterList &parlist)
Provides the interface to evaluate projected trust-region model functions from the Kelley-Sachs bound...
void reduce(const Real &input, Real &output) const
Provides interface for and implements trust-region subproblem solvers.
Provides the interface to evaluate trust-region model functions.
virtual void zero()
Set to zero vector.
Defines the linear algebra or vector space interface.
virtual const Ptr< const Vector< Real > > getGradient(void) const
Real dcauchy(Vector< Real > &s, Real &alpha, const Vector< Real > &x, const Vector< Real > &g, const Real del, TrustRegionModel< Real > &model, Vector< Real > &pwa1, Vector< Real > &pwa2, Vector< Real > &dwa)
ROL::LinMore::PositiveMax pmax_
ROL::LinMore::UpperBreakPoint ubp_
Ptr< Vector< Real > > pwa2_
virtual Real dot(const Vector &x) const =0
Compute where .
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Real dgpstep(Vector< Real > &s, const Vector< Real > &w, const Vector< Real > &x, const Real alpha, TrustRegionModel< Real > &model) const
void reduce(const Real &input, Real &output) const
void initialize(const Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g)
void setPredictedReduction(const Real pRed)
void reduce(const volatile Real &input, Real volatile &output) const
Real dtrpcg(Vector< Real > &w, int &iflag, int &iter, const Vector< Real > &g, const Vector< Real > &x, const Real del, TrustRegionModel< Real > &model, const Real tol, const Real stol, const int itermax, Vector< Real > &p, Vector< Real > &q, Vector< Real > &r, Vector< Real > &t)
ROL::LinMore::LowerBreakPoint lbp_
Real dprsrch(Vector< Real > &x, Vector< Real > &s, const Vector< Real > &g, TrustRegionModel< Real > &model, Vector< Real > &pwa, Vector< Real > &dwa)
Ptr< Vector< Real > > pwa1_
Real initialValue() const
Elementwise::EReductionType reductionType() const
Ptr< Vector< Real > > dwa1_
Elementwise::EReductionType reductionType() const
virtual void set(const Vector &x)
Set where .
virtual Real norm() const =0
Returns where .
Real dtrqsol(const Real xtx, const Real ptp, const Real ptx, const Real del)
ROL::LinMore::PositiveMin pmin_
virtual const Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
void reduce(const volatile Real &input, Real volatile &output) const
virtual const Ptr< const Vector< Real > > getIterate(void) const
Real initialValue() const
Real apply(const Real &x, const Real &y) const