ROL
ROL_EntropicRisk.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_EXPUTILITY_HPP
11 #define ROL_EXPUTILITY_HPP
12 
14 
15 namespace ROL {
16 
31 template<class Real>
32 class EntropicRisk : public RandVarFunctional<Real> {
33 private:
34  Real coeff_;
35 
41 
44 
49 
50  void checkInputs(void) const {
51  Real zero(0);
52  ROL_TEST_FOR_EXCEPTION((coeff_ <= zero), std::invalid_argument,
53  ">>> ERROR (ROL::EntropicRisk): Rate must be positive!");
54  }
55 
56 public:
61  EntropicRisk(const Real coeff = 1)
62  : RandVarFunctional<Real>(), coeff_(coeff) {
63  checkInputs();
64  }
65 
74  EntropicRisk(ROL::ParameterList &parlist)
75  : RandVarFunctional<Real>() {
76  ROL::ParameterList &list
77  = parlist.sublist("SOL").sublist("Risk Measure").sublist("Entropic Risk");
78  coeff_ = list.get<Real>("Rate");
79  checkInputs();
80  }
81 
83  const Vector<Real> &x,
84  const std::vector<Real> &xstat,
85  Real &tol) {
86  Real val = computeValue(obj,x,tol);
87  val_ += weight_ * std::exp(coeff_*val);
88  }
89 
90  Real getValue(const Vector<Real> &x,
91  const std::vector<Real> &xstat,
92  SampleGenerator<Real> &sampler) {
93  Real ev(0);
94  sampler.sumAll(&val_,&ev,1);
95  return std::log(ev)/coeff_;
96  }
97 
99  const Vector<Real> &x,
100  const std::vector<Real> &xstat,
101  Real &tol) {
102  Real val = computeValue(obj,x,tol);
103  Real ev = std::exp(coeff_*val);
104  val_ += weight_ * ev;
105  computeGradient(*dualVector_,obj,x,tol);
106  g_->axpy(weight_*ev,*dualVector_);
107  }
108 
110  std::vector<Real> &gstat,
111  const Vector<Real> &x,
112  const std::vector<Real> &xstat,
113  SampleGenerator<Real> &sampler) {
114  Real ev(0), one(1);
115  sampler.sumAll(&val_,&ev,1);
116  sampler.sumAll(*g_,g);
117  g.scale(one/ev);
118  }
119 
121  const Vector<Real> &v,
122  const std::vector<Real> &vstat,
123  const Vector<Real> &x,
124  const std::vector<Real> &xstat,
125  Real &tol) {
126  Real val = computeValue(obj,x,tol);
127  Real ev = std::exp(coeff_*val);
128  val_ += weight_ * ev;
129  Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
130  gv_ -= weight_ * ev * gv;
131  g_->axpy(weight_*ev,*dualVector_);
132  hv_->axpy(weight_*coeff_*ev*gv,*dualVector_);
133  computeHessVec(*dualVector_,obj,v,x,tol);
134  hv_->axpy(weight_*ev,*dualVector_);
135  }
136 
138  std::vector<Real> &hvstat,
139  const Vector<Real> &v,
140  const std::vector<Real> &vstat,
141  const Vector<Real> &x,
142  const std::vector<Real> &xstat,
143  SampleGenerator<Real> &sampler) {
144  Real one(1);
145  std::vector<Real> myval(2), val(2);
146  myval[0] = val_;
147  myval[1] = gv_;
148  sampler.sumAll(&myval[0],&val[0],2);
149 
150  sampler.sumAll(*hv_,hv);
151  hv.scale(one/val[0]);
152 
153  dualVector_->zero();
154  sampler.sumAll(*g_,*dualVector_);
155  hv.axpy(coeff_*val[1]/(val[0]*val[0]),*dualVector_);
156  }
157 };
158 
159 }
160 
161 #endif
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.
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)
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:119
Ptr< Vector< Real > > hv_
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.
Ptr< Vector< Real > > dualVector_
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.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
EntropicRisk(const Real coeff=1)
Constructor.
void sumAll(Real *input, Real *output, int dim) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
void checkInputs(void) const
Provides an interface for the entropic risk.
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...
EntropicRisk(ROL::ParameterList &parlist)
Constructor.
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.