ROL
ROL_ExpectationQuadDeviation.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_EXPECTATIONQUADDEVIATION_HPP
45 #define ROL_EXPECTATIONQUADDEVIATION_HPP
46 
47 #include "ROL_ExpectationQuad.hpp"
49 #include "ROL_Types.hpp"
50 
86 namespace ROL {
87 
88 template<class Real>
90 private:
91  Ptr<ExpectationQuad<Real>> eq_;
92 
98 
101 
106 
107 public:
109  : RandVarFunctional<Real>(), eq_(eq) {}
110 
113  void checkRegret(void) {
114  eq_->check();
115  }
116 
118  const Vector<Real> &x,
119  const std::vector<Real> &xstat,
120  Real &tol) {
121  Real val = computeValue(obj,x,tol);
122  Real r = eq_->error(val-xstat[0],0);
123  val_ += weight_ * r;
124  }
125 
127  const Vector<Real> &x,
128  const std::vector<Real> &xstat,
129  Real &tol) {
130  Real val = computeValue(obj,x,tol);
131  Real r = eq_->error(val-xstat[0],1);
132  if (std::abs(r) >= ROL_EPSILON<Real>()) {
133  val_ -= weight_ * r;
134  computeGradient(*dualVector_,obj,x,tol);
135  g_->axpy(weight_*r,*dualVector_);
136  }
137  }
138 
140  const Vector<Real> &v,
141  const std::vector<Real> &vstat,
142  const Vector<Real> &x,
143  const std::vector<Real> &xstat,
144  Real &tol) {
145  Real val = computeValue(obj,x,tol);
146  Real r1 = eq_->error(val-xstat[0],1);
147  Real r2 = eq_->error(val-xstat[0],2);
148  if (std::abs(r2) >= ROL_EPSILON<Real>()) {
149  Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
150  val_ += weight_ * r2 * (vstat[0] - gv);
151  hv_->axpy(weight_*r2*(gv-vstat[0]),*dualVector_);
152  }
153  if (std::abs(r1) >= ROL_EPSILON<Real>()) {
154  computeHessVec(*dualVector_,obj,v,x,tol);
155  hv_->axpy(weight_*r1,*dualVector_);
156  }
157  }
158 
159  Real getValue(const Vector<Real> &x,
160  const std::vector<Real> &xstat,
161  SampleGenerator<Real> &sampler) {
162  Real val(0);
163  sampler.sumAll(&val_,&val,1);
164  return val;
165  }
166 
168  std::vector<Real> &gstat,
169  const Vector<Real> &x,
170  const std::vector<Real> &xstat,
171  SampleGenerator<Real> &sampler) {
172  Real stat(0);
173  sampler.sumAll(&val_,&stat,1);
174  gstat[0] = stat;
175  sampler.sumAll(*g_,g);
176  }
177 
179  std::vector<Real> &hvstat,
180  const Vector<Real> &v,
181  const std::vector<Real> &vstat,
182  const Vector<Real> &x,
183  const std::vector<Real> &xstat,
184  SampleGenerator<Real> &sampler) {
185  Real stat(0);
186  sampler.sumAll(&val_,&stat,1);
187  hvstat[0] = stat;
188  sampler.sumAll(*hv_,hv);
189  }
190 };
191 
192 }
193 
194 #endif
ROL::RandVarFunctional::hv_
Ptr< Vector< Real > > hv_
Definition: ROL_RandVarFunctional.hpp:92
ROL::ExpectationQuadDeviation::getGradient
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_ExpectationQuadDeviation.hpp:167
ROL::SampleGenerator
Definition: ROL_SampleGenerator.hpp:54
ROL::RandVarFunctional::g_
Ptr< Vector< Real > > g_
Definition: ROL_RandVarFunctional.hpp:91
ROL::RandVarFunctional::computeValue
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Definition: ROL_RandVarFunctional.hpp:100
ROL::RandVarFunctional::computeHessVec
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition: ROL_RandVarFunctional.hpp:153
ROL::ExpectationQuad
Provides a general interface for risk and error measures generated through the expectation risk quadr...
Definition: ROL_ExpectationQuad.hpp:87
ROL_RandVarFunctional.hpp
ROL::RandVarFunctional::dualVector_
Ptr< Vector< Real > > dualVector_
Definition: ROL_RandVarFunctional.hpp:93
ROL::ExpectationQuadDeviation::checkRegret
void checkRegret(void)
Run derivative tests for the scalar regret function.
Definition: ROL_ExpectationQuadDeviation.hpp:113
ROL::Vector
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
ROL::ExpectationQuadDeviation::ExpectationQuadDeviation
ExpectationQuadDeviation(const Ptr< ExpectationQuad< Real >> &eq)
Definition: ROL_ExpectationQuadDeviation.hpp:108
ROL::RandVarFunctional::val_
Real val_
Definition: ROL_RandVarFunctional.hpp:89
ROL_Types.hpp
Contains definitions of custom data types in ROL.
ROL::ExpectationQuadDeviation::updateHessVec
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_ExpectationQuadDeviation.hpp:139
ROL::ExpectationQuadDeviation::updateValue
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
Definition: ROL_ExpectationQuadDeviation.hpp:117
ROL::ExpectationQuadDeviation::getValue
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
Definition: ROL_ExpectationQuadDeviation.hpp:159
ROL
Definition: ROL_ElementwiseVector.hpp:61
ROL::ExpectationQuadDeviation
Definition: ROL_ExpectationQuadDeviation.hpp:89
ROL::ExpectationQuadDeviation::getHessVec
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_ExpectationQuadDeviation.hpp:178
ROL::ExpectationQuadDeviation::updateGradient
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_ExpectationQuadDeviation.hpp:126
ROL::RandVarFunctional::weight_
Real weight_
Definition: ROL_RandVarFunctional.hpp:97
ROL::RandVarFunctional::computeGradient
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Definition: ROL_RandVarFunctional.hpp:118
ROL_ExpectationQuad.hpp
ROL::RandVarFunctional
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
Definition: ROL_RandVarFunctional.hpp:79
ROL::ExpectationQuadDeviation::eq_
Ptr< ExpectationQuad< Real > > eq_
Definition: ROL_ExpectationQuadDeviation.hpp:91
ROL::Objective
Provides the interface to evaluate objective functions.
Definition: ROL_Objective.hpp:77
ROL::SampleGenerator::sumAll
void sumAll(Real *input, Real *output, int dim) const
Definition: ROL_SampleGenerator.hpp:125
ROL::RandVarFunctional::computeGradVec
Real computeGradVec(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Definition: ROL_RandVarFunctional.hpp:134