ROL
ROL_SmoothedPOE.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_SMOOTHEDPOE_HPP
11#define ROL_SMOOTHEDPOE_HPP
12
14
29namespace ROL {
30
31template<class Real>
32class SmoothedPOE : public RandVarFunctional<Real> {
33private:
35 Real eps_;
36
37 using RandVarFunctional<Real>::val_;
38 using RandVarFunctional<Real>::gv_;
39 using RandVarFunctional<Real>::g_;
40 using RandVarFunctional<Real>::hv_;
42
43 using RandVarFunctional<Real>::point_;
45
50
51 Real smoothHeaviside(const Real x, const int deriv = 0) const {
52 const Real one(1), two(2);
53 Real val(0);
54 if (deriv == 0) {
55 Real ex = std::exp(-two*x/eps_);
56 val = one/(one+ex);
57 }
58 else if (deriv == 1) {
59 Real ex = std::exp(-two*x/eps_);
60 val = (two/eps_)*ex/std::pow(one+ex,2);
61 }
62 else if (deriv == 2) {
63 Real ex = std::exp(two*x/eps_);
64 val = std::pow(two/eps_,2)*ex*(one-ex)/std::pow(one+ex,3);
65 }
66 return val;
67 }
68
69public:
70 SmoothedPOE(const Real threshold, const Real eps)
71 : RandVarFunctional<Real>(),
72 threshold_(threshold), eps_(eps) {}
73
74 SmoothedPOE(ROL::ParameterList &parlist)
75 : RandVarFunctional<Real>() {
76 ROL::ParameterList &list = parlist.sublist("SOL").sublist("Probability").sublist("Smoothed POE");
77 threshold_ = list.get<Real>("Threshold");
78 eps_ = list.get<Real>("Smoothing Parameter");
79 }
80
82 const Vector<Real> &x,
83 const std::vector<Real> &xstat,
84 Real &tol) {
85 Real val = computeValue(obj,x,tol);
86 Real sp = smoothHeaviside(val-threshold_,0);
87 if ( std::abs(sp) > ROL_EPSILON<Real>() ) {
88 val_ += weight_*sp;
89 }
90 }
91
92 Real getValue(const Vector<Real> &x,
93 const std::vector<Real> &xstat,
94 SampleGenerator<Real> &sampler) {
95 Real spoe(0);
96 sampler.sumAll(&val_,&spoe,1);
97 return spoe;
98 }
99
101 const Vector<Real> &x,
102 const std::vector<Real> &xstat,
103 Real &tol) {
104 Real val = computeValue(obj,x,tol);
105 Real sp = smoothHeaviside(val-threshold_,1);
106 if ( std::abs(sp) > ROL_EPSILON<Real>() ) {
107 computeGradient(*dualVector_,obj,x,tol);
108 g_->axpy(weight_*sp,*dualVector_);
109 }
110 }
111
113 std::vector<Real> &gstat,
114 const Vector<Real> &x,
115 const std::vector<Real> &xstat,
116 SampleGenerator<Real> &sampler) {
117 sampler.sumAll(*g_,g);
118 }
119
121 const Vector<Real> &v,
122 const std::vector<Real> &vstat,
123 const Vector<Real> &x,
124 const std::vector<Real> &xstat,
125 Real &tol) {
126 Real val = computeValue(obj,x,tol);
127 Real sp1 = smoothHeaviside(val-threshold_,1);
128 Real sp2 = smoothHeaviside(val-threshold_,2);
129 if ( std::abs(sp1) > ROL_EPSILON<Real>() ) {
130 // Hessian only
131 computeHessVec(*dualVector_,obj,v,x,tol);
132 hv_->axpy(weight_*sp1,*dualVector_);
133 }
134 if ( std::abs(sp2) > ROL_EPSILON<Real>() ) {
135 // Gradient only
136 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
137 hv_->axpy(weight_*sp2*gv,*dualVector_);
138 }
139 }
140
142 std::vector<Real> &hvstat,
143 const Vector<Real> &v,
144 const std::vector<Real> &vstat,
145 const Vector<Real> &x,
146 const std::vector<Real> &xstat,
147 SampleGenerator<Real> &sampler) {
148 sampler.sumAll(*hv_,hv);
149 }
150};
151
152}
153
154#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)
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
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.