ROL
ROL_SmoothedPOE.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_SMOOTHEDPOE_HPP
45#define ROL_SMOOTHEDPOE_HPP
46
48
63namespace ROL {
64
65template<class Real>
66class SmoothedPOE : public RandVarFunctional<Real> {
67private:
69 Real eps_;
70
71 using RandVarFunctional<Real>::val_;
72 using RandVarFunctional<Real>::gv_;
73 using RandVarFunctional<Real>::g_;
74 using RandVarFunctional<Real>::hv_;
76
77 using RandVarFunctional<Real>::point_;
79
84
85 Real smoothHeaviside(const Real x, const int deriv = 0) const {
86 const Real one(1), two(2);
87 Real val(0);
88 if (deriv == 0) {
89 Real ex = std::exp(-two*x/eps_);
90 val = one/(one+ex);
91 }
92 else if (deriv == 1) {
93 Real ex = std::exp(-two*x/eps_);
94 val = (two/eps_)*ex/std::pow(one+ex,2);
95 }
96 else if (deriv == 2) {
97 Real ex = std::exp(two*x/eps_);
98 val = std::pow(two/eps_,2)*ex*(one-ex)/std::pow(one+ex,3);
99 }
100 return val;
101 }
102
103public:
104 SmoothedPOE(const Real threshold, const Real eps)
105 : RandVarFunctional<Real>(),
106 threshold_(threshold), eps_(eps) {}
107
108 SmoothedPOE(ROL::ParameterList &parlist)
109 : RandVarFunctional<Real>() {
110 ROL::ParameterList &list = parlist.sublist("SOL").sublist("Probability").sublist("Smoothed POE");
111 threshold_ = list.get<Real>("Threshold");
112 eps_ = list.get<Real>("Smoothing Parameter");
113 }
114
116 const Vector<Real> &x,
117 const std::vector<Real> &xstat,
118 Real &tol) {
119 Real val = computeValue(obj,x,tol);
120 Real sp = smoothHeaviside(val-threshold_,0);
121 if ( std::abs(sp) > ROL_EPSILON<Real>() ) {
122 val_ += weight_*sp;
123 }
124 }
125
126 Real getValue(const Vector<Real> &x,
127 const std::vector<Real> &xstat,
128 SampleGenerator<Real> &sampler) {
129 Real spoe(0);
130 sampler.sumAll(&val_,&spoe,1);
131 return spoe;
132 }
133
135 const Vector<Real> &x,
136 const std::vector<Real> &xstat,
137 Real &tol) {
138 Real val = computeValue(obj,x,tol);
139 Real sp = smoothHeaviside(val-threshold_,1);
140 if ( std::abs(sp) > ROL_EPSILON<Real>() ) {
141 computeGradient(*dualVector_,obj,x,tol);
142 g_->axpy(weight_*sp,*dualVector_);
143 }
144 }
145
147 std::vector<Real> &gstat,
148 const Vector<Real> &x,
149 const std::vector<Real> &xstat,
150 SampleGenerator<Real> &sampler) {
151 sampler.sumAll(*g_,g);
152 }
153
155 const Vector<Real> &v,
156 const std::vector<Real> &vstat,
157 const Vector<Real> &x,
158 const std::vector<Real> &xstat,
159 Real &tol) {
160 Real val = computeValue(obj,x,tol);
161 Real sp1 = smoothHeaviside(val-threshold_,1);
162 Real sp2 = smoothHeaviside(val-threshold_,2);
163 if ( std::abs(sp1) > ROL_EPSILON<Real>() ) {
164 // Hessian only
165 computeHessVec(*dualVector_,obj,v,x,tol);
166 hv_->axpy(weight_*sp1,*dualVector_);
167 }
168 if ( std::abs(sp2) > ROL_EPSILON<Real>() ) {
169 // Gradient only
170 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
171 hv_->axpy(weight_*sp2*gv,*dualVector_);
172 }
173 }
174
176 std::vector<Real> &hvstat,
177 const Vector<Real> &v,
178 const std::vector<Real> &vstat,
179 const Vector<Real> &x,
180 const std::vector<Real> &xstat,
181 SampleGenerator<Real> &sampler) {
182 sampler.sumAll(*hv_,hv);
183 }
184};
185
186}
187
188#endif
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
Provides the implementation of the smoothed probability of exceedance.
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
SmoothedPOE(const Real threshold, const Real eps)
SmoothedPOE(ROL::ParameterList &parlist)
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value 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 smoothHeaviside(const Real x, const int deriv=0) const
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.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84