ROL
ROL_MoreauYosidaCVaR.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_MOREAUYOSIDACVAR_HPP
45 #define ROL_MOREAUYOSIDACVAR_HPP
46 
47 #include "ROL_ExpectationQuad.hpp"
48 
102 namespace ROL {
103 
104 template<class Real>
105 class MoreauYosidaCVaR : public ExpectationQuad<Real> {
106 private:
107 
108  Real prob_;
109  Real eps_;
110 
111  Real omp_;
112  Real ub_;
113 
114  void parseParameterList(ROL::ParameterList &parlist) {
115  std::string type = parlist.sublist("SOL").get("Stochastic Component Type","Risk Averse");
116  ROL::ParameterList list;
117  if (type == "Risk Averse") {
118  list = parlist.sublist("SOL").sublist("Risk Measure").sublist("Moreau-Yosida CVaR");
119  }
120  else if (type == "Error") {
121  list = parlist.sublist("SOL").sublist("Error Measure").sublist("Moreau-Yosida-Koenker-Bassett");
122  }
123  else if (type == "Deviation") {
124  list = parlist.sublist("SOL").sublist("Deviation Measure").sublist("Moreau-Yosida CVaR");
125  }
126  else if (type == "Regret") {
127  list = parlist.sublist("SOL").sublist("Regret Measure").sublist("Moreau-Yosida Mean Absolute Loss");
128  }
129  prob_ = list.get<Real>("Confidence Level");
130  eps_ = list.get<Real>("Smoothing Parameter");
131  }
132 
133  void checkInputs(void) const {
134  Real zero(0), one(1);
135  ROL_TEST_FOR_EXCEPTION((prob_ <= zero) || (prob_ >= one), std::invalid_argument,
136  ">>> ERROR (ROL::MoreauYosidaCVaR): Confidence level must be between 0 and 1!");
137  ROL_TEST_FOR_EXCEPTION((eps_ <= zero), std::invalid_argument,
138  ">>> ERROR (ROL::MoreauYosidaCVaR): Smoothing parameter must be positive!");
139  }
140 
141  void setParameters(void) {
142  Real one(1);
143  omp_ = one-prob_;
144  ub_ = eps_/omp_;
145  }
146 
147 public:
153  MoreauYosidaCVaR(Real prob, Real eps )
154  : ExpectationQuad<Real>(), prob_(prob), eps_(eps) {
155  checkInputs();
156  setParameters();
157  }
158 
168  MoreauYosidaCVaR(ROL::ParameterList &parlist)
169  : ExpectationQuad<Real>() {
170  parseParameterList(parlist);
171  checkInputs();
172  setParameters();
173  }
174 
175  Real error(Real x, int deriv = 0) {
176  Real zero(0), one(1);
177  Real X = ((deriv==0) ? x : ((deriv==1) ? one : zero));
178  return regret(x,deriv) - X;
179  }
180 
181  Real regret(Real x, int deriv = 0) {
182  Real zero(0), half(0.5), one(1), reg(0);
183  if ( x <= zero ) {
184  reg = 0;
185  }
186  else if ( x >= ub_ ) {
187  reg = ((deriv == 0) ? (x-half*ub_)/omp_
188  : ((deriv == 1) ? one/omp_ : zero));
189  }
190  else {
191  reg = ((deriv == 0) ? half/eps_*x*x
192  : ((deriv == 1) ? x/eps_ : one/eps_));
193  }
194  return reg;
195  }
196 
197  void check(void) {
199  Real zero(0), one(1), two(2), p1(0.1);
200  // Check v'(eps)
201  Real x = eps_;
202  Real vx = zero, vy = zero;
203  Real dv = regret(x,1);
204  Real t = one;
205  Real diff = zero;
206  Real err = zero;
207  std::cout << std::right << std::setw(20) << "CHECK REGRET: v'(eps) is correct? \n";
208  std::cout << std::right << std::setw(20) << "t"
209  << std::setw(20) << "v'(x)"
210  << std::setw(20) << "(v(x+t)-v(x-t))/2t"
211  << std::setw(20) << "Error"
212  << "\n";
213  for (int i = 0; i < 13; i++) {
214  vy = regret(x+t,0);
215  vx = regret(x-t,0);
216  diff = (vy-vx)/(two*t);
217  err = std::abs(diff-dv);
218  std::cout << std::scientific << std::setprecision(11) << std::right
219  << std::setw(20) << t
220  << std::setw(20) << dv
221  << std::setw(20) << diff
222  << std::setw(20) << err
223  << "\n";
224  t *= p1;
225  }
226  std::cout << "\n";
227  // check v''(eps)
228  vx = zero;
229  vy = zero;
230  dv = regret(x,2);
231  t = one;
232  diff = zero;
233  err = zero;
234  std::cout << std::right << std::setw(20) << "CHECK REGRET: v''(eps) is correct? \n";
235  std::cout << std::right << std::setw(20) << "t"
236  << std::setw(20) << "v''(x)"
237  << std::setw(20) << "(v'(x+t)-v'(x-t))/2t"
238  << std::setw(20) << "Error"
239  << "\n";
240  for (int i = 0; i < 13; i++) {
241  vy = regret(x+t,1);
242  vx = regret(x-t,1);
243  diff = (vy-vx)/(two*t);
244  err = std::abs(diff-dv);
245  std::cout << std::scientific << std::setprecision(11) << std::right
246  << std::setw(20) << t
247  << std::setw(20) << dv
248  << std::setw(20) << diff
249  << std::setw(20) << err
250  << "\n";
251  t *= p1;
252  }
253  std::cout << "\n";
254  // Check v'(0)
255  x = zero;
256  vx = zero;
257  vy = zero;
258  dv = regret(x,1);
259  t = one;
260  diff = zero;
261  err = zero;
262  std::cout << std::right << std::setw(20) << "CHECK REGRET: v'(0) is correct? \n";
263  std::cout << std::right << std::setw(20) << "t"
264  << std::setw(20) << "v'(x)"
265  << std::setw(20) << "(v(x+t)-v(x-t))/2t"
266  << std::setw(20) << "Error"
267  << "\n";
268  for (int i = 0; i < 13; i++) {
269  vy = regret(x+t,0);
270  vx = regret(x-t,0);
271  diff = (vy-vx)/(two*t);
272  err = std::abs(diff-dv);
273  std::cout << std::scientific << std::setprecision(11) << std::right
274  << std::setw(20) << t
275  << std::setw(20) << dv
276  << std::setw(20) << diff
277  << std::setw(20) << err
278  << "\n";
279  t *= p1;
280  }
281  std::cout << "\n";
282  // check v''(eps)
283  vx = zero;
284  vy = zero;
285  dv = regret(x,2);
286  t = one;
287  diff = zero;
288  err = zero;
289  std::cout << std::right << std::setw(20) << "CHECK REGRET: v''(0) is correct? \n";
290  std::cout << std::right << std::setw(20) << "t"
291  << std::setw(20) << "v''(x)"
292  << std::setw(20) << "(v'(x+t)-v'(x-t))/2t"
293  << std::setw(20) << "Error"
294  << "\n";
295  for (int i = 0; i < 13; i++) {
296  vy = regret(x+t,1);
297  vx = regret(x-t,1);
298  diff = (vy-vx)/(two*t);
299  err = std::abs(diff-dv);
300  std::cout << std::scientific << std::setprecision(11) << std::right
301  << std::setw(20) << t
302  << std::setw(20) << dv
303  << std::setw(20) << diff
304  << std::setw(20) << err
305  << "\n";
306  t *= p1;
307  }
308  std::cout << "\n";
309  // Check v'(0)
310  x = -eps_;
311  vx = zero;
312  vy = zero;
313  dv = regret(x,1);
314  t = one;
315  diff = zero;
316  err = zero;
317  std::cout << std::right << std::setw(20) << "CHECK REGRET: v'(-eps) is correct? \n";
318  std::cout << std::right << std::setw(20) << "t"
319  << std::setw(20) << "v'(x)"
320  << std::setw(20) << "(v(x+t)-v(x-t))/2t"
321  << std::setw(20) << "Error"
322  << "\n";
323  for (int i = 0; i < 13; i++) {
324  vy = regret(x+t,0);
325  vx = regret(x-t,0);
326  diff = (vy-vx)/(two*t);
327  err = std::abs(diff-dv);
328  std::cout << std::scientific << std::setprecision(11) << std::right
329  << std::setw(20) << t
330  << std::setw(20) << dv
331  << std::setw(20) << diff
332  << std::setw(20) << err
333  << "\n";
334  t *= p1;
335  }
336  std::cout << "\n";
337  // check v''(eps)
338  vx = zero;
339  vy = zero;
340  dv = regret(x,2);
341  t = one;
342  diff = zero;
343  err = zero;
344  std::cout << std::right << std::setw(20) << "CHECK REGRET: v''(-eps) is correct? \n";
345  std::cout << std::right << std::setw(20) << "t"
346  << std::setw(20) << "v''(x)"
347  << std::setw(20) << "(v'(x+t)-v'(x-t))/2t"
348  << std::setw(20) << "Error"
349  << "\n";
350  for (int i = 0; i < 13; i++) {
351  vy = regret(x+t,1);
352  vx = regret(x-t,1);
353  diff = (vy-vx)/(two*t);
354  err = std::abs(diff-dv);
355  std::cout << std::scientific << std::setprecision(11) << std::right
356  << std::setw(20) << t
357  << std::setw(20) << dv
358  << std::setw(20) << diff
359  << std::setw(20) << err
360  << "\n";
361  t *= p1;
362  }
363  std::cout << "\n";
364  }
365 
366 };
367 
368 }
369 #endif
void check(void)
Run default derivative tests for the scalar regret function.
Provides a general interface for risk and error measures generated through the expectation risk quadr...
Provides an interface for a smooth approximation of the conditional value-at-risk.
virtual void check(void)
Run default derivative tests for the scalar regret function.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
void parseParameterList(ROL::ParameterList &parlist)
MoreauYosidaCVaR(ROL::ParameterList &parlist)
Constructor.
MoreauYosidaCVaR(Real prob, Real eps)
Constructor.
Real error(Real x, int deriv=0)
Evaluate the scalar error function at x.
Real regret(Real x, int deriv=0)
Evaluate the scalar regret function at x.