ROL
ROL_EntropicRisk.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_EXPUTILITY_HPP
45#define ROL_EXPUTILITY_HPP
46
48
49namespace ROL {
50
65template<class Real>
66class EntropicRisk : public RandVarFunctional<Real> {
67private:
68 Real coeff_;
69
70 using RandVarFunctional<Real>::val_;
71 using RandVarFunctional<Real>::gv_;
72 using RandVarFunctional<Real>::g_;
73 using RandVarFunctional<Real>::hv_;
75
76 using RandVarFunctional<Real>::point_;
78
83
84 void checkInputs(void) const {
85 Real zero(0);
86 ROL_TEST_FOR_EXCEPTION((coeff_ <= zero), std::invalid_argument,
87 ">>> ERROR (ROL::EntropicRisk): Rate must be positive!");
88 }
89
90public:
95 EntropicRisk(const Real coeff = 1)
96 : RandVarFunctional<Real>(), coeff_(coeff) {
98 }
99
108 EntropicRisk(ROL::ParameterList &parlist)
109 : RandVarFunctional<Real>() {
110 ROL::ParameterList &list
111 = parlist.sublist("SOL").sublist("Risk Measure").sublist("Entropic Risk");
112 coeff_ = list.get<Real>("Rate");
113 checkInputs();
114 }
115
117 const Vector<Real> &x,
118 const std::vector<Real> &xstat,
119 Real &tol) {
120 Real val = computeValue(obj,x,tol);
121 val_ += weight_ * std::exp(coeff_*val);
122 }
123
124 Real getValue(const Vector<Real> &x,
125 const std::vector<Real> &xstat,
126 SampleGenerator<Real> &sampler) {
127 Real ev(0);
128 sampler.sumAll(&val_,&ev,1);
129 return std::log(ev)/coeff_;
130 }
131
133 const Vector<Real> &x,
134 const std::vector<Real> &xstat,
135 Real &tol) {
136 Real val = computeValue(obj,x,tol);
137 Real ev = std::exp(coeff_*val);
138 val_ += weight_ * ev;
139 computeGradient(*dualVector_,obj,x,tol);
140 g_->axpy(weight_*ev,*dualVector_);
141 }
142
144 std::vector<Real> &gstat,
145 const Vector<Real> &x,
146 const std::vector<Real> &xstat,
147 SampleGenerator<Real> &sampler) {
148 Real ev(0), one(1);
149 sampler.sumAll(&val_,&ev,1);
150 sampler.sumAll(*g_,g);
151 g.scale(one/ev);
152 }
153
155 const Vector<Real> &v,
156 const std::vector<Real> &vstat,
157 const Vector<Real> &x,
158 const std::vector<Real> &xstat,
159 Real &tol) {
160 Real val = computeValue(obj,x,tol);
161 Real ev = std::exp(coeff_*val);
162 val_ += weight_ * ev;
163 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
164 gv_ -= weight_ * ev * gv;
165 g_->axpy(weight_*ev,*dualVector_);
166 hv_->axpy(weight_*coeff_*ev*gv,*dualVector_);
167 computeHessVec(*dualVector_,obj,v,x,tol);
168 hv_->axpy(weight_*ev,*dualVector_);
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 one(1);
179 std::vector<Real> myval(2), val(2);
180 myval[0] = val_;
181 myval[1] = gv_;
182 sampler.sumAll(&myval[0],&val[0],2);
183
184 sampler.sumAll(*hv_,hv);
185 hv.scale(one/val[0]);
186
187 dualVector_->zero();
188 sampler.sumAll(*g_,*dualVector_);
189 hv.axpy(coeff_*val[1]/(val[0]*val[0]),*dualVector_);
190 }
191};
192
193}
194
195#endif
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Provides an interface for the entropic risk.
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
void checkInputs(void) const
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.
EntropicRisk(const Real coeff=1)
Constructor.
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 updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
EntropicRisk(ROL::ParameterList &parlist)
Constructor.
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 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)
Ptr< Vector< Real > > g_
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > hv_
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.
Definition: ROL_Vector.hpp:84
virtual void scale(const Real alpha)=0
Compute where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153