ROL
ROL_PD_CVaR.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_PD_CVAR_HPP
11 #define ROL_PD_CVAR_HPP
12 
14 #include "ROL_Types.hpp"
15 
16 namespace ROL {
17 
18 template<class Real>
19 class PD_CVaR : public PD_RandVarFunctional<Real> {
20 private:
21  Real alpha_;
22  Real beta_;
23 
24  Ptr<ScalarController<Real>> values_;
25  Ptr<ScalarController<Real>> gradvecs_;
26  Ptr<VectorController<Real>> gradients_;
27  Ptr<VectorController<Real>> hessvecs_;
28 
34 
37 
42 
47 
48  void initializeStorage(void) {
49  values_ = makePtr<ScalarController<Real>>();
50  gradvecs_ = makePtr<ScalarController<Real>>();
51  gradients_ = makePtr<VectorController<Real>>();
52  hessvecs_ = makePtr<VectorController<Real>>();
53 
55  RandVarFunctional<Real>::setHessVecStorage(gradvecs_,hessvecs_);
56  }
57 
58  void clear(void) {
59  gradvecs_->reset();
60  hessvecs_->reset();
61  }
62 
63  void checkInputs(void) {
64  Real zero(0), one(1);
65  ROL_TEST_FOR_EXCEPTION((alpha_ <= zero) || (alpha_ > one), std::invalid_argument,
66  ">>> ERROR (ROL::PD_CVaR): Convex combination parameter alpha is out of range!");
67  ROL_TEST_FOR_EXCEPTION((beta_ < zero) || (beta_ >= one), std::invalid_argument,
68  ">>> ERROR (ROL::PD_CVaR): Confidence parameter beta is out of range!");
70  }
71 
72 public:
73  PD_CVaR(const Real alpha, const Real beta)
74  : PD_RandVarFunctional<Real>(), alpha_(alpha), beta_(beta) {
75  checkInputs();
76  }
77 
78  void setStorage(const Ptr<ScalarController<Real>> &value_storage,
79  const Ptr<VectorController<Real>> &gradient_storage) {
80  values_ = value_storage;
81  gradients_ = gradient_storage;
83  }
84 
85  void setHessVecStorage(const Ptr<ScalarController<Real>> &gradvec_storage,
86  const Ptr<VectorController<Real>> &hessvec_storage) {
87  gradvecs_ = gradvec_storage;
88  hessvecs_ = hessvec_storage;
90  }
91 
92  void initialize(const Vector<Real> &x) {
94  clear();
95  }
96 
98  const Vector<Real> &x,
99  const std::vector<Real> &xstat,
100  Real &tol) {
101  const Real one(1);
102  Real lam(0);
103  getMultiplier(lam, point_);
104  Real val = computeValue(obj, x, tol);
105  Real arg = val - xstat[0];
106  Real pf = ppf(arg, lam, getPenaltyParameter(), 0);
107  val_ += weight_ * ((one-alpha_) * val + alpha_/(one-beta_) * pf);
108  setValue(arg, point_);
109  }
110 
111  Real getValue(const Vector<Real> &x,
112  const std::vector<Real> &xstat,
113  SampleGenerator<Real> &sampler) {
114  Real ev(0);
115  sampler.sumAll(&val_, &ev, 1);
116  return ev + alpha_ * xstat[0];
117  }
118 
120  const Vector<Real> &x,
121  const std::vector<Real> &xstat,
122  Real &tol) {
123  const Real zero(0), one(1);
124  Real lam(0);
125  getMultiplier(lam, point_);
126  Real val = computeValue(obj, x, tol);
127  Real arg = val - xstat[0];
128  Real pf = ppf(arg, lam, getPenaltyParameter(), 1);
129  val_ += weight_ * pf;
130  Real c = (one-alpha_) + alpha_/(one-beta_) * pf;
131  if ( std::abs(c) > zero ) {
132  computeGradient(*dualVector_, obj, x, tol);
133  g_->axpy(weight_ * c, *dualVector_);
134  }
135  }
136 
138  std::vector<Real> &gstat,
139  const Vector<Real> &x,
140  const std::vector<Real> &xstat,
141  SampleGenerator<Real> &sampler) {
142  const Real one(1);
143  Real ev(0);
144  sampler.sumAll(&val_, &ev, 1);
145  ev *= -alpha_/(one-beta_);
146  ev += alpha_;
147  gstat[0] = ev;
148  sampler.sumAll(*g_, g);
149  }
150 
152  const Vector<Real> &v,
153  const std::vector<Real> &vstat,
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 pf1 = ppf(arg, lam, getPenaltyParameter(), 1);
163  Real pf2 = ppf(arg, lam, getPenaltyParameter(), 2);
164  Real c(0);
165  if ( std::abs(pf2) > zero ) {
166  Real gv = computeGradVec(*dualVector_, obj, v, x, tol);
167  val_ += weight_ * pf2 * (vstat[0] - gv);
168  c = pf2 * alpha_/(one-beta_) * (gv - vstat[0]);
169  hv_->axpy(weight_ * c, *dualVector_);
170  }
171  c = (one-alpha_) + alpha_/(one-beta_) * pf1;
172  if ( std::abs(c) > zero ) {
173  computeHessVec(*dualVector_, obj, v, x, tol);
174  hv_->axpy(weight_ * c, *dualVector_);
175  }
176  }
177 
179  std::vector<Real> &hvstat,
180  const Vector<Real> &v,
181  const std::vector<Real> &vstat,
182  const Vector<Real> &x,
183  const std::vector<Real> &xstat,
184  SampleGenerator<Real> &sampler) {
185  const Real one(1);
186  Real ev(0);
187  sampler.sumAll(&val_, &ev, 1);
188  ev *= alpha_/(one-beta_);
189  hvstat[0] = ev;
190  sampler.sumAll(*hv_, hv);
191  }
192 };
193 
194 }
195 
196 #endif
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_
Ptr< VectorController< Real > > gradients_
Definition: ROL_PD_CVaR.hpp:26
virtual void setHessVecStorage(const Ptr< ScalarController< Real >> &gradvec_storage, const Ptr< VectorController< Real >> &hessvec_storage)
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > hv_
PD_CVaR(const Real alpha, const Real beta)
Definition: ROL_PD_CVaR.hpp:73
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:48
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
Definition: ROL_PD_CVaR.hpp:97
Ptr< Vector< Real > > dualVector_
virtual void setStorage(const Ptr< ScalarController< Real >> &value_storage, const Ptr< VectorController< Real >> &gradient_storage)
void checkInputs(void)
Definition: ROL_PD_CVaR.hpp:63
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
void sumAll(Real *input, Real *output, int dim) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Ptr< ScalarController< Real > > values_
Definition: ROL_PD_CVaR.hpp:24
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.
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< ScalarController< Real >> &value_storage, const Ptr< VectorController< Real >> &gradient_storage)
void setStorage(const Ptr< ScalarController< Real >> &value_storage, const Ptr< VectorController< Real >> &gradient_storage)
Definition: ROL_PD_CVaR.hpp:78
void getMultiplier(Real &lam, const std::vector< Real > &pt) const
void setHessVecStorage(const Ptr< ScalarController< Real >> &gradvec_storage, const Ptr< VectorController< Real >> &hessvec_storage)
Definition: ROL_PD_CVaR.hpp:85
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
void initialize(const Vector< Real > &x)
Initialize temporary variables.
Definition: ROL_PD_CVaR.hpp:92
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...
Ptr< ScalarController< Real > > gradvecs_
Definition: ROL_PD_CVaR.hpp:25
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.
virtual void setHessVecStorage(const Ptr< ScalarController< Real >> &gradvec_storage, const Ptr< VectorController< Real >> &hessvec_storage)
void clear(void)
Definition: ROL_PD_CVaR.hpp:58
Ptr< VectorController< Real > > hessvecs_
Definition: ROL_PD_CVaR.hpp:27