44 #ifndef ROL_BUNDLE_U_AS_DEF_H
45 #define ROL_BUNDLE_U_AS_DEF_H
49 template<
typename Real>
53 const unsigned remSize)
54 :
Bundle_U<Real>(maxSize,coeff,omega,remSize), isInitialized_(false) {}
56 template<
typename Real>
59 if ( !isInitialized_ ) {
65 isInitialized_ =
true;
69 template<
typename Real>
79 iter = solveDual_arbitrary(t,maxit,tol);
84 template<
typename Real>
87 Real sum(0), err(0), tmp(0), y(0);
88 for (
unsigned i = 0; i < Bundle_U<Real>::size(); ++i) {
93 err = (tmp - sum) - y;
96 for (
unsigned i = 0; i < Bundle_U<Real>::size(); ++i) {
100 nworkingSet_.clear();
102 for (
unsigned i = 0; i < Bundle_U<Real>::size(); ++i) {
104 workingSet_.insert(i);
107 nworkingSet_.insert(i);
112 template<
typename Real>
115 unsigned n = workingSet_.size();
118 typename std::set<unsigned>::iterator it = workingSet_.begin();
119 for (
unsigned i = 0; i < n; ++i) {
120 lam[i] = g[*it] - mu; it++;
128 template<
typename Real>
131 unsigned n = workingSet_.size();
134 Real min = ROL_OVERFLOW<Real>();
135 typename std::set<unsigned>::iterator it = workingSet_.begin();
136 for (
unsigned i = 0; i < n; ++i) {
143 flag = ((min < -ROL_EPSILON<Real>()) ?
false :
true);
148 template<
typename Real>
151 Real alpha(1), tmp(0);
153 typename std::set<unsigned>::iterator it;
154 for (it = nworkingSet_.begin(); it != nworkingSet_.end(); it++) {
155 if ( p[*it] < -ROL_EPSILON<Real>() ) {
156 tmp = -x[*it]/p[*it];
157 if ( alpha >= tmp ) {
163 return std::max(zero,alpha);
166 template<
typename Real>
168 const std::vector<Real> &g,
const Real tol)
const {
171 unsigned n = nworkingSet_.size(), cnt = 0;
175 std::vector<Real> gk(n,zero);
176 typename std::set<unsigned>::iterator it = nworkingSet_.begin();
177 for (
unsigned i = 0; i < n; ++i) {
178 gk[i] = g[*it]; it++;
180 std::vector<Real> sk(n,zero);
181 cnt = projectedCG(sk,mu,gk,tol);
182 it = nworkingSet_.begin();
183 for (
unsigned i = 0; i < n; ++i) {
184 s[*it] = sk[i]; it++;
190 template<
typename Real>
194 std::vector<Real> tmp(Px.size(),
zero);
196 case 0: applyPreconditioner_Identity(tmp,x);
break;
197 case 1: applyPreconditioner_Jacobi(tmp,x);
break;
198 case 2: applyPreconditioner_SymGS(tmp,x);
break;
200 applyPreconditioner_Identity(Px,tmp);
203 template<
typename Real>
207 case 0: applyG_Identity(Gx,x);
break;
208 case 1: applyG_Jacobi(Gx,x);
break;
209 case 2: applyG_SymGS(Gx,x);
break;
213 template<
typename Real>
215 unsigned dim = nworkingSet_.size();
216 Real sum(0), err(0), tmp(0), y(0);
217 for (
unsigned i = 0; i <
dim; ++i) {
222 err = (tmp - sum) - y;
226 for (
unsigned i = 0; i <
dim; ++i) {
231 template<
typename Real>
233 Gx.assign(x.begin(),x.end());
236 template<
typename Real>
238 const Real
zero(0), one(1);
239 unsigned dim = nworkingSet_.size();
241 Real errX(0), tmpX(0), yX(0), errE(0), tmpE(0), yE(0);
242 std::vector<Real> gg(dim,
zero);
243 typename std::set<unsigned>::iterator it = nworkingSet_.begin();
244 for (
unsigned i = 0; i <
dim; ++i) {
248 yX = x[i]*gg[i] - errX;
250 errX = (tmpX - sum) - yX;
256 errE = (tmpE - eHe) - yE;
260 for (
unsigned i = 0; i <
dim; ++i) {
261 Px[i] = (x[i]-sum)*gg[i];
265 template<
typename Real>
267 unsigned dim = nworkingSet_.size();
268 typename std::set<unsigned>::iterator it = nworkingSet_.begin();
269 for (
unsigned i = 0; i <
dim; ++i) {
274 template<
typename Real>
276 int dim = nworkingSet_.size();
278 gx_->zero(); ge_->zero();
279 Real eHx(0), eHe(0), one(1);
281 std::vector<Real> x1(dim,0), e1(dim,0),gg(dim,0);
282 typename std::set<unsigned>::iterator it, jt;
283 it = nworkingSet_.begin();
284 for (
int i = 0; i <
dim; ++i) {
285 gx_->zero(); ge_->zero(); jt = nworkingSet_.begin();
286 for (
int j = 0; j < i; ++j) {
297 for (
int i = 0; i <
dim; ++i) {
302 std::vector<Real> Hx(dim,0), He(dim,0); it = nworkingSet_.end();
303 for (
int i = dim-1; i >= 0; --i) {
305 gx_->zero(); ge_->zero(); jt = nworkingSet_.end();
306 for (
int j = dim-1; j >= i+1; --j) {
318 for (
int i = 0; i <
dim; ++i) {
319 Px[i] = Hx[i] - (eHx/eHe)*He[i];
323 template<
typename Real>
325 unsigned dim = nworkingSet_.size();
326 typename std::set<unsigned>::iterator it = nworkingSet_.begin();
327 for (
unsigned i = 0; i <
dim; ++i) {
332 template<
typename Real>
334 unsigned n = g.size();
335 std::vector<Real> Gg(n,0);
336 Real y(0), ytmp(0), yprt(0), yerr(0);
337 applyPreconditioner(g,r);
340 for (
unsigned i = 0; i < n; ++i) {
342 yprt = (r[i] - Gg[i]) - yerr;
344 yerr = (ytmp - y) - yprt;
348 for (
unsigned i = 0; i < n; ++i) {
351 applyPreconditioner(g,r);
354 template<
typename Real>
357 gx_->zero(); eG_->zero();
358 for (
unsigned i = 0; i < Bundle_U<Real>::size(); ++i) {
362 tG_->set(*gx_); tG_->plus(*yG_);
363 eG_->set(*tG_); eG_->axpy(-one,*gx_); eG_->axpy(-one,*yG_);
366 for (
unsigned i = 0; i < Bundle_U<Real>::size(); ++i) {
372 template<
typename Real>
375 gx_->zero(); eG_->zero();
376 unsigned n = nworkingSet_.size();
377 typename std::set<unsigned>::iterator it = nworkingSet_.begin();
378 for (
unsigned i = 0; i < n; ++i) {
382 tG_->set(*gx_); tG_->plus(*yG_);
383 eG_->set(*tG_); eG_->axpy(-one,*gx_); eG_->axpy(-one,*yG_);
387 it = nworkingSet_.begin();
388 for (
unsigned i = 0; i < n; ++i) {
394 template<
typename Real>
396 const Real one(1),
zero(0);
397 unsigned n = nworkingSet_.size();
398 std::vector<Real> r(n,0), r0(n,0), g(n,0), d(n,0), Ad(n,0);
402 r0.assign(r.begin(),r.end());
404 computeResidualUpdate(r,g);
405 Real rg = dot(r,g), rg0(0);
408 Real alpha(0), kappa(0), beta(0), TOL(1.e-2);
409 Real CGtol = std::min(tol,TOL*rg);
411 while (rg > CGtol && cnt < 2*n+1) {
418 computeResidualUpdate(r,g);
428 Real err(0), tmp(0), y(0);
429 for (
unsigned i = 0; i < n; ++i) {
433 err = (tmp - mu) - y;
436 mu /=
static_cast<Real
>(n);
441 template<
typename Real>
444 Real val(0), err(0), tmp(0), y0(0);
445 unsigned n = std::min(x.size(),y.size());
446 for (
unsigned i = 0; i < n; ++i) {
448 y0 = x[i]*y[i] - err;
450 err = (tmp - val) - y0;
456 template<
typename Real>
458 return std::sqrt(dot(x,x));
461 template<
typename Real>
463 unsigned n = std::min(y.size(),x.size());
464 for (
unsigned i = 0; i < n; ++i) {
469 template<
typename Real>
471 for (
unsigned i = 0; i < x.size(); ++i) {
476 template<
typename Real>
478 unsigned n = std::min(x.size(),y.size());
479 for (
unsigned i = 0; i < n; ++i) {
484 template<
typename Real>
486 const Real
zero(0), one(1);
487 initializeDualSolver();
489 unsigned ind = 0, i = 0, CGiter = 0;
490 Real snorm(0), alpha(0), mu(0);
494 for (
unsigned j = 0; j < Bundle_U<Real>::size(); ++j) {
499 for (i = 0; i < maxit; ++i) {
500 CGiter += solveEQPsubproblem(s,mu,g,tol);
502 if ( snorm < ROL_EPSILON<Real>() ) {
503 computeLagMult(lam,mu,g);
504 nonneg = isNonnegative(ind,lam);
511 workingSet_.erase(ind);
512 nworkingSet_.insert(ind);
517 alpha = computeStepSize(ind,dualVariables,s);
518 if ( alpha >
zero ) {
519 axpy(alpha,s,dualVariables);
520 applyFullMatrix(Hs,s);
524 workingSet_.insert(ind);
525 nworkingSet_.erase(ind);
533 for (
unsigned j = 0; j < Bundle_U<Real>::size(); ++j) {
539 template<
typename Real>
541 const Real
zero(0), one(1);
543 vsort.assign(v.begin(),v.end());
544 std::sort(vsort.begin(),vsort.end());
545 Real sum(-1), lam(0);
556 for (
unsigned i = 0; i < Bundle_U<Real>::size(); ++i) {
557 x[i] = std::max(
zero,v[i] - lam);
561 template<
typename Real>
563 const Real
zero(0), one(1);
bool isNonnegative(unsigned &ind, const std::vector< Real > &x) const
Real norm(const std::vector< Real > &x) const
unsigned solveDual_dim1(const Real t, const unsigned maxit=1000, const Real tol=1.e-8)
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void scale(std::vector< Real > &x, const Real a) const
void applyPreconditioner(std::vector< Real > &Px, const std::vector< Real > &x) const
void setDualVariable(const unsigned i, const Real val)
unsigned solveEQPsubproblem(std::vector< Real > &s, Real &mu, const std::vector< Real > &g, const Real tol) const
const Real dotGi(const unsigned i, const Vector< Real > &x) const
void applyPreconditioner_Jacobi(std::vector< Real > &Px, const std::vector< Real > &x) const
const Real GiGj(const unsigned i, const unsigned j) const
Real dot(const std::vector< Real > &x, const std::vector< Real > &y) const
void applyG_Identity(std::vector< Real > &Gx, const std::vector< Real > &x) const
Provides the interface for and implements a bundle.
Defines the linear algebra or vector space interface.
virtual void initialize(const Vector< Real > &g)
void applyPreconditioner_SymGS(std::vector< Real > &Px, const std::vector< Real > &x) const
void applyMatrix(std::vector< Real > &Hx, const std::vector< Real > &x) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
unsigned size(void) const
Real computeCriticality(const std::vector< Real > &g, const std::vector< Real > &sol) const
Real evaluateObjective(std::vector< Real > &g, const std::vector< Real > &x, const Real t) const
unsigned projectedCG(std::vector< Real > &x, Real &mu, const std::vector< Real > &b, const Real tol) const
unsigned solveDual_arbitrary(const Real t, const unsigned maxit=1000, const Real tol=1.e-8)
unsigned solveDual(const Real t, const unsigned maxit=1000, const Real tol=1.e-8)
unsigned solveDual_dim2(const Real t, const unsigned maxit=1000, const Real tol=1.e-8)
void computeResidualUpdate(std::vector< Real > &r, std::vector< Real > &g) const
void applyG(std::vector< Real > &Gx, const std::vector< Real > &x) const
void initialize(const Vector< Real > &g)
Real computeStepSize(unsigned &ind, const std::vector< Real > &x, const std::vector< Real > &p) const
void addGi(const unsigned i, const Real a, Vector< Real > &x) const
void applyG_Jacobi(std::vector< Real > &Gx, const std::vector< Real > &x) const
void axpy(const Real a, const std::vector< Real > &x, std::vector< Real > &y) const
void applyPreconditioner_Identity(std::vector< Real > &Px, const std::vector< Real > &x) const
void initializeDualSolver(void)
void applyFullMatrix(std::vector< Real > &Hx, const std::vector< Real > &x) const
const Real getDualVariable(const unsigned i) const
void computeLagMult(std::vector< Real > &lam, const Real mu, const std::vector< Real > &g) const
void project(std::vector< Real > &x, const std::vector< Real > &v) const
Bundle_U_AS(const unsigned maxSize=10, const Real coeff=0.0, const Real omega=2.0, const unsigned remSize=2)
void applyG_SymGS(std::vector< Real > &Gx, const std::vector< Real > &x) const