10 #ifndef ROL_BUNDLE_U_DEF_H
11 #define ROL_BUNDLE_U_DEF_H
17 template<
typename Real>
20 for (
unsigned j = ind.back()+1; j < size_; ++j) {
21 (subgradients_[j-1])->set(*(subgradients_[j]));
22 linearizationErrors_[j-1] = linearizationErrors_[j];
23 distanceMeasures_[j-1] = distanceMeasures_[j];
24 dualVariables_[j-1] = dualVariables_[j];
26 (subgradients_[size_-1])->
zero();
27 linearizationErrors_[size_-1] = ROL_OVERFLOW<Real>();
28 distanceMeasures_[size_-1] = ROL_OVERFLOW<Real>();
29 dualVariables_[size_-1] =
zero;
30 for (
unsigned i = ind.size()-1; i > 0; --i) {
31 for (
unsigned j = ind[i-1]+1; j < size_; ++j) {
32 (subgradients_[j-1])->set(*(subgradients_[j]));
33 linearizationErrors_[j-1] = linearizationErrors_[j];
34 distanceMeasures_[j-1] = distanceMeasures_[j];
35 dualVariables_[j-1] = dualVariables_[j];
41 template<
typename Real>
44 (subgradients_[size_])->set(g);
45 linearizationErrors_[size_] = le;
46 distanceMeasures_[size_] = dm;
47 dualVariables_[size_] =
zero;
51 template<
typename Real>
55 const unsigned remSize)
56 : size_(0), maxSize_(maxSize), remSize_(remSize),
57 coeff_(coeff), omega_(omega), isInitialized_(false) {
72 template<
typename Real>
74 if ( !isInitialized_ ) {
76 for (
unsigned i = 0; i < maxSize_; ++i) {
77 subgradients_[i] = g.
clone();
79 (subgradients_[0])->set(g);
80 linearizationErrors_[0] =
zero;
81 distanceMeasures_[0] =
zero;
82 dualVariables_[0] = one;
84 isInitialized_ =
true;
93 template<
typename Real>
95 return linearizationErrors_[i];
98 template<
typename Real>
100 return distanceMeasures_[i];
103 template<
typename Real>
105 return *(subgradients_[i]);
108 template<
typename Real>
110 return dualVariables_[i];
113 template<
typename Real>
115 dualVariables_[i] = val;
118 template<
typename Real>
121 dualVariables_.assign(size_,zero);
124 template<
typename Real>
127 if ( coeff_ > ROL_EPSILON<Real>() ) {
128 alpha = std::max(coeff_*std::pow(dm,omega_),le);
133 template<
typename Real>
135 return computeAlpha(distanceMeasures_[i],linearizationErrors_[i]);
138 template<
typename Real>
143 template<
typename Real>
145 Real
zero(0), one(1);
147 Real eLE(0), eDM(0), yLE(0), yDM(0), tLE(0), tDM(0);
148 for (
unsigned i = 0; i < size_; ++i) {
151 yG_->set(*subgradients_[i]); yG_->scale(dualVariables_[i]); yG_->axpy(-one,*eG_);
152 tG_->set(aggSubGrad); tG_->plus(*yG_);
153 eG_->set(*tG_); eG_->axpy(-one,aggSubGrad); eG_->axpy(-one,*yG_);
154 aggSubGrad.
set(*tG_);
157 yLE = dualVariables_[i]*linearizationErrors_[i] - eLE;
158 tLE = aggLinErr + yLE;
159 eLE = (tLE - aggLinErr) - yLE;
163 yDM = dualVariables_[i]*distanceMeasures_[i] - eDM;
164 tDM = aggDistMeas + yDM;
165 eDM = (tDM - aggDistMeas) - yDM;
170 template<
typename Real>
172 if (size_ == maxSize_) {
174 unsigned loc = size_, cnt = 0;
175 std::vector<unsigned> ind(remSize_,0);
176 for (
unsigned i = size_; i > 0; --i) {
177 if ( std::abs(linearizationErrors_[i-1]) < ROL_EPSILON<Real>() ) {
182 for (
unsigned i = 0; i < size_; ++i) {
187 if (cnt == remSize_) {
198 template<
typename Real>
204 for (
unsigned i = 0; i < size_; ++i) {
206 linearizationErrors_[i] += linErr - subgradients_[i]->apply(s);
207 distanceMeasures_[i] += distMeas;
209 linearizationErrors_[size_] =
zero;
210 distanceMeasures_[size_] =
zero;
214 linearizationErrors_[size_] = linErr;
215 distanceMeasures_[size_] = distMeas;
218 (subgradients_[size_])->set(g);
220 dualVariables_[size_] =
zero;
225 template<
typename Real>
227 return subgradient(i).dot(subgradient(j));
230 template<
typename Real>
232 return x.
dot(subgradient(i));
235 template<
typename Real>
237 x.
axpy(a,subgradient(i));
240 template<
typename Real>
242 Real one(1), half(0.5);
243 gx_->zero(); eG_->zero();
244 for (
unsigned i = 0; i < size(); ++i) {
247 yG_->set(subgradient(i)); yG_->scale(x[i]); yG_->axpy(-one,*eG_);
248 tG_->set(*gx_); tG_->plus(*yG_);
249 eG_->set(*tG_); eG_->axpy(-one,*gx_); eG_->axpy(-one,*yG_);
252 Real Hx(0), val(0), err(0), tmp(0), y(0);
253 for (
unsigned i = 0; i < size(); ++i) {
258 y = x[i]*(half*Hx + alpha(i)/t) - err;
260 err = (tmp - val) - y;
263 g[i] = Hx + alpha(i)/t;
268 template<
typename Real>
270 setDualVariable(0,static_cast<Real>(1));
275 template<
typename Real>
277 Real diffg = gx_->dot(*gx_),
zero(0), one(1), half(0.5);
278 gx_->set(subgradient(0)); addGi(1,-one,*gx_);
279 if ( std::abs(diffg) > ROL_EPSILON<Real>() ) {
280 Real diffa = (alpha(0)-alpha(1))/t;
281 Real gdiffg = dotGi(1,*gx_);
282 setDualVariable(0,std::min(one,std::max(
zero,-(gdiffg+diffa)/diffg)));
283 setDualVariable(1,one-getDualVariable(0));
286 if ( std::abs(alpha(0)-alpha(1)) > ROL_EPSILON<Real>() ) {
287 if ( alpha(0) < alpha(1) ) {
288 setDualVariable(0,one); setDualVariable(1,
zero);
290 else if ( alpha(0) > alpha(1) ) {
291 setDualVariable(0,
zero); setDualVariable(1,one);
295 setDualVariable(0,half); setDualVariable(1,half);
void reset(const Vector< Real > &g, const Real le, const Real dm)
void remove(const std::vector< unsigned > &ind)
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 setDualVariable(const unsigned i, const Real val)
const Vector< Real > & subgradient(const unsigned i) const
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
const Real dotGi(const unsigned i, const Vector< Real > &x) const
void update(const bool flag, const Real linErr, const Real distMeas, const Vector< Real > &g, const Vector< Real > &s)
Contains definitions of custom data types in ROL.
const Real GiGj(const unsigned i, const unsigned j) const
std::vector< Real > dualVariables_
const Real alpha(const unsigned i) const
virtual void zero()
Set to zero vector.
std::vector< Real > distanceMeasures_
Defines the linear algebra or vector space interface.
virtual void initialize(const Vector< Real > &g)
virtual Real dot(const Vector &x) const =0
Compute where .
void resetDualVariables(void)
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
unsigned size(void) const
void aggregate(Vector< Real > &aggSubGrad, Real &aggLinErr, Real &aggDistMeas) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Bundle_U(const unsigned maxSize=10, const Real coeff=0.0, const Real omega=2.0, const unsigned remSize=2)
Real evaluateObjective(std::vector< Real > &g, const std::vector< Real > &x, const Real t) const
void add(const Vector< Real > &g, const Real le, const Real dm)
const Real distanceMeasure(const unsigned i) const
unsigned solveDual_dim2(const Real t, const unsigned maxit=1000, const Real tol=1.e-8)
std::vector< Ptr< Vector< Real > > > subgradients_
void addGi(const unsigned i, const Real a, Vector< Real > &x) const
const Real linearizationError(const unsigned i) const
std::vector< Real > linearizationErrors_
virtual void set(const Vector &x)
Set where .
const Real getDualVariable(const unsigned i) const
const Real computeAlpha(const Real dm, const Real le) const