ROL
ROL_PD_BPOE.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_PD_BPOE_HPP
45 #define ROL_PD_BPOE_HPP
46 
48 #include "ROL_Types.hpp"
49 
50 namespace ROL {
51 
52 template<class Real>
53 class PD_BPOE : public PD_RandVarFunctional<Real> {
54 private:
55  Real thresh_;
56 
57  Ptr<SampledScalar<Real>> values_;
58  Ptr<SampledScalar<Real>> gradvecs_;
59  Ptr<SampledVector<Real>> gradients_;
60  Ptr<SampledVector<Real>> hessvecs_;
61 
67 
70 
75 
80 
81  void initializeStorage(void) {
82  values_ = makePtr<SampledScalar<Real>>();
83  gradvecs_ = makePtr<SampledScalar<Real>>();
84  gradients_ = makePtr<SampledVector<Real>>();
85  hessvecs_ = makePtr<SampledVector<Real>>();
86 
88  RandVarFunctional<Real>::setHessVecStorage(gradvecs_,hessvecs_);
89  }
90 
91  void clear(void) {
92  gradvecs_->update();
93  hessvecs_->update();
94  }
95 
96  void checkInputs(void) {
98  }
99 
100 public:
101  PD_BPOE(const Real thresh)
102  : PD_RandVarFunctional<Real>(), thresh_(thresh) {
103  checkInputs();
104  }
105 
106  void setStorage(const Ptr<SampledScalar<Real>> &value_storage,
107  const Ptr<SampledVector<Real>> &gradient_storage) {
108  values_ = value_storage;
109  gradients_ = gradient_storage;
111  }
112 
113  void setHessVecStorage(const Ptr<SampledScalar<Real>> &gradvec_storage,
114  const Ptr<SampledVector<Real>> &hessvec_storage) {
115  gradvecs_ = gradvec_storage;
116  hessvecs_ = hessvec_storage;
118  }
119 
120  void initialize(const Vector<Real> &x) {
122  clear();
123  }
124 
126  const Vector<Real> &x,
127  const std::vector<Real> &xstat,
128  Real &tol) {
129  const Real one(1);
130  Real lam(0);
131  getMultiplier(lam, point_);
132  Real val = computeValue(obj, x, tol);
133  Real arg = xstat[0] * (val - thresh_) + one;
134  Real pf = ppf(arg, lam, getPenaltyParameter(), 0);
135  val_ += weight_ * pf;
136  setValue(arg, point_);
137  }
138 
139  Real getValue(const Vector<Real> &x,
140  const std::vector<Real> &xstat,
141  SampleGenerator<Real> &sampler) {
142  Real ev(0);
143  sampler.sumAll(&val_, &ev, 1);
144  return ev;
145  }
146 
148  const Vector<Real> &x,
149  const std::vector<Real> &xstat,
150  Real &tol) {
151  const Real zero(0), one(1);
152  Real lam(0);
153  getMultiplier(lam, point_);
154  Real val = computeValue(obj, x, tol);
155  Real arg = xstat[0] * (val - thresh_) + one;
156  Real pf = ppf(arg, lam, getPenaltyParameter(), 1);
157  if ( pf > zero ) {
158  computeGradient(*dualVector_, obj, x, tol);
159  val_ += weight_ * pf * (val - thresh_);
160  g_->axpy(weight_ * pf * xstat[0], *dualVector_);
161  }
162  }
163 
165  std::vector<Real> &gstat,
166  const Vector<Real> &x,
167  const std::vector<Real> &xstat,
168  SampleGenerator<Real> &sampler) {
169  Real ev(0);
170  sampler.sumAll(&val_, &ev, 1);
171  sampler.sumAll(*g_, g);
172  gstat[0] = ev;
173  }
174 
176  const Vector<Real> &v,
177  const std::vector<Real> &vstat,
178  const Vector<Real> &x,
179  const std::vector<Real> &xstat,
180  Real &tol) {
181  const Real zero(0), one(1);
182  Real lam(0);
183  getMultiplier(lam, point_);
184  Real val = computeValue(obj, x, tol);
185  Real arg = xstat[0] * (val - thresh_) + one;
186  Real pf1 = ppf(arg, lam, getPenaltyParameter(), 1);
187  Real pf2 = ppf(arg, lam, getPenaltyParameter(), 2);
188  if ( pf1 > zero ) {
189  Real gv = computeGradVec(*dualVector_, obj, v, x, tol);
190  val_ += weight_ * pf1 * gv;
191  hv_->axpy(weight_ * pf1 * vstat[0], *dualVector_);
192  computeHessVec(*dualVector_, obj, v, x, tol);
193  hv_->axpy(weight_ * pf1 * xstat[0], *dualVector_);
194  }
195  if ( pf2 > zero ) {
196  Real gv = computeGradVec(*dualVector_, obj, v, x, tol);
197  Real c1 = pf2 * (val - thresh_) * xstat[0];
198  Real c2 = pf2 * (val - thresh_) * (val - thresh_);
199  Real c3 = pf2 * xstat[0] * xstat[0];
200  val_ += weight_ * (c1 * gv + c2 * vstat[0]);
201  hv_->axpy(weight_ * (c3 * gv + c1 * vstat[0]), *dualVector_);
202  }
203  }
204 
206  std::vector<Real> &hvstat,
207  const Vector<Real> &v,
208  const std::vector<Real> &vstat,
209  const Vector<Real> &x,
210  const std::vector<Real> &xstat,
211  SampleGenerator<Real> &sampler) {
212  Real ev(0);
213  sampler.sumAll(&val_, &ev, 1);
214  sampler.sumAll(*hv_, hv);
215  hvstat[0] = ev;
216  }
217 };
218 
219 }
220 
221 #endif
virtual void setHessVecStorage(const Ptr< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_storage)
void clear(void)
Definition: ROL_PD_BPOE.hpp:91
Provides the interface to evaluate objective functions.
void getGradient(Vector< Real > &g, std::vector< Real > &gstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure (sub)gradient.
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > g_
Ptr< SampledScalar< Real > > values_
Definition: ROL_PD_BPOE.hpp:57
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > hv_
Real ppf(const Real x, const Real t, const Real r, const int deriv=0) const
Ptr< SampledVector< Real > > gradients_
Definition: ROL_PD_BPOE.hpp:59
void checkInputs(void)
Definition: ROL_PD_BPOE.hpp:96
void initialize(const Vector< Real > &x)
Initialize temporary variables.
Contains definitions of custom data types in ROL.
Ptr< Vector< Real > > dualVector_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
Ptr< SampledVector< Real > > hessvecs_
Definition: ROL_PD_BPOE.hpp:60
void sumAll(Real *input, Real *output, int dim) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
virtual void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
Ptr< SampledScalar< Real > > gradvecs_
Definition: ROL_PD_BPOE.hpp:58
void updateHessVec(Objective< Real > &obj, const Vector< Real > &v, const std::vector< Real > &vstat, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for Hessian-time-a-vector computation.
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
virtual void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
void getMultiplier(Real &lam, const std::vector< Real > &pt) const
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
Real computeGradVec(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
void getHessVec(Vector< Real > &hv, std::vector< Real > &hvstat, const Vector< Real > &v, const std::vector< Real > &vstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure Hessian-times-a-vector.
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
PD_BPOE(const Real thresh)
void setValue(const Real val, const std::vector< Real > &pt)
void setHessVecStorage(const Ptr< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_storage)
virtual void setHessVecStorage(const Ptr< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_storage)
void initializeStorage(void)
Definition: ROL_PD_BPOE.hpp:81