ROL
ROL_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_BPOE_HPP
11 #define ROL_BPOE_HPP
12 
14 
29 namespace ROL {
30 
31 template<class Real>
32 class BPOE : public RandVarFunctional<Real> {
33 private:
34  Real threshold_;
35  Real order_;
36 
37  std::vector<Real> hvec_;
38  ROL::Ptr<Vector<Real> > dualVec1_, dualVec2_;
39 
41 
47 
50 
55 
56 public:
57  BPOE(const Real threshold, const Real order=1)
58  : RandVarFunctional<Real>(), threshold_(threshold), order_(order), firstResetBPOE_(true) {
59  hvec_.resize(5);
60  }
61 
62  BPOE(ROL::ParameterList &parlist) : RandVarFunctional<Real>(), firstResetBPOE_(true) {
63  ROL::ParameterList &list = parlist.sublist("SOL").sublist("Probability").sublist("bPOE");
64  threshold_ = list.get<Real>("Threshold");
65  order_ = list.get<Real>("Moment Order");
66  hvec_.resize(5);
67  }
68 
69  void initialize(const Vector<Real> &x) {
71  if ( firstResetBPOE_ ) {
72  dualVec1_ = x.dual().clone();
73  dualVec2_ = x.dual().clone();
74  firstResetBPOE_ = false;
75  }
76  dualVec1_->zero();
77  dualVec2_->zero();
78  hvec_.assign(5,0);
79  }
80 
82  const Vector<Real> &x,
83  const std::vector<Real> &xstat,
84  Real &tol) {
85  const Real zero(0), one(1);
86  Real val = computeValue(obj,x,tol);
87  Real bp = xstat[0]*(val-threshold_)+one;
88  if ( bp > zero ) {
89  val_ += weight_*((order_==one) ? bp : std::pow(bp,order_));
90  }
91  }
92 
93  Real getValue(const Vector<Real> &x,
94  const std::vector<Real> &xstat,
95  SampleGenerator<Real> &sampler) {
96  const Real one(1);
97  Real bpoe(0);
98  sampler.sumAll(&val_,&bpoe,1);
99  return ((order_==one) ? bpoe : std::pow(bpoe,one/order_));
100  }
101 
103  const Vector<Real> &x,
104  const std::vector<Real> &xstat,
105  Real &tol) {
106  const Real zero(0), one(1), two(2);
107  Real val = computeValue(obj,x,tol);
108  Real bp = xstat[0]*(val-threshold_)+one;
109  if ( bp > zero ) {
110  computeGradient(*dualVector_,obj,x,tol);
111  Real pvalp0 = ((order_==one) ? bp : std::pow(bp,order_));
112  Real pvalp1 = ((order_==one) ? one : ((order_==two) ? bp : std::pow(bp,order_-one)));
113  val_ += weight_ * pvalp0;
114  gv_ += weight_ * pvalp1 * (val - threshold_);
115  g_->axpy(weight_ * pvalp1, *dualVector_);
116  }
117  }
118 
120  std::vector<Real> &gstat,
121  const Vector<Real> &x,
122  const std::vector<Real> &xstat,
123  SampleGenerator<Real> &sampler) {
124  const Real zero(0), one(1);
125  std::vector<Real> myvals(2), gvals(2);
126  myvals[0] = val_; myvals[1] = gv_;
127  sampler.sumAll(&myvals[0],&gvals[0],2);
128  if ( gvals[0] > zero) {
129  sampler.sumAll(*g_,g);
130  Real norm = std::pow(gvals[0],(order_-one)/order_);
131  g.scale(xstat[0]/norm);
132  gstat[0] = gvals[1]/norm;
133  }
134  else {
135  g.zero();
136  gstat[0] = zero;
137  }
138  }
139 
141  const Vector<Real> &v,
142  const std::vector<Real> &vstat,
143  const Vector<Real> &x,
144  const std::vector<Real> &xstat,
145  Real &tol) {
146  const Real zero(0), one(1), two(2), three(3);
147  Real val = computeValue(obj,x,tol);
148  Real bp = xstat[0]*(val-threshold_)+one;
149  if ( bp > zero ) {
150  // Gradient only
151  Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
152  Real pvalp0 = ((order_==one) ? bp : std::pow(bp,order_));
153  Real pvalp1 = ((order_==one) ? one
154  : ((order_==two) ? bp : std::pow(bp,order_-one)));
155  Real pvalp2 = ((order_==one) ? zero
156  : ((order_==two) ? one
157  : ((order_==three) ? bp : std::pow(bp,order_-two))));
158  hvec_[0] += weight_ * pvalp0;
159  hvec_[1] += weight_ * pvalp1 * (val-threshold_);
160  hvec_[2] += weight_ * pvalp2 * (val-threshold_) * (val-threshold_);
161  hvec_[3] += weight_ * pvalp1 * gv;
162  hvec_[4] += weight_ * pvalp2 * (val-threshold_) * gv;
163  g_->axpy(weight_ * pvalp1, *dualVector_);
164  dualVec1_->axpy(weight_ * pvalp2 * (val-threshold_), *dualVector_);
165  dualVec2_->axpy(weight_ * pvalp2 * gv, *dualVector_);
166  // Hessian only
167  computeHessVec(*dualVector_,obj,v,x,tol);
168  hv_->axpy(weight_ * pvalp1, *dualVector_);
169  }
170  }
171 
173  std::vector<Real> &hvstat,
174  const Vector<Real> &v,
175  const std::vector<Real> &vstat,
176  const Vector<Real> &x,
177  const std::vector<Real> &xstat,
178  SampleGenerator<Real> &sampler) {
179  const Real zero(0), one(1), two(2);
180  std::vector<Real> gvals(5);
181  sampler.sumAll(&hvec_[0],&gvals[0],5);
182 
183  if ( gvals[0] > zero ) {
184  Real norm0 = ((order_==one) ? one
185  : ((order_==two) ? std::sqrt(gvals[0])
186  : std::pow(gvals[0],(order_-one)/order_)));
187  Real norm1 = ((order_==one) ? gvals[0]
188  : std::pow(gvals[0],(two*order_-one)/order_));
189  hvstat[0] = (order_-one)*((gvals[2]/norm0 - gvals[1]*gvals[1]/norm1)*vstat[0]
190  +xstat[0]*(gvals[4]/norm0 - gvals[3]*gvals[1]/norm1))
191  +(gvals[3]/norm0);
192 
193  sampler.sumAll(*hv_,hv);
194  hv.scale(xstat[0]/norm0);
195 
196  sampler.sumAll(*g_,*hv_);
197  Real coeff = -(order_-one)*xstat[0]*(xstat[0]*gvals[3]+vstat[0]*gvals[1])/norm1+vstat[0]/norm0;
198  hv.axpy(coeff,*hv_);
199 
200  sampler.sumAll(*dualVec1_,*hv_);
201  hv.axpy((order_-one)*vstat[0]*xstat[0]/norm0,*hv_);
202 
203  sampler.sumAll(*dualVec2_,*hv_);
204  hv.axpy((order_-one)*xstat[0]*xstat[0]/norm0,*hv_);
205  }
206  }
207 };
208 
209 }
210 
211 #endif
Provides the interface to evaluate objective functions.
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:192
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
Definition: ROL_BPOE.hpp:93
virtual void scale(const Real alpha)=0
Compute where .
ROL::Ptr< Vector< Real > > dualVec2_
Definition: ROL_BPOE.hpp:38
Ptr< Vector< Real > > g_
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:119
Ptr< Vector< Real > > hv_
Provides the implementation of the buffered probability of exceedance.
Definition: ROL_BPOE.hpp:32
BPOE(const Real threshold, const Real order=1)
Definition: ROL_BPOE.hpp:57
Real threshold_
Definition: ROL_BPOE.hpp:34
std::vector< Real > hvec_
Definition: ROL_BPOE.hpp:37
Ptr< Vector< Real > > dualVector_
Real order_
Definition: ROL_BPOE.hpp:35
virtual void zero()
Set to zero vector.
Definition: ROL_Vector.hpp:133
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
bool firstResetBPOE_
Definition: ROL_BPOE.hpp:40
void initialize(const Vector< Real > &x)
Initialize temporary variables.
Definition: ROL_BPOE.hpp:69
void sumAll(Real *input, Real *output, int dim) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
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.
Definition: ROL_BPOE.hpp:119
ROL::Ptr< Vector< Real > > dualVec1_
Definition: ROL_BPOE.hpp:38
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.
Definition: ROL_BPOE.hpp:172
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
Definition: ROL_BPOE.hpp:81
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
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 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.
Definition: ROL_BPOE.hpp:140
BPOE(ROL::ParameterList &parlist)
Definition: ROL_BPOE.hpp:62
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
Definition: ROL_BPOE.hpp:102
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.