ROL
ROL_CoherentEntropicRisk.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_COHERENTEXPUTILITY_HPP
45 #define ROL_COHERENTEXPUTILITY_HPP
46 
48 
64 namespace ROL {
65 
66 template<class Real>
68 private:
69  Real dval1_;
70  Real dval2_;
71  Real dval3_;
72 
78 
80 
85 
86 public:
88  dval1_(0), dval2_(0), dval3_(0) {}
89 
90  void initialize(const Vector<Real> &x) {
92  Real zero(0);
93  dval1_ = zero; dval2_ = zero; dval3_ = zero;
94  }
95 
97  const Vector<Real> &x,
98  const std::vector<Real> &xstat,
99  Real &tol) {
100  Real val = computeValue(obj,x,tol);
101  val_ += weight_ * std::exp(val/xstat[0]);
102  }
103 
104  Real getValue(const Vector<Real> &x,
105  const std::vector<Real> &xstat,
106  SampleGenerator<Real> &sampler) {
107  Real ev(0);
108  sampler.sumAll(&val_,&ev,1);
109  return xstat[0]*std::log(ev);
110  }
111 
113  const Vector<Real> &x,
114  const std::vector<Real> &xstat,
115  Real &tol) {
116  Real val = computeValue(obj,x,tol);
117  Real ev = std::exp(val/xstat[0]);
118  val_ += weight_ * ev;
119  gv_ += weight_ * ev * val;
120  computeGradient(*dualVector_,obj,x,tol);
121  g_->axpy(weight_*ev,*dualVector_);
122  }
123 
125  std::vector<Real> &gstat,
126  const Vector<Real> &x,
127  const std::vector<Real> &xstat,
128  SampleGenerator<Real> &sampler) {
129  const Real one(1);
130  // Perform sum over batches
131  std::vector<Real> myval(2,0), val(2,0);
132  myval[0] = val_;
133  myval[1] = gv_;
134  sampler.sumAll(&myval[0],&val[0],2);
135 
136  sampler.sumAll(*g_,g);
137  g.scale(one/val[0]);
138  gstat[0] = std::log(val[0]) - val[1]/(val[0]*xstat[0]);
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  Real val = computeValue(obj,x,tol);
148  Real ev = std::exp(val/xstat[0]);
149  val_ += weight_ * ev;
150 
151  Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
152  gv_ += weight_ * ev * gv;
153  g_->axpy(weight_*ev,*dualVector_);
154  hv_->axpy(weight_*ev*(gv-val*vstat[0]/xstat[0])/xstat[0],*dualVector_);
155 
156  dval1_ += weight_ * ev * val;
157  dval2_ += weight_ * ev * val * val;
158  dval3_ += weight_ * ev * val * gv;
159 
160  computeHessVec(*dualVector_,obj,v,x,tol);
161  hv_->axpy(weight_*ev,*dualVector_);
162  }
163 
165  std::vector<Real> &hvstat,
166  const Vector<Real> &v,
167  const std::vector<Real> &vstat,
168  const Vector<Real> &x,
169  const std::vector<Real> &xstat,
170  SampleGenerator<Real> &sampler) {
171  const Real one(1);
172  std::vector<Real> myval(5,0), val(5,0);
173  myval[0] = val_;
174  myval[1] = gv_;
175  myval[2] = dval1_;
176  myval[3] = dval2_;
177  myval[4] = dval3_;
178  sampler.sumAll(&myval[0],&val[0],5);
179 
180  Real xs2 = xstat[0]*xstat[0];
181  Real xs3 = xs2*xstat[0];
182  Real v02 = val[0]*val[0];
183  Real h11 = (val[3]*val[0] - val[2]*val[2])/(v02*xs3) * vstat[0];
184  Real h12 = (val[1]*val[2] - val[4]*val[0])/(v02*xs2);
185  hvstat[0] = h11+h12;
186  sampler.sumAll(*hv_,hv);
187  hv.scale(one/val[0]);
188 
189  dualVector_->zero();
190  sampler.sumAll(*g_,*dualVector_);
191  hv.axpy((vstat[0]*val[2]/xs2-val[1]/xstat[0])/v02,*dualVector_);
192  }
193 };
194 
195 }
196 
197 #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)
virtual void scale(const Real alpha)=0
Compute where .
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:153
Ptr< Vector< Real > > hv_
Ptr< Vector< Real > > dualVector_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
void sumAll(Real *input, Real *output, int dim) const
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
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.
Provides the interface for the coherent entropic risk measure.
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 updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
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 initialize(const Vector< Real > &x)
Initialize temporary variables.
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 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.
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.