19 #include "ROL_Elementwise_Function.hpp"
20 #include "ROL_Elementwise_Reduce.hpp"
38 Real
apply(
const Real &x,
const Real &y)
const {
39 const Real
zero(0), one(1);
40 return (x >
zero && y <
zero) ? -x/y : -one;
46 Real
apply(
const Real &x,
const Real &y)
const {
47 const Real
zero(0), one(1);
48 return (x >
zero && y >
zero) ? x/y : -one;
54 void reduce(
const Real &input, Real &output)
const {
56 output = (input<output && input>
zero) ? input : output;
58 void reduce(
const volatile Real &input, Real
volatile &output )
const {
60 output = (input<output && input>
zero) ? input : output;
63 return ROL_INF<Real>();
66 return Elementwise::REDUCE_MIN;
72 void reduce(
const Real &input, Real &output)
const {
74 output = (input>output && input>
zero) ? input : output;
76 void reduce(
const volatile Real &input, Real
volatile &output )
const {
78 output = (input>output && input>
zero) ? input : output;
81 return static_cast<Real
>(0);
84 return Elementwise::REDUCE_MAX;
93 Real em4(1e-4), em2(1e-2);
94 maxit_ = parlist.sublist(
"General").sublist(
"Krylov").get(
"Iteration Limit",20);
95 tol1_ = parlist.sublist(
"General").sublist(
"Krylov").get(
"Absolute Tolerance",em4);
96 tol2_ = parlist.sublist(
"General").sublist(
"Krylov").get(
"Relative Tolerance",em2);
98 verbosity_ = parlist.sublist(
"General").get(
"Print Verbosity", 0);
114 const Real
zero(0), half(0.5), one(1);
115 Real tol0 = std::sqrt(ROL_EPSILON<Real>());
116 Real gfnorm(0), gfnormf(0), tol(0), stol(0);
121 x_->set(*model.getIterate());
123 model.getBoundConstraint()->project(*
x_);
126 s.
set(*
x_); s.
axpy(-one,*model.getIterate());
128 g_->plus(*model.getGradient());
129 model.getBoundConstraint()->pruneActive(*
g_,*
x_,
zero);
132 std::cout << std::endl;
133 std::cout <<
" Computation of Cauchy point" << std::endl;
134 std::cout <<
" Step length (alpha): " <<
alpha_ << std::endl;
135 std::cout <<
" Step length (alpha*g): " << snorm << std::endl;
136 std::cout <<
" Norm of Cauchy point: " <<
x_->norm() << std::endl;
137 std::cout <<
" Norm of free gradient components: " << gfnorm << std::endl;
144 for (
int i = 0; i <
dim; ++i) {
146 int flagCG = 0, iterCG = 0;
154 std::cout << std::endl;
155 std::cout <<
" Computation of CG step" << std::endl;
156 std::cout <<
" Number of faces: " << dim << std::endl;
157 std::cout <<
" Current face (i): " << i << std::endl;
158 std::cout <<
" CG step length: " << snorm << std::endl;
159 std::cout <<
" Number of CG iterations: " << iterCG << std::endl;
160 std::cout <<
" CG flag: " << flagCG << std::endl;
161 std::cout <<
" Total number of iterations: " << iter << std::endl;
167 std::cout <<
" Step length (beta*s): " << snorm << std::endl;
168 std::cout <<
" Iterate length: " <<
x_->norm() << std::endl;
172 s.
set(*
x_); s.
axpy(-one,*model.getIterate());
174 g_->plus(*model.getGradient());
175 model.getBoundConstraint()->pruneActive(*
g_,*
x_,
zero);
176 gfnormf =
g_->norm();
178 std::cout << std::endl;
179 std::cout <<
" Update model gradient" << std::endl;
180 std::cout <<
" Step length: " << s.
norm() << std::endl;
181 std::cout <<
" Norm of free gradient components: " << gfnormf << std::endl;
182 std::cout << std::endl;
186 if (gfnormf <=
tol2_*gfnorm) {
190 else if (iter >=
maxit_) {
194 else if (flagCG == 2) {
198 else if (flagCG == 3) {
210 gs = s.
dot(model.getGradient()->dual());
211 q = half * s.
dot(
dwa1_->dual()) + gs;
229 s.
axpy(static_cast<Real>(-1),x);
243 Real &bpmin, Real &bpmax,
245 const Real
zero(0), one(1);
246 bpmin = one; bpmax =
zero;
247 Real lbpmin = one, lbpmax =
zero, ubpmin = one, ubpmax =
zero;
268 bpmin = std::min(lbpmin,ubpmin);
269 bpmax = std::max(lbpmax,ubpmax);
275 std::cout << std::endl;
276 std::cout <<
" Computation of break points" << std::endl;
277 std::cout <<
" Minimum break point: " << bpmin << std::endl;
278 std::cout <<
" Maximum break point: " << bpmax << std::endl;
297 const Real half(0.5), one(1), mu0(0.01), interpf(0.1), extrapf(10);
299 Real tol = std::sqrt(ROL_EPSILON<Real>());
301 Real q(0), gs(0), bpmin(0), bpmax(0), snorm(0);
304 dbreakpt(x,pwa1,model,bpmin,bpmax,pwa2);
306 snorm =
dgpstep(s,g,x,-alpha,model);
313 q = half * s.
dot(dwa.
dual()) + gs;
314 interp = (q > mu0*gs);
321 snorm =
dgpstep(s,g,x,-alpha,model);
325 q = half * s.
dot(dwa.
dual()) + gs;
326 search = (q > mu0*gs);
333 while (search && alpha <= bpmax) {
335 snorm =
dgpstep(s,g,x,-alpha,model);
339 q = half * s.
dot(dwa.
dual()) + gs;
350 snorm =
dgpstep(s,g,x,-alpha,model);
366 const Real half(0.5), one(1), mu0(0.01), interpf(0.5);
367 Real tol = std::sqrt(ROL_EPSILON<Real>());
368 Real beta(1), snorm(0), q(0), gs(0), bpmin(0), bpmax(0);
371 dbreakpt(x,s,model,bpmin,bpmax,pwa);
374 while (search && beta > bpmin) {
376 snorm =
dgpstep(pwa,s,x,beta,model);
379 q = half * s.
dot(dwa.
dual()) + gs;
387 if (beta < one && beta < bpmin) {
390 snorm =
dgpstep(pwa,s,x,beta,model);
394 std::cout << std::endl;
395 std::cout <<
" Projected search" << std::endl;
396 std::cout <<
" Step length (beta): " << beta << std::endl;
408 Real
dtrqsol(
const Real xtx,
const Real ptp,
const Real ptx,
const Real del) {
411 Real rad = ptx*ptx + ptp*(dsq-xtx);
412 rad = std::sqrt(std::max(rad,zero));
415 sigma = (dsq-xtx)/(ptx+rad);
417 else if (rad > zero) {
418 sigma = (rad-ptx)/ptp;
444 const Real tol,
const Real stol,
const int itermax,
447 Real tol0 = std::sqrt(ROL_EPSILON<Real>());
448 const Real
zero(0), one(1), two(2);
449 Real rho(0), tnorm(0), rnorm(0), rnorm0(0), kappa(0), beta(0), sigma(0), alpha(0), rtr(0);
450 Real sMs(0), pMp(0), sMp(0);
459 rnorm0 = std::sqrt(rho);
460 if ( rnorm0 ==
zero ) {
467 for (iter = 0; iter < itermax; ++iter) {
472 alpha = (kappa>
zero) ? rho/kappa :
zero;
473 sigma =
dtrqsol(sMs,pMp,sMp,del);
475 if (kappa <= zero || alpha >= sigma) {
477 iflag = (kappa<=
zero) ? 2 : 3;
486 rnorm = std::sqrt(rtr);
488 if (rnorm <= stol || tnorm <= tol) {
500 sMs = sMs + two*alpha*sMp + alpha*alpha*pMp;
501 sMp = beta*(sMp + alpha*pMp);
502 pMp = rho + beta*beta*pMp;
505 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