ROL
ROL_ExpectationQuadRegret.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_EXPECTATIONQUADREGRET_HPP
11#define ROL_EXPECTATIONQUADREGRET_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:
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 val_ += weight_ * eq_->regret(val,0);
89 }
90
92 const Vector<Real> &x,
93 const std::vector<Real> &xstat,
94 Real &tol) {
95 Real val = computeValue(obj,x,tol);
96 Real r = eq_->regret(val,1);
97 if (std::abs(r) >= ROL_EPSILON<Real>()) {
98 computeGradient(*dualVector_,obj,x,tol);
99 g_->axpy(weight_*r,*dualVector_);
100 }
101 }
102
104 const Vector<Real> &v,
105 const std::vector<Real> &vstat,
106 const Vector<Real> &x,
107 const std::vector<Real> &xstat,
108 Real &tol) {
109 Real val = computeValue(obj,x,tol);
110 Real r1 = eq_->regret(val,1);
111 Real r2 = eq_->regret(val,2);
112 if (std::abs(r2) >= ROL_EPSILON<Real>()) {
113 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
114 hv_->axpy(weight_*r2*gv,*dualVector_);
115 }
116 if (std::abs(r1) >= ROL_EPSILON<Real>()) {
117 computeHessVec(*dualVector_,obj,v,x,tol);
118 hv_->axpy(weight_*r1,*dualVector_);
119 }
120 }
121
122 Real getValue(const Vector<Real> &x,
123 const std::vector<Real> &xstat,
124 SampleGenerator<Real> &sampler) {
125 Real val(0);
126 sampler.sumAll(&val_,&val,1);
127 return val;
128 }
129
131 std::vector<Real> &gstat,
132 const Vector<Real> &x,
133 const std::vector<Real> &xstat,
134 SampleGenerator<Real> &sampler) {
135 sampler.sumAll(*g_,g);
136 }
137
139 std::vector<Real> &hvstat,
140 const Vector<Real> &v,
141 const std::vector<Real> &vstat,
142 const Vector<Real> &x,
143 const std::vector<Real> &xstat,
144 SampleGenerator<Real> &sampler) {
145 sampler.sumAll(*hv_,hv);
146 }
147};
148
149}
150
151#endif
Contains definitions of custom data types in ROL.
Provides a general interface for regret measures generated through the expectation risk quadrangle.
Ptr< ExpectationQuad< Real > > eq_
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 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 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 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.
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
ExpectationQuadRegret(const Ptr< ExpectationQuad< Real > > &eq)
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.