10 #ifndef ROL_LOGQUANTILEQUAD_HPP
11 #define ROL_LOGQUANTILEQUAD_HPP
45 ROL::Ptr<PlusFunction<Real> >
pf_;
52 std::string type = parlist.sublist(
"SOL").get(
"Type",
"Risk Averse");
53 ROL::ParameterList list;
54 if (type ==
"Risk Averse") {
55 list = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Log Quantile");
57 else if (type ==
"Error") {
58 list = parlist.sublist(
"SOL").sublist(
"Error Measure").sublist(
"Log Quantile");
60 else if (type ==
"Deviation") {
61 list = parlist.sublist(
"SOL").sublist(
"Deviation Measure").sublist(
"Log Quantile");
63 else if (type ==
"Regret") {
64 list = parlist.sublist(
"SOL").sublist(
"Regret Measure").sublist(
"Log Quantile");
67 alpha_ = list.get<Real>(
"Slope for Linear Growth");
68 rate_ = list.get<Real>(
"Rate for Exponential Growth");
69 eps_ = list.get<Real>(
"Smoothing Parameter");
71 pf_ = ROL::makePtr<PlusFunction<Real>>(list);
76 ROL_TEST_FOR_EXCEPTION((
alpha_ <
zero) || (
alpha_ >= one), std::invalid_argument,
77 ">>> ERROR (ROL::LogQuantileQuadrangle): Linear growth rate must be between 0 and 1!");
78 ROL_TEST_FOR_EXCEPTION((
rate_ <=
zero), std::invalid_argument,
79 ">>> ERROR (ROL::LogQuantileQuadrangle): Exponential growth rate must be positive!");
80 ROL_TEST_FOR_EXCEPTION((
eps_ <=
zero), std::invalid_argument,
81 ">>> ERROR (ROL::LogQuantileQuadrangle): Smoothing parameter must be positive!");
82 ROL_TEST_FOR_EXCEPTION(
pf_ == ROL::nullPtr, std::invalid_argument,
83 ">>> ERROR (ROL::LogQuantileQuadrangle): PlusFunction pointer is null!");
118 Real
zero(0), one(1);
119 ROL_TEST_FOR_EXCEPTION( (deriv > 2), std::invalid_argument,
120 ">>> ERROR (ROL::LogQuantileQuadrangle::error): deriv greater than 2!");
121 ROL_TEST_FOR_EXCEPTION( (deriv < 0), std::invalid_argument,
122 ">>> ERROR (ROL::LogQuantileQuadrangle::error): deriv less than 0!");
124 Real X = ((deriv == 0) ? x : ((deriv == 1) ? one :
zero));
125 return regret(x,deriv) - X;
129 Real
zero(0), one(1);
130 ROL_TEST_FOR_EXCEPTION( (deriv > 2), std::invalid_argument,
131 ">>> ERROR (ROL::LogQuantileQuadrangle::regret): deriv greater than 2!");
132 ROL_TEST_FOR_EXCEPTION( (deriv < 0), std::invalid_argument,
133 ">>> ERROR (ROL::LogQuantileQuadrangle::regret): deriv less than 0!");
135 Real arg = std::exp(
rate_*x);
136 Real sarg =
rate_*arg;
137 Real reg = (
pf_->evaluate(arg-one,deriv) *
138 ((deriv == 0) ? one/
rate_ : ((deriv == 1) ? arg : sarg*arg))
139 + ((deriv == 2) ?
pf_->evaluate(arg-one,deriv-1)*sarg :
zero))
140 + ((deriv%2 == 0) ? -one : one) *
alpha_ *
pf_->evaluate(-x,deriv);
147 Real x =
eps_, two(2), p1(0.1),
zero(0), one(1);
150 Real t(1), diff(0), err(0);
151 std::cout << std::right << std::setw(20) <<
"CHECK REGRET: v'(eps) is correct? \n";
152 std::cout << std::right << std::setw(20) <<
"t"
153 << std::setw(20) <<
"v'(x)"
154 << std::setw(20) <<
"(v(x+t)-v(x-t))/2t"
155 << std::setw(20) <<
"Error"
157 for (
int i = 0; i < 13; i++) {
160 diff = (vy-vx)/(two*t);
161 err = std::abs(diff-dv);
162 std::cout << std::scientific << std::setprecision(11) << std::right
163 << std::setw(20) << t
164 << std::setw(20) << dv
165 << std::setw(20) << diff
166 << std::setw(20) << err
178 std::cout << std::right << std::setw(20) <<
"CHECK REGRET: v''(eps) is correct? \n";
179 std::cout << std::right << std::setw(20) <<
"t"
180 << std::setw(20) <<
"v''(x)"
181 << std::setw(20) <<
"(v'(x+t)-v'(x-t))/2t"
182 << std::setw(20) <<
"Error"
184 for (
int i = 0; i < 13; i++) {
187 diff = (vy-vx)/(two*t);
188 err = std::abs(diff-dv);
189 std::cout << std::scientific << std::setprecision(11) << std::right
190 << std::setw(20) << t
191 << std::setw(20) << dv
192 << std::setw(20) << diff
193 << std::setw(20) << err
206 std::cout << std::right << std::setw(20) <<
"CHECK REGRET: v'(0) is correct? \n";
207 std::cout << std::right << std::setw(20) <<
"t"
208 << std::setw(20) <<
"v'(x)"
209 << std::setw(20) <<
"(v(x+t)-v(x-t))/2t"
210 << std::setw(20) <<
"Error"
212 for (
int i = 0; i < 13; i++) {
215 diff = (vy-vx)/(two*t);
216 err = std::abs(diff-dv);
217 std::cout << std::scientific << std::setprecision(11) << std::right
218 << std::setw(20) << t
219 << std::setw(20) << dv
220 << std::setw(20) << diff
221 << std::setw(20) << err
233 std::cout << std::right << std::setw(20) <<
"CHECK REGRET: v''(0) is correct? \n";
234 std::cout << std::right << std::setw(20) <<
"t"
235 << std::setw(20) <<
"v''(x)"
236 << std::setw(20) <<
"(v'(x+t)-v'(x-t))/2t"
237 << std::setw(20) <<
"Error"
239 for (
int i = 0; i < 13; i++) {
242 diff = (vy-vx)/(two*t);
243 err = std::abs(diff-dv);
244 std::cout << std::scientific << std::setprecision(11) << std::right
245 << std::setw(20) << t
246 << std::setw(20) << dv
247 << std::setw(20) << diff
248 << std::setw(20) << err
261 std::cout << std::right << std::setw(20) <<
"CHECK REGRET: v'(-eps) is correct? \n";
262 std::cout << std::right << std::setw(20) <<
"t"
263 << std::setw(20) <<
"v'(x)"
264 << std::setw(20) <<
"(v(x+t)-v(x-t))/2t"
265 << std::setw(20) <<
"Error"
267 for (
int i = 0; i < 13; i++) {
270 diff = (vy-vx)/(two*t);
271 err = std::abs(diff-dv);
272 std::cout << std::scientific << std::setprecision(11) << std::right
273 << std::setw(20) << t
274 << std::setw(20) << dv
275 << std::setw(20) << diff
276 << std::setw(20) << err
288 std::cout << std::right << std::setw(20) <<
"CHECK REGRET: v''(-eps) is correct? \n";
289 std::cout << std::right << std::setw(20) <<
"t"
290 << std::setw(20) <<
"v''(x)"
291 << std::setw(20) <<
"(v'(x+t)-v'(x-t))/2t"
292 << std::setw(20) <<
"Error"
294 for (
int i = 0; i < 13; i++) {
297 diff = (vy-vx)/(two*t);
298 err = std::abs(diff-dv);
299 std::cout << std::scientific << std::setprecision(11) << std::right
300 << std::setw(20) << t
301 << std::setw(20) << dv
302 << std::setw(20) << diff
303 << std::setw(20) << err
Real error(Real x, int deriv=0)
Evaluate the scalar error function at x.
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()
Provides an interface for the conditioanl entropic risk using the expectation risk quadrangle...
LogQuantileQuadrangle(ROL::ParameterList &parlist)
Constructor.
void parseParameterList(ROL::ParameterList &parlist)
ROL::Ptr< PlusFunction< Real > > pf_
void check(void)
Run default derivative tests for the scalar regret function.
Real regret(Real x, int deriv=0)
Evaluate the scalar regret function at x.
LogQuantileQuadrangle(Real alpha, Real rate, Real eps, ROL::Ptr< PlusFunction< Real > > &pf)
Constructor.
void checkInputs(void) const