ROL
ROL_PD_BPOE.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_BPOE_HPP
11 #define ROL_PD_BPOE_HPP
12 
14 #include "ROL_Types.hpp"
15 
16 namespace ROL {
17 
18 template<class Real>
19 class PD_BPOE : public PD_RandVarFunctional<Real> {
20 private:
21  Real thresh_;
22 
23  Ptr<ScalarController<Real>> values_;
24  Ptr<ScalarController<Real>> gradvecs_;
25  Ptr<VectorController<Real>> gradients_;
26  Ptr<VectorController<Real>> hessvecs_;
27 
33 
36 
41 
46 
47  void initializeStorage(void) {
48  values_ = makePtr<ScalarController<Real>>();
49  gradvecs_ = makePtr<ScalarController<Real>>();
50  gradients_ = makePtr<VectorController<Real>>();
51  hessvecs_ = makePtr<VectorController<Real>>();
52 
54  RandVarFunctional<Real>::setHessVecStorage(gradvecs_,hessvecs_);
55  }
56 
57  void clear(void) {
58  gradvecs_->reset();
59  hessvecs_->reset();
60  }
61 
62  void checkInputs(void) {
64  }
65 
66 public:
67  PD_BPOE(const Real thresh)
68  : PD_RandVarFunctional<Real>(), thresh_(thresh) {
69  checkInputs();
70  }
71 
72  void setStorage(const Ptr<ScalarController<Real>> &value_storage,
73  const Ptr<VectorController<Real>> &gradient_storage) {
74  values_ = value_storage;
75  gradients_ = gradient_storage;
77  }
78 
79  void setHessVecStorage(const Ptr<ScalarController<Real>> &gradvec_storage,
80  const Ptr<VectorController<Real>> &hessvec_storage) {
81  gradvecs_ = gradvec_storage;
82  hessvecs_ = hessvec_storage;
84  }
85 
86  void initialize(const Vector<Real> &x) {
88  clear();
89  }
90 
92  const Vector<Real> &x,
93  const std::vector<Real> &xstat,
94  Real &tol) {
95  const Real one(1);
96  Real lam(0);
97  getMultiplier(lam, point_);
98  Real val = computeValue(obj, x, tol);
99  Real arg = xstat[0] * (val - thresh_) + one;
100  Real pf = ppf(arg, lam, getPenaltyParameter(), 0);
101  val_ += weight_ * pf;
102  setValue(arg, point_);
103  }
104 
105  Real getValue(const Vector<Real> &x,
106  const std::vector<Real> &xstat,
107  SampleGenerator<Real> &sampler) {
108  Real ev(0);
109  sampler.sumAll(&val_, &ev, 1);
110  return ev;
111  }
112 
114  const Vector<Real> &x,
115  const std::vector<Real> &xstat,
116  Real &tol) {
117  const Real zero(0), one(1);
118  Real lam(0);
119  getMultiplier(lam, point_);
120  Real val = computeValue(obj, x, tol);
121  Real arg = xstat[0] * (val - thresh_) + one;
122  Real pf = ppf(arg, lam, getPenaltyParameter(), 1);
123  if ( pf > zero ) {
124  computeGradient(*dualVector_, obj, x, tol);
125  val_ += weight_ * pf * (val - thresh_);
126  g_->axpy(weight_ * pf * xstat[0], *dualVector_);
127  }
128  }
129 
131  std::vector<Real> &gstat,
132  const Vector<Real> &x,
133  const std::vector<Real> &xstat,
134  SampleGenerator<Real> &sampler) {
135  Real ev(0);
136  sampler.sumAll(&val_, &ev, 1);
137  sampler.sumAll(*g_, g);
138  gstat[0] = ev;
139  }
140 
142  const Vector<Real> &v,
143  const std::vector<Real> &vstat,
144  const Vector<Real> &x,
145  const std::vector<Real> &xstat,
146  Real &tol) {
147  const Real zero(0), one(1);
148  Real lam(0);
149  getMultiplier(lam, point_);
150  Real val = computeValue(obj, x, tol);
151  Real arg = xstat[0] * (val - thresh_) + one;
152  Real pf1 = ppf(arg, lam, getPenaltyParameter(), 1);
153  Real pf2 = ppf(arg, lam, getPenaltyParameter(), 2);
154  if ( pf1 > zero ) {
155  Real gv = computeGradVec(*dualVector_, obj, v, x, tol);
156  val_ += weight_ * pf1 * gv;
157  hv_->axpy(weight_ * pf1 * vstat[0], *dualVector_);
158  computeHessVec(*dualVector_, obj, v, x, tol);
159  hv_->axpy(weight_ * pf1 * xstat[0], *dualVector_);
160  }
161  if ( pf2 > zero ) {
162  Real gv = computeGradVec(*dualVector_, obj, v, x, tol);
163  Real c1 = pf2 * (val - thresh_) * xstat[0];
164  Real c2 = pf2 * (val - thresh_) * (val - thresh_);
165  Real c3 = pf2 * xstat[0] * xstat[0];
166  val_ += weight_ * (c1 * gv + c2 * vstat[0]);
167  hv_->axpy(weight_ * (c3 * gv + c1 * vstat[0]), *dualVector_);
168  }
169  }
170 
172  std::vector<Real> &hvstat,
173  const Vector<Real> &v,
174  const std::vector<Real> &vstat,
175  const Vector<Real> &x,
176  const std::vector<Real> &xstat,
177  SampleGenerator<Real> &sampler) {
178  Real ev(0);
179  sampler.sumAll(&val_, &ev, 1);
180  sampler.sumAll(*hv_, hv);
181  hvstat[0] = ev;
182  }
183 };
184 
185 }
186 
187 #endif
void clear(void)
Definition: ROL_PD_BPOE.hpp:57
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_
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_
Real ppf(const Real x, const Real t, const Real r, const int deriv=0) const
void checkInputs(void)
Definition: ROL_PD_BPOE.hpp:62
void initialize(const Vector< Real > &x)
Initialize temporary variables.
Definition: ROL_PD_BPOE.hpp:86
Contains definitions of custom data types in ROL.
Ptr< Vector< Real > > dualVector_
virtual void setStorage(const Ptr< ScalarController< Real >> &value_storage, const Ptr< VectorController< Real >> &gradient_storage)
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 > > gradvecs_
Definition: ROL_PD_BPOE.hpp:24
void setStorage(const Ptr< ScalarController< Real >> &value_storage, const Ptr< VectorController< Real >> &gradient_storage)
Definition: ROL_PD_BPOE.hpp:72
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)
Ptr< VectorController< Real > > gradients_
Definition: ROL_PD_BPOE.hpp:25
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_BPOE.hpp:91
Ptr< ScalarController< Real > > values_
Definition: ROL_PD_BPOE.hpp:23
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 computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
void setHessVecStorage(const Ptr< ScalarController< Real >> &gradvec_storage, const Ptr< VectorController< Real >> &hessvec_storage)
Definition: ROL_PD_BPOE.hpp:79
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)
Definition: ROL_PD_BPOE.hpp:67
void setValue(const Real val, const std::vector< Real > &pt)
virtual void setHessVecStorage(const Ptr< ScalarController< Real >> &gradvec_storage, const Ptr< VectorController< Real >> &hessvec_storage)
Ptr< VectorController< Real > > hessvecs_
Definition: ROL_PD_BPOE.hpp:26
void initializeStorage(void)
Definition: ROL_PD_BPOE.hpp:47