ROL
ROL_ExpectationQuadRisk.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_EXPECTATIONQUADRISK_HPP
11#define ROL_EXPECTATIONQUADRISK_HPP
12
15#include "ROL_Types.hpp"
16
52namespace ROL {
53
54template<class Real>
56private:
57 Ptr<ExpectationQuad<Real>> eq_;
58
59 using RandVarFunctional<Real>::val_;
60 using RandVarFunctional<Real>::gv_;
61 using RandVarFunctional<Real>::g_;
62 using RandVarFunctional<Real>::hv_;
64
65 using RandVarFunctional<Real>::point_;
67
72
73public:
75 : RandVarFunctional<Real>(), eq_(eq) {}
76
79 void checkRegret(void) {
80 eq_->check();
81 }
82
84 const Vector<Real> &x,
85 const std::vector<Real> &xstat,
86 Real &tol) {
87 Real val = computeValue(obj,x,tol);
88 Real r = eq_->regret(val-xstat[0],0);
89 val_ += weight_ * r;
90 }
91
93 const Vector<Real> &x,
94 const std::vector<Real> &xstat,
95 Real &tol) {
96 Real val = computeValue(obj,x,tol);
97 Real r = eq_->regret(val-xstat[0],1);
98 if (std::abs(r) >= ROL_EPSILON<Real>()) {
99 val_ -= weight_ * r;
100 computeGradient(*dualVector_,obj,x,tol);
101 g_->axpy(weight_*r,*dualVector_);
102 }
103 }
104
106 const Vector<Real> &v,
107 const std::vector<Real> &vstat,
108 const Vector<Real> &x,
109 const std::vector<Real> &xstat,
110 Real &tol) {
111 Real val = computeValue(obj,x,tol);
112 Real r1 = eq_->regret(val-xstat[0],1);
113 Real r2 = eq_->regret(val-xstat[0],2);
114 if (std::abs(r2) >= ROL_EPSILON<Real>()) {
115 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
116 val_ += weight_ * r2 * (vstat[0] - gv);
117 hv_->axpy(weight_*r2*(gv-vstat[0]),*dualVector_);
118 }
119 if (std::abs(r1) >= ROL_EPSILON<Real>()) {
120 computeHessVec(*dualVector_,obj,v,x,tol);
121 hv_->axpy(weight_*r1,*dualVector_);
122 }
123 }
124
125 Real getValue(const Vector<Real> &x,
126 const std::vector<Real> &xstat,
127 SampleGenerator<Real> &sampler) {
128 Real val(0);
129 sampler.sumAll(&val_,&val,1);
130 val += xstat[0];
131 return val;
132 }
133
135 std::vector<Real> &gstat,
136 const Vector<Real> &x,
137 const std::vector<Real> &xstat,
138 SampleGenerator<Real> &sampler) {
139 Real stat(0), one(1);
140 sampler.sumAll(&val_,&stat,1);
141 stat += one;
142 gstat[0] = stat;
143 sampler.sumAll(*g_,g);
144 }
145
147 std::vector<Real> &hvstat,
148 const Vector<Real> &v,
149 const std::vector<Real> &vstat,
150 const Vector<Real> &x,
151 const std::vector<Real> &xstat,
152 SampleGenerator<Real> &sampler) {
153 Real stat(0);
154 sampler.sumAll(&val_,&stat,1);
155 hvstat[0] = stat;
156 sampler.sumAll(*hv_,hv);
157 }
158};
159
160}
161
162#endif
Contains definitions of custom data types in ROL.
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
ExpectationQuadRisk(const Ptr< ExpectationQuad< Real > > &eq)
Ptr< ExpectationQuad< Real > > eq_
void checkRegret(void)
Run derivative tests for the scalar regret function.
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
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 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 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 updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
Provides a general interface for risk and error measures generated through the expectation risk quadr...
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)
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.