ROL
ROL_SmoothedWorstCaseQuadrangle.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_SMOOTHEDWORSTCASEQUAD_HPP
45 #define ROL_SMOOTHEDWORSTCASEQUAD_HPP
46 
47 #include "ROL_ExpectationQuad.hpp"
48 
86 namespace ROL {
87 
88 template<class Real>
90 private:
91 
92  Real eps_;
93 
94  void parseParameterList(ROL::ParameterList &parlist) {
95  std::string type = parlist.sublist("SOL").get("Stochastic Component Type","Risk Averse");
96  ROL::ParameterList list;
97  if (type == "Risk Averse") {
98  list = parlist.sublist("SOL").sublist("Risk Measure").sublist("Smoothed Worst Case");
99  }
100  else if (type == "Error") {
101  list = parlist.sublist("SOL").sublist("Error Measure").sublist("Smoothed Worst Case");
102  }
103  else if (type == "Deviation") {
104  list = parlist.sublist("SOL").sublist("Deviation Measure").sublist("Smoothed Upper Range");
105  }
106  else if (type == "Regret") {
107  list = parlist.sublist("SOL").sublist("Regret Measure").sublist("Smoothed Worst Case");
108  }
109  eps_ = list.get<Real>("Smoothing Parameter");
110  }
111 
112  void checkInputs(void) const {
113  Real zero(0);
114  ROL_TEST_FOR_EXCEPTION((eps_ <= zero), std::invalid_argument,
115  ">>> ERROR (ROL::SmoothedWorstCaseQuadrangle): Smoothing parameter must be positive!");
116  }
117 
118 public:
124  : ExpectationQuad<Real>(), eps_(eps) {
125  checkInputs();
126  }
127 
136  SmoothedWorstCaseQuadrangle(ROL::ParameterList &parlist) : ExpectationQuad<Real>() {
137  parseParameterList(parlist);
138  checkInputs();
139  }
140 
141  Real error(Real x, int deriv = 0) {
142  Real err(0), zero(0), half(0.5), one(1);
143  if (deriv == 0) {
144  err = (x <= -eps_) ? -(x+half*eps_) : half*x*x/eps_;
145  }
146  else if (deriv == 1) {
147  err = (x <= -eps_) ? -one : x/eps_;
148  }
149  else {
150  err = (x <= -eps_) ? zero : one/eps_;
151  }
152  return err;
153  }
154 
155  Real regret(Real x, int deriv = 0) {
156  Real zero(0), one(1);
157  Real X = ((deriv==0) ? x : ((deriv==1) ? one : zero));
158  Real reg = error(x,deriv) + X;
159  return reg;
160  }
161 
162  void check(void) {
164  // Check v'(-eps)
165  Real x = -eps_, zero(0), one(1), two(2), p1(0.1);
166  Real vx = zero, vy = zero;
167  Real dv = regret(x,1);
168  Real t = one;
169  Real diff = zero;
170  Real err = zero;
171  std::cout << std::right << std::setw(20) << "CHECK REGRET: v'(-eps) is correct? \n";
172  std::cout << std::right << std::setw(20) << "t"
173  << std::setw(20) << "v'(x)"
174  << std::setw(20) << "(v(x+t)-v(x-t))/2t"
175  << std::setw(20) << "Error"
176  << "\n";
177  for (int i = 0; i < 13; i++) {
178  vy = regret(x+t,0);
179  vx = regret(x-t,0);
180  diff = (vy-vx)/(two*t);
181  err = std::abs(diff-dv);
182  std::cout << std::scientific << std::setprecision(11) << std::right
183  << std::setw(20) << t
184  << std::setw(20) << dv
185  << std::setw(20) << diff
186  << std::setw(20) << err
187  << "\n";
188  t *= p1;
189  }
190  std::cout << "\n";
191  // check v''(-eps)
192  vx = zero;
193  vy = zero;
194  dv = regret(x,2);
195  t = one;
196  diff = zero;
197  err = zero;
198  std::cout << std::right << std::setw(20) << "CHECK REGRET: v''(-eps) is correct? \n";
199  std::cout << std::right << std::setw(20) << "t"
200  << std::setw(20) << "v''(x)"
201  << std::setw(20) << "(v'(x+t)-v'(x-t))/2t"
202  << std::setw(20) << "Error"
203  << "\n";
204  for (int i = 0; i < 13; i++) {
205  vy = regret(x+t,1);
206  vx = regret(x-t,1);
207  diff = (vy-vx)/(two*t);
208  err = std::abs(diff-dv);
209  std::cout << std::scientific << std::setprecision(11) << std::right
210  << std::setw(20) << t
211  << std::setw(20) << dv
212  << std::setw(20) << diff
213  << std::setw(20) << err
214  << "\n";
215  t *= p1;
216  }
217  std::cout << "\n";
218  // Check v'(0)
219  x = zero;
220  vx = zero;
221  vy = zero;
222  dv = regret(x,1);
223  t = one;
224  diff = zero;
225  err = zero;
226  std::cout << std::right << std::setw(20) << "CHECK REGRET: v'(0) is correct? \n";
227  std::cout << std::right << std::setw(20) << "t"
228  << std::setw(20) << "v'(x)"
229  << std::setw(20) << "(v(x+t)-v(x-t))/2t"
230  << std::setw(20) << "Error"
231  << "\n";
232  for (int i = 0; i < 13; i++) {
233  vy = regret(x+t,0);
234  vx = regret(x-t,0);
235  diff = (vy-vx)/(two*t);
236  err = std::abs(diff-dv);
237  std::cout << std::scientific << std::setprecision(11) << std::right
238  << std::setw(20) << t
239  << std::setw(20) << dv
240  << std::setw(20) << diff
241  << std::setw(20) << err
242  << "\n";
243  t *= p1;
244  }
245  std::cout << "\n";
246  // check v''(0)
247  vx = zero;
248  vy = zero;
249  dv = regret(x,2);
250  t = one;
251  diff = zero;
252  err = zero;
253  std::cout << std::right << std::setw(20) << "CHECK REGRET: v''(0) is correct? \n";
254  std::cout << std::right << std::setw(20) << "t"
255  << std::setw(20) << "v''(x)"
256  << std::setw(20) << "(v'(x+t)-v'(x-t))/2t"
257  << std::setw(20) << "Error"
258  << "\n";
259  for (int i = 0; i < 13; i++) {
260  vy = regret(x+t,1);
261  vx = regret(x-t,1);
262  diff = (vy-vx)/(two*t);
263  err = std::abs(diff-dv);
264  std::cout << std::scientific << std::setprecision(11) << std::right
265  << std::setw(20) << t
266  << std::setw(20) << dv
267  << std::setw(20) << diff
268  << std::setw(20) << err
269  << "\n";
270  t *= p1;
271  }
272  std::cout << "\n";
273  // Check v'(-1-eps)
274  x = -eps_-one;
275  vx = zero;
276  vy = zero;
277  dv = regret(x,1);
278  t = one;
279  diff = zero;
280  err = zero;
281  std::cout << std::right << std::setw(20) << "CHECK REGRET: v'(-1-eps) is correct? \n";
282  std::cout << std::right << std::setw(20) << "t"
283  << std::setw(20) << "v'(x)"
284  << std::setw(20) << "(v(x+t)-v(x-t))/2t"
285  << std::setw(20) << "Error"
286  << "\n";
287  for (int i = 0; i < 13; i++) {
288  vy = regret(x+t,0);
289  vx = regret(x-t,0);
290  diff = (vy-vx)/(two*t);
291  err = std::abs(diff-dv);
292  std::cout << std::scientific << std::setprecision(11) << std::right
293  << std::setw(20) << t
294  << std::setw(20) << dv
295  << std::setw(20) << diff
296  << std::setw(20) << err
297  << "\n";
298  t *= p1;
299  }
300  std::cout << "\n";
301  // check v''(-1-eps)
302  vx = zero;
303  vy = zero;
304  dv = regret(x,2);
305  t = one;
306  diff = zero;
307  err = zero;
308  std::cout << std::right << std::setw(20) << "CHECK REGRET: v''(-1-eps) is correct? \n";
309  std::cout << std::right << std::setw(20) << "t"
310  << std::setw(20) << "v''(x)"
311  << std::setw(20) << "(v'(x+t)-v'(x-t))/2t"
312  << std::setw(20) << "Error"
313  << "\n";
314  for (int i = 0; i < 13; i++) {
315  vy = regret(x+t,1);
316  vx = regret(x-t,1);
317  diff = (vy-vx)/(two*t);
318  err = std::abs(diff-dv);
319  std::cout << std::scientific << std::setprecision(11) << std::right
320  << std::setw(20) << t
321  << std::setw(20) << dv
322  << std::setw(20) << diff
323  << std::setw(20) << err
324  << "\n";
325  t *= p1;
326  }
327  std::cout << "\n";
328  }
329 
330 };
331 
332 }
333 #endif
Provides an interface for a smoothed version of the worst-case scenario risk measure using the expect...
Provides a general interface for risk and error measures generated through the expectation risk quadr...
virtual void check(void)
Run default derivative tests for the scalar regret function.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
SmoothedWorstCaseQuadrangle(ROL::ParameterList &parlist)
Constructor.
Real regret(Real x, int deriv=0)
Evaluate the scalar regret function at x.
SmoothedWorstCaseQuadrangle(const Real eps)
Constructor.
Real error(Real x, int deriv=0)
Evaluate the scalar error function at x.
void check(void)
Run default derivative tests for the scalar regret function.
void parseParameterList(ROL::ParameterList &parlist)