ROL
ROL_CVaR.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_CVAR_HPP
45#define ROL_CVAR_HPP
46
48#include "ROL_PlusFunction.hpp"
49
75namespace ROL {
76
77template<class Real>
78class CVaR : public RandVarFunctional<Real> {
79private:
80 Ptr<PlusFunction<Real> > plusFunction_;
81 Real prob_;
82 Real coeff_;
83
84 using RandVarFunctional<Real>::val_;
85 using RandVarFunctional<Real>::gv_;
86 using RandVarFunctional<Real>::g_;
87 using RandVarFunctional<Real>::hv_;
89
90 using RandVarFunctional<Real>::point_;
92
97
98 void checkInputs(void) const {
99 Real zero(0), one(1);
100 ROL_TEST_FOR_EXCEPTION((prob_ <= zero) || (prob_ >= one), std::invalid_argument,
101 ">>> ERROR (ROL::CVaR): Confidence level must be between 0 and 1!");
102 ROL_TEST_FOR_EXCEPTION((coeff_ < zero) || (coeff_ > one), std::invalid_argument,
103 ">>> ERROR (ROL::CVaR): Convex combination parameter must be positive!");
104 ROL_TEST_FOR_EXCEPTION(plusFunction_ == nullPtr, std::invalid_argument,
105 ">>> ERROR (ROL::CVaR): PlusFunction pointer is null!");
106 }
107
108public:
109
118 CVaR( const Real prob, const Real coeff,
119 const Ptr<PlusFunction<Real> > &pf )
120 : RandVarFunctional<Real>(), plusFunction_(pf), prob_(prob), coeff_(coeff) {
121 checkInputs();
122 }
123
134 CVaR( ROL::ParameterList &parlist )
135 : RandVarFunctional<Real>() {
136 ROL::ParameterList &list
137 = parlist.sublist("SOL").sublist("Risk Measure").sublist("CVaR");
138 // Check CVaR inputs
139 prob_ = list.get<Real>("Confidence Level");
140 coeff_ = list.get<Real>("Convex Combination Parameter");
141 // Build (approximate) plus function
142 plusFunction_ = makePtr<PlusFunction<Real>>(list);
143 // Check Inputs
144 checkInputs();
145 }
146
148 const Vector<Real> &x,
149 const std::vector<Real> &xstat,
150 Real &tol) {
151 Real one(1);
152 Real val = computeValue(obj,x,tol);
153 Real pf = plusFunction_->evaluate(val-xstat[0],0);
154 val_ += weight_*((one-coeff_)*val + coeff_/(one-prob_)*pf);
155 }
156
158 const Vector<Real> &x,
159 const std::vector<Real> &xstat,
160 Real &tol) {
161 Real one(1);
162 Real val = computeValue(obj,x,tol);
163 Real pf = plusFunction_->evaluate(val-xstat[0],1);
164 val_ += weight_*pf;
165 Real c = (one-coeff_) + coeff_/(one-prob_)*pf;
166 if (std::abs(c) >= ROL_EPSILON<Real>()) {
167 computeGradient(*dualVector_,obj,x,tol);
168 g_->axpy(weight_*c,*dualVector_);
169 }
170 }
171
173 const Vector<Real> &v,
174 const std::vector<Real> &vstat,
175 const Vector<Real> &x,
176 const std::vector<Real> &xstat,
177 Real &tol) {
178 Real one(1);
179 Real val = computeValue(obj,x,tol);
180 Real pf1 = plusFunction_->evaluate(val-xstat[0],1);
181 Real pf2 = plusFunction_->evaluate(val-xstat[0],2);
182 Real c(0);
183 if (std::abs(pf2) >= ROL_EPSILON<Real>()) {
184 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
185 val_ += weight_*pf2*(vstat[0]-gv);
186 c = pf2*coeff_/(one-prob_)*(gv-vstat[0]);
187 hv_->axpy(weight_*c,*dualVector_);
188 }
189 c = (one-coeff_) + coeff_/(one-prob_)*pf1;
190 if (std::abs(c) >= ROL_EPSILON<Real>()) {
191 computeHessVec(*dualVector_,obj,v,x,tol);
192 hv_->axpy(weight_*c,*dualVector_);
193 }
194 }
195
196 Real getValue(const Vector<Real> &x,
197 const std::vector<Real> &xstat,
198 SampleGenerator<Real> &sampler) {
199 Real cvar(0);
200 sampler.sumAll(&val_,&cvar,1);
201 cvar += coeff_*xstat[0];
202 return cvar;
203 }
204
206 std::vector<Real> &gstat,
207 const Vector<Real> &x,
208 const std::vector<Real> &xstat,
209 SampleGenerator<Real> &sampler) {
210 Real var(0), one(1);
211 sampler.sumAll(&val_,&var,1);
212 var *= -coeff_/(one-prob_);
213 var += coeff_;
214 gstat[0] = var;
215 sampler.sumAll(*g_,g);
216 }
217
219 std::vector<Real> &hvstat,
220 const Vector<Real> &v,
221 const std::vector<Real> &vstat,
222 const Vector<Real> &x,
223 const std::vector<Real> &xstat,
224 SampleGenerator<Real> &sampler) {
225 Real var(0), one(1);
226 sampler.sumAll(&val_,&var,1);
227 var *= coeff_/(one-prob_);
228 hvstat[0] = var;
229 sampler.sumAll(*hv_,hv);
230 }
231};
232
233}
234
235#endif
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Provides an interface for a convex combination of the expected value and the conditional value-at-ris...
Definition: ROL_CVaR.hpp:78
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
Definition: ROL_CVaR.hpp:196
CVaR(ROL::ParameterList &parlist)
Constructor.
Definition: ROL_CVaR.hpp:134
Real coeff_
Definition: ROL_CVaR.hpp:82
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
Definition: ROL_CVaR.hpp:147
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
Definition: ROL_CVaR.hpp:157
Real prob_
Definition: ROL_CVaR.hpp:81
Ptr< PlusFunction< Real > > plusFunction_
Definition: ROL_CVaR.hpp:80
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.
Definition: ROL_CVaR.hpp:205
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.
Definition: ROL_CVaR.hpp:172
CVaR(const Real prob, const Real coeff, const Ptr< PlusFunction< Real > > &pf)
Constructor.
Definition: ROL_CVaR.hpp:118
void checkInputs(void) const
Definition: ROL_CVaR.hpp:98
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.
Definition: ROL_CVaR.hpp:218
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