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