ROL
ROL_MeanVarianceQuadrangle.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_MEANVARIANCEQUAD_HPP
11 #define ROL_MEANVARIANCEQUAD_HPP
12 
13 #include "ROL_ExpectationQuad.hpp"
14 
41 namespace ROL {
42 
43 template<class Real>
45 private:
46  Real coeff_;
47 
48  void parseParameterList(ROL::ParameterList &parlist) {
49  std::string type = parlist.sublist("SOL").get("Type","Risk Averse");
50  ROL::ParameterList list;
51  if (type == "Risk Averse") {
52  list = parlist.sublist("SOL").sublist("Risk Measure").sublist("Safety Margin");
53  }
54  else if (type == "Regret") {
55  list = parlist.sublist("SOL").sublist("Regret Measure").sublist("Mean L2");
56  }
57  else if (type == "Error" || type == "Deviation") {
58  coeff_ = static_cast<Real>(1);
59  return;
60  }
61  coeff_ = list.get<Real>("Coefficient");
62  }
63 
64  void checkInputs(void) const {
65  Real zero(0);
66  ROL_TEST_FOR_EXCEPTION((coeff_ <= zero), std::invalid_argument,
67  ">>> ERROR (ROL::MeanVarianceQuadrangle): Coefficient must be positive!");
68  }
69 
70 public:
75  MeanVarianceQuadrangle(const Real coeff = 1)
76  : ExpectationQuad<Real>(), coeff_(coeff) {
77  checkInputs();
78  }
79 
88  MeanVarianceQuadrangle(ROL::ParameterList &parlist)
89  : ExpectationQuad<Real>() {
90  parseParameterList(parlist);
91  checkInputs();
92  }
93 
94  Real error(Real x, int deriv = 0) {
95  Real err(0), two(2);
96  if (deriv==0) {
97  err = coeff_*x*x;
98  }
99  else if (deriv==1) {
100  err = two*coeff_*x;
101  }
102  else {
103  err = two*coeff_;
104  }
105  return err;
106  }
107 
108  Real regret(Real x, int deriv = 0) {
109  Real zero(0), one(1);
110  Real X = ((deriv==0) ? x : ((deriv==1) ? one : zero));
111  Real reg = error(x,deriv) + X;
112  return reg;
113  }
114 
115 };
116 
117 }
118 #endif
Real regret(Real x, int deriv=0)
Evaluate the scalar regret function at x.
Provides a general interface for risk and error measures generated through the expectation risk quadr...
MeanVarianceQuadrangle(ROL::ParameterList &parlist)
Constructor.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
MeanVarianceQuadrangle(const Real coeff=1)
Constructor.
Provides an interface for the mean plus variance risk measure using the expectation risk quadrangle...
void parseParameterList(ROL::ParameterList &parlist)
Real error(Real x, int deriv=0)
Evaluate the scalar error function at x.