ROL
ROL_InteriorPointObjective.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
44#ifndef ROL_INTERIORPOINTOBJECTIVE_H
45#define ROL_INTERIORPOINTOBJECTIVE_H
46
47#include "ROL_Objective.hpp"
49#include "ROL_ParameterList.hpp"
51
61namespace ROL {
62
63template<class Real>
64class InteriorPointObjective : public Objective<Real> {
65
66 typedef Elementwise::ValueSet<Real> ValueSet;
67
68private:
69
70 const Ptr<Objective<Real>> obj_;
71 const Ptr<BoundConstraint<Real>> bnd_;
72 const Ptr<const Vector<Real>> lo_;
73 const Ptr<const Vector<Real>> up_;
74
75 Ptr<Vector<Real>> maskL_; // Elements are 1 when xl>-INF, zero for xl =-INF
76 Ptr<Vector<Real>> maskU_; // Elements are 1 when xu< INF, zero for xu = INF
77 Ptr<Vector<Real>> maskL0_; // Elements are 1 when xl>-INF and xu = INF, zero for xl =-INF
78 Ptr<Vector<Real>> maskU0_; // Elements are 1 when xu< INF and XL =-INF, zero for xu = INF
79 Ptr<Vector<Real>> pwa_; // Scratch vector
80
81 bool useLinearDamping_; // Add linear damping terms to the penalized objective
82 // to prevent the problems such as when the log barrier
83 // contribution is unbounded below on the feasible set
84 Real kappaD_; // Linear damping coefficient
85 Real mu_; // Penalty parameter
86
87 Ptr<ScalarController<Real,int>> fval_;
88 Ptr<VectorController<Real,int>> gradient_;
89
90 int nfval_;
91 int ngrad_;
92
93 // x <- f(x) = { log(x) if x > 0
94 // { -inf if x <= 0
95 class ModifiedLogarithm : public Elementwise::UnaryFunction<Real> {
96 public:
97 Real apply( const Real &x ) const {
98 const Real zero(0), NINF(ROL_NINF<Real>());
99 return (x>zero) ? std::log(x) : NINF;
100 //return std::log(x);
101 }
102 }; // class ModifiedLogarithm
103
104 // x <- f(x) = { 1/x if x > 0
105 // { 0 if x <= 0
106 class ModifiedReciprocal : public Elementwise::UnaryFunction<Real> {
107 public:
108 Real apply( const Real &x ) const {
109 const Real zero(0), one(1);
110 return (x>zero) ? one/x : zero;
111 //return one/x;
112 }
113
114 }; // class ModifiedReciprocal
115
116 // x <- f(x,y) = { y/x if x > 0
117 // { 0 if x <= 0
118 class ModifiedDivide : public Elementwise::BinaryFunction<Real> {
119 public:
120 Real apply( const Real &x, const Real &y ) const {
121 const Real zero(0);
122 return (x>zero) ? y/x : zero;
123 //return y/x;
124 }
125 }; // class ModifiedDivide
126
127 // x <- f(x,y) = { x if y != 0, complement == false
128 // { 0 if y == 0, complement == false
129 // { 0 if y != 0, complement == true
130 // { x if y == 0, complement == true
131 class Mask : public Elementwise::BinaryFunction<Real> {
132 private:
134 public:
135 Mask( bool complement ) : complement_(complement) {}
136 Real apply( const Real &x, const Real &y ) const {
137 const Real zero(0);
138 return ( complement_ ^ (y != zero) ) ? zero : x;
139 }
140 }; // class Mask
141
142 void initialize(const Vector<Real> &x, const Vector<Real> &g) {
143 const Real zero(0), one(1);
144
145 fval_ = makePtr<ScalarController<Real,int>>();
146 gradient_ = makePtr<VectorController<Real,int>>();
147
148 // Determine the index sets where the
149 ValueSet isBoundedBelow( ROL_NINF<Real>(), ValueSet::GREATER_THAN, one, zero );
150 ValueSet isBoundedAbove( ROL_INF<Real>(), ValueSet::LESS_THAN, one, zero );
151
152 maskL_ = x.clone(); maskL_->applyBinary(isBoundedBelow,*lo_);
153 maskU_ = x.clone(); maskU_->applyBinary(isBoundedAbove,*up_);
154
155 pwa_ = x.clone();
156
157 if( useLinearDamping_ ) {
158 maskL0_ = x.clone();
159 maskL0_->set(*maskL_); // c_i = { 1 if l_i > NINF
160 // { 0 otherwise
161 maskL0_->applyBinary(Mask(true),*maskU_); // c_i = { 1 if l_i > NINF and u_i = INF
162 // { 0 otherwise
163 maskU0_ = x.clone();
164 maskU0_->set(*maskU_); // c_i = { 1 if u_i < INF
165 // { 0 otherwise
166 maskU0_->applyBinary(Mask(true),*maskL_); // c_i = { 1 if u_i < INF and l_i = NINF
167 // { 0 otherwise
168 }
169 }
170
171public:
172
174 const Ptr<BoundConstraint<Real>> &bnd,
175 const Vector<Real> &x,
176 const Vector<Real> &g,
177 const bool useLinearDamping,
178 const Real kappaD,
179 const Real mu )
180 : obj_(obj), bnd_(bnd), lo_(bnd->getLowerBound()), up_(bnd->getUpperBound()),
181 useLinearDamping_(useLinearDamping), kappaD_(kappaD), mu_(mu),
182 nfval_(0), ngrad_(0) {
183 initialize(x,g);
184 }
185
187 const Ptr<BoundConstraint<Real>> &bnd,
188 const Vector<Real> &x,
189 const Vector<Real> &g,
190 ParameterList &parlist )
191 : obj_(obj), bnd_(bnd), lo_(bnd->getLowerBound()), up_(bnd->getUpperBound()),
192 nfval_(0), ngrad_(0) {
193 ParameterList &iplist = parlist.sublist("Step").sublist("Primal Dual Interior Point");
194 ParameterList &lblist = iplist.sublist("Barrier Objective");
195
196 useLinearDamping_ = lblist.get("Use Linear Damping", true);
197 kappaD_ = lblist.get("Linear Damping Coefficient", 1.e-4);
198 mu_ = lblist.get("Initial Barrier Parameter", 0.1);
199
200 initialize(x,g);
201 }
202
203 Real getObjectiveValue(const Vector<Real> &x, Real &tol) {
204 int key(0);
205 Real val(0);
206 bool isComputed = fval_->get(val,key);
207 if (!isComputed) {
208 val = obj_->value(x,tol); nfval_++;
209 fval_->set(val,key);
210 }
211 return val;
212 }
213
214 const Ptr<const Vector<Real>> getObjectiveGradient(const Vector<Real> &x, Real &tol) {
215 int key(0);
216 if (!gradient_->isComputed(key)) {
217 if (gradient_->isNull(key)) gradient_->allocate(x.dual(),key);
218 obj_->gradient(*gradient_->set(key),x,tol); ngrad_++;
219 }
220 return gradient_->get(key);
221 }
222
224 return nfval_;
225 }
226
228 return ngrad_;
229 }
230
231 void updatePenalty(const Real mu) {
232 mu_ = mu;
233 }
234
235 void update( const Vector<Real> &x, UpdateType type, int iter = -1 ) {
236 obj_->update(x,type,iter);
237 fval_->objectiveUpdate(type);
238 gradient_->objectiveUpdate(type);
239 }
240
241 Real value( const Vector<Real> &x, Real &tol ) {
242 const Real zero(0), one(1);
243 Real linearTerm = zero;
244 // Compute the unpenalized objective value
245 Real fval = getObjectiveValue(x,tol);
246 // Compute log barrier
248 Elementwise::ReductionSum<Real> sum;
249 Elementwise::Multiply<Real> mult;
250
251 pwa_->set(x); // pwa = x
252 pwa_->axpy(-one,*lo_); // pwa = x-l
253 if( useLinearDamping_ ) {
254 // Penalizes large positive x_i when only a lower bound exists
255 linearTerm += maskL0_->dot(*pwa_);
256 }
257 pwa_->applyUnary(mlog); // pwa = mlog(x-l)
258 Real aval = pwa_->dot(*maskL_);
259
260 pwa_->set(*up_); // pwa = u
261 pwa_->axpy(-one,x); // pwa = u-x
262 if( useLinearDamping_ ) {
263 // Penalizes large negative x_i when only an upper bound exists
264 linearTerm += maskU0_->dot(*pwa_);
265 }
266 pwa_->applyUnary(mlog); // pwa = mlog(u-x)
267 Real bval = pwa_->dot(*maskU_);
268
269 fval -= mu_*(aval+bval);
270 fval += kappaD_*mu_*linearTerm;
271 return fval;
272 }
273
274 void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
275 const Real one(1);
276 // Compute gradient of objective function
277 g.set(*getObjectiveGradient(x,tol));
278
279 // Add gradient of the log barrier penalty
281
282 pwa_->set(x); // pwa = x
283 pwa_->axpy(-one,*lo_); // pwa = x-l
284 pwa_->applyUnary(mrec); // pwa_i = 1/(x_i-l_i) for i s.t. x_i > l_i, 0 otherwise
285 pwa_->applyBinary(Mask(true),*maskL_); // zero elements where l = NINF
286 g.axpy(-mu_,pwa_->dual());
287 if( useLinearDamping_ ) {
288 g.axpy(-mu_*kappaD_,maskL0_->dual());
289 }
290
291 pwa_->set(*up_); // pwa = u
292 pwa_->axpy(-one,x); // pwa = u-x
293 pwa_->applyUnary(mrec); // pwa_i = 1/(u_i-x_i) for i s.t. u_i > x_i, 0 otherwise
294 pwa_->applyBinary(Mask(true),*maskU_); // zero elements where u = INF
295 g.axpy( mu_,pwa_->dual());
296 if( useLinearDamping_ ) {
297 g.axpy( mu_*kappaD_,maskU0_->dual());
298 }
299 }
300
301 void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
302 const Real one(1), two(2);
303 // Evaluate objective hessian
304 obj_->hessVec(hv,v,x,tol);
305
306 // Evaluate log barrier hessian
308 Elementwise::Multiply<Real> mult;
309 Elementwise::Power<Real> square(two);
310
311 pwa_->set(x); // pwa = x
312 pwa_->axpy(-one,*lo_); // pwa = x-l
313 pwa_->applyUnary(mrec); // pwa_i = 1/(x_i-l_i) for i s.t. x_i > l_i, 0 otherwise
314 pwa_->applyBinary(Mask(true),*maskL_); // zero elements where l = NINF
315 pwa_->applyUnary(square); // pwa_i = { (x_i-l_i)^(-2) if l_i > NINF
316 // { 0 if l_i = NINF
317 pwa_->applyBinary(mult,v);
318 hv.axpy(mu_,pwa_->dual());
319
320 pwa_->set(*up_); // pwa = u
321 pwa_->axpy(-one,x); // pwa = u-x
322 pwa_->applyUnary(mrec); // pwa_i = 1/(u_i-x_i) for i s.t. u_i > x_i, 0 otherwise
323 pwa_->applyBinary(Mask(true),*maskU_); // zero elements where u = INF
324 pwa_->applyUnary(square); // pwa_i = { (u_i-x_i)^(-2) if u_i < INF
325 // { 0 if u_i = INF
326 pwa_->applyBinary(mult,v);
327 hv.axpy(mu_,pwa_->dual());
328 }
329
330}; // class InteriorPointObjective
331
332}
333
334#endif // ROL_INTERIORPOINTOBJECTIVE_H
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Provides the interface to apply upper and lower bound constraints.
Real apply(const Real &x, const Real &y) const
Real apply(const Real &x, const Real &y) const
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
const Ptr< BoundConstraint< Real > > bnd_
Ptr< VectorController< Real, int > > gradient_
const Ptr< const Vector< Real > > up_
InteriorPointObjective(const Ptr< Objective< Real > > &obj, const Ptr< BoundConstraint< Real > > &bnd, const Vector< Real > &x, const Vector< Real > &g, const bool useLinearDamping, const Real kappaD, const Real mu)
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
InteriorPointObjective(const Ptr< Objective< Real > > &obj, const Ptr< BoundConstraint< Real > > &bnd, const Vector< Real > &x, const Vector< Real > &g, ParameterList &parlist)
const Ptr< const Vector< Real > > lo_
void initialize(const Vector< Real > &x, const Vector< Real > &g)
Elementwise::ValueSet< Real > ValueSet
const Ptr< const Vector< Real > > getObjectiveGradient(const Vector< Real > &x, Real &tol)
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Real getObjectiveValue(const Vector< Real > &x, Real &tol)
const Ptr< Objective< Real > > obj_
Ptr< ScalarController< Real, int > > fval_
Provides the interface to evaluate objective functions.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:209
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
Definition: ROL_Vector.hpp:226
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153