ROL
ROL_CoherentEntropicRisk.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_COHERENTEXPUTILITY_HPP
11#define ROL_COHERENTEXPUTILITY_HPP
12
14
30namespace ROL {
31
32template<class Real>
34private:
35 Real dval1_;
36 Real dval2_;
37 Real dval3_;
38
39 using RandVarFunctional<Real>::val_;
40 using RandVarFunctional<Real>::gv_;
41 using RandVarFunctional<Real>::g_;
42 using RandVarFunctional<Real>::hv_;
44
46
51
52public:
54 dval1_(0), dval2_(0), dval3_(0) {}
55
56 void initialize(const Vector<Real> &x) {
58 Real zero(0);
60 }
61
63 const Vector<Real> &x,
64 const std::vector<Real> &xstat,
65 Real &tol) {
66 Real val = computeValue(obj,x,tol);
67 val_ += weight_ * std::exp(val/xstat[0]);
68 }
69
70 Real getValue(const Vector<Real> &x,
71 const std::vector<Real> &xstat,
72 SampleGenerator<Real> &sampler) {
73 Real ev(0);
74 sampler.sumAll(&val_,&ev,1);
75 return xstat[0]*std::log(ev);
76 }
77
79 const Vector<Real> &x,
80 const std::vector<Real> &xstat,
81 Real &tol) {
82 Real val = computeValue(obj,x,tol);
83 Real ev = std::exp(val/xstat[0]);
84 val_ += weight_ * ev;
85 gv_ += weight_ * ev * val;
86 computeGradient(*dualVector_,obj,x,tol);
87 g_->axpy(weight_*ev,*dualVector_);
88 }
89
91 std::vector<Real> &gstat,
92 const Vector<Real> &x,
93 const std::vector<Real> &xstat,
94 SampleGenerator<Real> &sampler) {
95 const Real one(1);
96 // Perform sum over batches
97 std::vector<Real> myval(2,0), val(2,0);
98 myval[0] = val_;
99 myval[1] = gv_;
100 sampler.sumAll(&myval[0],&val[0],2);
101
102 sampler.sumAll(*g_,g);
103 g.scale(one/val[0]);
104 gstat[0] = std::log(val[0]) - val[1]/(val[0]*xstat[0]);
105 }
106
108 const Vector<Real> &v,
109 const std::vector<Real> &vstat,
110 const Vector<Real> &x,
111 const std::vector<Real> &xstat,
112 Real &tol) {
113 Real val = computeValue(obj,x,tol);
114 Real ev = std::exp(val/xstat[0]);
115 val_ += weight_ * ev;
116
117 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
118 gv_ += weight_ * ev * gv;
119 g_->axpy(weight_*ev,*dualVector_);
120 hv_->axpy(weight_*ev*(gv-val*vstat[0]/xstat[0])/xstat[0],*dualVector_);
121
122 dval1_ += weight_ * ev * val;
123 dval2_ += weight_ * ev * val * val;
124 dval3_ += weight_ * ev * val * gv;
125
126 computeHessVec(*dualVector_,obj,v,x,tol);
127 hv_->axpy(weight_*ev,*dualVector_);
128 }
129
131 std::vector<Real> &hvstat,
132 const Vector<Real> &v,
133 const std::vector<Real> &vstat,
134 const Vector<Real> &x,
135 const std::vector<Real> &xstat,
136 SampleGenerator<Real> &sampler) {
137 const Real one(1);
138 std::vector<Real> myval(5,0), val(5,0);
139 myval[0] = val_;
140 myval[1] = gv_;
141 myval[2] = dval1_;
142 myval[3] = dval2_;
143 myval[4] = dval3_;
144 sampler.sumAll(&myval[0],&val[0],5);
145
146 Real xs2 = xstat[0]*xstat[0];
147 Real xs3 = xs2*xstat[0];
148 Real v02 = val[0]*val[0];
149 Real h11 = (val[3]*val[0] - val[2]*val[2])/(v02*xs3) * vstat[0];
150 Real h12 = (val[1]*val[2] - val[4]*val[0])/(v02*xs2);
151 hvstat[0] = h11+h12;
152 sampler.sumAll(*hv_,hv);
153 hv.scale(one/val[0]);
154
155 dualVector_->zero();
156 sampler.sumAll(*g_,*dualVector_);
157 hv.axpy((vstat[0]*val[2]/xs2-val[1]/xstat[0])/v02,*dualVector_);
158 }
159};
160
161}
162
163#endif
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Provides the interface for the coherent entropic risk measure.
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
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 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 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.
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 initialize(const Vector< Real > &x)
Initialize temporary variables.
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
Provides the interface to evaluate objective functions.
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > dualVector_
Real computeGradVec(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
void sumAll(Real *input, Real *output, int dim) const
Defines the linear algebra or vector space interface.
virtual void scale(const Real alpha)=0
Compute where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .