ROL
ROL_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_BPOE_HPP
45 #define ROL_BPOE_HPP
46 
47 #include "ROL_RiskMeasure.hpp"
48 
63 namespace ROL {
64 
65 template<class Real>
66 class BPOE : public RiskMeasure<Real> {
67 private:
68  Real threshold_;
69  Real order_;
70 
71  Real xvar_, vvar_;
72 
73  std::vector<Real> hvec_;
74  Teuchos::RCP<Vector<Real> > dualVec1_, dualVec2_;
75 
77 
78 public:
79  BPOE(const Real threshold, const Real order=1)
80  : RiskMeasure<Real>(), threshold_(threshold), order_(order), firstReset_(true) {
81  hvec_.resize(5);
82  }
83 
84  BPOE(Teuchos::ParameterList &parlist) : RiskMeasure<Real>(), firstReset_(true) {
85  threshold_ = parlist.sublist("SOL").sublist("BPOE").get("Threshold",1.0);
86  order_ = parlist.sublist("SOL").sublist("BPOE").get("Moment Order",1.0);
87  hvec_.resize(5);
88  }
89 
90  void reset(Teuchos::RCP<Vector<Real> > &x0, const Vector<Real> &x) {
92  xvar_ = Teuchos::dyn_cast<const RiskVector<Real> >(x).getStatistic(0);
93  }
94 
95  void reset(Teuchos::RCP<Vector<Real> > &x0, const Vector<Real> &x,
96  Teuchos::RCP<Vector<Real> > &v0, const Vector<Real> &v) {
97  reset(x0,x);
98  v0 = Teuchos::rcp_const_cast<Vector<Real> >(
99  Teuchos::dyn_cast<const RiskVector<Real> >(v).getVector());
100  vvar_ = Teuchos::dyn_cast<const RiskVector<Real> >(v).getStatistic(0);
101 
102  if ( firstReset_ ) {
103  dualVec1_ = (x0->dual()).clone();
104  dualVec2_ = (x0->dual()).clone();
105  firstReset_ = false;
106  }
107  dualVec1_->zero();
108  dualVec2_->zero();
109  hvec_.assign(5,0);
110  }
111 
112  void update(const Real val, const Real weight) {
113  const Real zero(0), one(1);
114  Real bp = xvar_*(val-threshold_)+one;
115  if ( bp > zero ) {
116  RiskMeasure<Real>::val_ += weight
117  * ((order_==one) ? bp : std::pow(bp,order_));
118  }
119  }
120 
122  const Real one(1);
123  Real val = RiskMeasure<Real>::val_, bpoe(0);
124  sampler.sumAll(&val,&bpoe,1);
125  return ((order_==one) ? bpoe : std::pow(bpoe,one/order_));
126  }
127 
128  void update(const Real val, const Vector<Real> &g, const Real weight) {
129  const Real zero(0), one(1), two(2);
130  Real bp = xvar_*(val-threshold_)+one;
131  if ( bp > zero ) {
132  Real pvalp0 = ((order_==one) ? bp : std::pow(bp,order_));
133  Real pvalp1 = ((order_==one) ? one : ((order_==two) ? bp : std::pow(bp,order_-one)));
134  RiskMeasure<Real>::val_ += weight * pvalp0;
135  RiskMeasure<Real>::gv_ += weight * pvalp1 * (val - threshold_);
136  RiskMeasure<Real>::g_->axpy(weight * pvalp1, g);
137  }
138  }
139 
141  const Real zero(0), one(1);
142  std::vector<Real> myvals(2), gvals(2);
143  myvals[0] = RiskMeasure<Real>::val_;
144  myvals[1] = RiskMeasure<Real>::gv_;
145  sampler.sumAll(&myvals[0],&gvals[0],2);
146 
147  Real gvar(0);
148  if ( gvals[0] > zero) {
149  Teuchos::RCP<Vector<Real> > gvec
150  = Teuchos::dyn_cast<RiskVector<Real> >(g).getVector();
151  sampler.sumAll(*(RiskMeasure<Real>::g_),*gvec);
152  Real norm = std::pow(gvals[0],(order_-one)/order_);
153  gvec->scale(xvar_/norm);
154  gvar = gvals[1]/norm;
155  }
156  Teuchos::dyn_cast<RiskVector<Real> >(g).setStatistic(gvar);
157  }
158 
159  void update(const Real val, const Vector<Real> &g, const Real gv, const Vector<Real> &hv,
160  const Real weight) {
161  const Real zero(0), one(1), two(2), three(3);
162  Real bp = xvar_*(val-threshold_)+one;
163  if ( bp > zero ) {
164  Real pvalp0 = ((order_==one) ? bp : std::pow(bp,order_));
165  Real pvalp1 = ((order_==one) ? one
166  : ((order_==two) ? bp : std::pow(bp,order_-one)));
167  Real pvalp2 = ((order_==one) ? zero
168  : ((order_==two) ? one
169  : ((order_==three) ? bp : std::pow(bp,order_-two))));
170  hvec_[0] += weight * pvalp0;
171  hvec_[1] += weight * pvalp1 * (val-threshold_);
172  hvec_[2] += weight * pvalp2 * (val-threshold_) * (val-threshold_);
173  hvec_[3] += weight * pvalp1 * gv;
174  hvec_[4] += weight * pvalp2 * (val-threshold_) * gv;
175  RiskMeasure<Real>::g_->axpy(weight * pvalp1, g);
176  dualVec1_->axpy(weight * pvalp2 * (val-threshold_), g);
177  dualVec2_->axpy(weight * pvalp2 * gv, g);
178  RiskMeasure<Real>::hv_->axpy(weight * pvalp1, hv);
179  }
180  }
181 
183  const Real zero(0), one(1), two(2);
184  std::vector<Real> gvals(5);
185  sampler.sumAll(&hvec_[0],&gvals[0],5);
186 
187  Real hvar(0);
188  if ( gvals[0] > zero ) {
189  Teuchos::RCP<Vector<Real> > hvec
190  = Teuchos::dyn_cast<RiskVector<Real> >(hv).getVector();
191  Real norm0 = ((order_==one) ? one
192  : ((order_==two) ? std::sqrt(gvals[0])
193  : std::pow(gvals[0],(order_-one)/order_)));
194  Real norm1 = ((order_==one) ? gvals[0]
195  : std::pow(gvals[0],(two*order_-one)/order_));
196  hvar = (order_-one)*((gvals[2]/norm0 - gvals[1]*gvals[1]/norm1)*vvar_
197  +xvar_*(gvals[4]/norm0 - gvals[3]*gvals[1]/norm1))
198  +(gvals[3]/norm0);
199 
200  sampler.sumAll(*RiskMeasure<Real>::hv_,*hvec);
201  hvec->scale(xvar_/norm0);
202 
204  Real coeff = -(order_-one)*xvar_*(xvar_*gvals[3]+vvar_*gvals[1])/norm1+vvar_/norm0;
205  hvec->axpy(coeff,*RiskMeasure<Real>::hv_);
206 
207  sampler.sumAll(*dualVec1_,*RiskMeasure<Real>::hv_);
208  hvec->axpy((order_-one)*vvar_*xvar_/norm0,*RiskMeasure<Real>::hv_);
209 
210  sampler.sumAll(*dualVec2_,*RiskMeasure<Real>::hv_);
211  hvec->axpy((order_-one)*xvar_*xvar_/norm0,*RiskMeasure<Real>::hv_);
212  }
213  Teuchos::dyn_cast<RiskVector<Real> >(hv).setStatistic(hvar);
214  }
215 };
216 
217 }
218 
219 #endif
void update(const Real val, const Vector< Real > &g, const Real gv, const Vector< Real > &hv, const Real weight)
Update internal risk measure storage for Hessian-time-a-vector computation.
Definition: ROL_BPOE.hpp:159
bool firstReset_
Definition: ROL_BPOE.hpp:76
Provides the implementation of the buffered probability of exceedance.
Definition: ROL_BPOE.hpp:66
Teuchos::RCP< Vector< Real > > dualVec1_
Definition: ROL_BPOE.hpp:74
Real getValue(SampleGenerator< Real > &sampler)
Return risk measure value.
Definition: ROL_BPOE.hpp:121
BPOE(const Real threshold, const Real order=1)
Definition: ROL_BPOE.hpp:79
Real threshold_
Definition: ROL_BPOE.hpp:68
std::vector< Real > hvec_
Definition: ROL_BPOE.hpp:73
void sumAll(Real *input, Real *output, int dim) const
Real order_
Definition: ROL_BPOE.hpp:69
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:76
BPOE(Teuchos::ParameterList &parlist)
Definition: ROL_BPOE.hpp:84
void getGradient(Vector< Real > &g, SampleGenerator< Real > &sampler)
Return risk measure (sub)gradient.
Definition: ROL_BPOE.hpp:140
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
Definition: ROL_BPOE.hpp:90
void getHessVec(Vector< Real > &hv, SampleGenerator< Real > &sampler)
Return risk measure Hessian-times-a-vector.
Definition: ROL_BPOE.hpp:182
void update(const Real val, const Real weight)
Update internal risk measure storage for value computation.
Definition: ROL_BPOE.hpp:112
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x, Teuchos::RCP< Vector< Real > > &v0, const Vector< Real > &v)
Reset internal risk measure storage. Called for Hessian-times-a-vector computation.
Definition: ROL_BPOE.hpp:95
Real vvar_
Definition: ROL_BPOE.hpp:71
void update(const Real val, const Vector< Real > &g, const Real weight)
Update internal risk measure storage for gradient computation.
Definition: ROL_BPOE.hpp:128
virtual void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
Real xvar_
Definition: ROL_BPOE.hpp:71
Teuchos::RCP< Vector< Real > > dualVec2_
Definition: ROL_BPOE.hpp:74
Provides the interface to implement risk measures.