10 #ifndef ROL_RISKMEASUREINFO_HPP
11 #define ROL_RISKMEASUREINFO_HPP
13 #include "ROL_ParameterList.hpp"
20 int &nStatistic, std::vector<Real> &lower,
21 std::vector<Real> &upper,
bool &isBoundActivated,
22 const bool printToStream =
false,
23 std::ostream &outStream = std::cout) {
24 name = parlist.sublist(
"SOL").sublist(
"Risk Measure").get<std::string>(
"Name");
26 lower.clear(); upper.clear();
27 nStatistic = 0; isBoundActivated =
false;
28 if ( name ==
"CVaR" ||
30 name ==
"Moreau-Yosida CVaR" ||
31 name ==
"Generalized Moreau-Yosida CVaR" ||
32 name ==
"Log Quantile" ||
33 name ==
"Smoothed Worst Case" ||
34 name ==
"Safety Margin" ||
35 name ==
"Log Exponential" ||
36 name ==
"Truncated Mean" ) {
38 lower.resize(nStatistic,ROL_NINF<Real>());
39 upper.resize(nStatistic,ROL_INF<Real>());
41 else if ( name ==
"Quantile Radius" ) {
43 lower.resize(nStatistic,ROL_NINF<Real>());
44 upper.resize(nStatistic,ROL_INF<Real>());
46 else if ( name ==
"Coherent Entropic Risk" ||
47 name ==
"KL Divergence" ) {
49 isBoundActivated =
true;
50 lower.resize(nStatistic,zero);
51 upper.resize(nStatistic,ROL_INF<Real>());
53 else if ( name ==
"Chi-Squared Divergence" ) {
55 isBoundActivated =
true;
56 lower.resize(nStatistic,ROL_NINF<Real>()); lower[0] =
zero;
57 upper.resize(nStatistic,ROL_INF<Real>());
59 else if ( name ==
"Mixed CVaR" ) {
60 ROL::ParameterList &list
61 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mixed CVaR");
62 std::vector<Real> prob
63 = ROL::getArrayFromStringParameter<Real>(list,
"Probability Array");
64 nStatistic = prob.size();
65 lower.resize(nStatistic,ROL_NINF<Real>());
66 upper.resize(nStatistic,ROL_INF<Real>());
68 else if ( name ==
"Second Order CVaR" ||
69 name ==
"Chebyshev Spectral Risk" ||
70 name ==
"Spectral Risk" ) {
71 ROL::ParameterList &list
72 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(name);
73 nStatistic = list.get(
"Number of Quadrature Points",5);
74 lower.resize(nStatistic,ROL_NINF<Real>());
75 upper.resize(nStatistic,ROL_INF<Real>());
77 else if ( name ==
"Entropic Risk" ||
78 name ==
"Mean Plus Semi-Deviation From Target" ||
79 name ==
"Mean Plus Semi-Deviation" ||
80 name ==
"Mean Plus Deviation From Target" ||
81 name ==
"Mean Plus Deviation" ||
82 name ==
"Mean Plus Variance From Target" ||
83 name ==
"Mean Plus Variance" ) {
86 else if ( name ==
"Convex Combination Risk Measure" ) {
87 ROL::ParameterList &list
88 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Convex Combination Risk Measure");
90 std::vector<Real> lambda
91 = ROL::getArrayFromStringParameter<Real>(list,
"Convex Combination Parameters");
93 std::vector<std::string> riskString;
95 std::ostringstream convert;
97 std::string si = convert.str();
98 ROL::ParameterList &ilist = list.sublist(si);
99 std::string namei = ilist.get<std::string>(
"Name");
100 riskString.push_back(namei);
103 if ( riskString[i] ==
"CVaR" ||
104 riskString[i] ==
"HMCR" ||
105 riskString[i] ==
"Moreau-Yosida CVaR" ||
106 riskString[i] ==
"Generalized Moreau-Yosida CVaR" ||
107 riskString[i] ==
"Log Quantile" ||
108 riskString[i] ==
"Smoothed Worst Case" ||
109 riskString[i] ==
"Safety Margin" ||
110 riskString[i] ==
"Log Exponential" ||
111 riskString[i] ==
"Truncated Mean" ) {
113 lower.push_back(ROL_NINF<Real>());
114 upper.push_back(ROL_INF<Real>());
116 else if ( riskString[i] ==
"Quantile Radius" ) {
118 lower.push_back(ROL_NINF<Real>()); lower.push_back(ROL_NINF<Real>());
119 upper.push_back(ROL_INF<Real>()); upper.push_back(ROL_INF<Real>());
121 else if ( riskString[i] ==
"Coherent Entropic Risk" ||
122 riskString[i] ==
"KL Divergence" ) {
124 isBoundActivated =
true;
125 lower.push_back(zero);
126 upper.push_back(ROL_INF<Real>());
128 else if ( riskString[i] ==
"Chi-Squared Divergence" ) {
130 isBoundActivated =
true;
131 lower.push_back(zero); lower.push_back(ROL_NINF<Real>());
132 upper.push_back(ROL_INF<Real>()); upper.push_back(ROL_INF<Real>());
134 else if ( riskString[i] ==
"Mixed CVaR" ) {
135 ROL::ParameterList &MQlist = list.sublist(
"Mixed CVaR");
136 std::vector<Real> prob
137 = ROL::getArrayFromStringParameter<Real>(MQlist,
"Probability Array");
138 nStatistic += prob.size();
140 lower.push_back(ROL_NINF<Real>());
141 upper.push_back(ROL_INF<Real>());
144 else if ( riskString[i] ==
"Second Order CVaR" ||
145 riskString[i] ==
"Chebyshev Spectral Risk" ||
146 riskString[i] ==
"Spectral Risk" ) {
147 ROL::ParameterList &SQlist = list.sublist(riskString[i]);
148 int nSQQstat = SQlist.get(
"Number of Quadrature Points",5);
149 nStatistic += nSQQstat;
150 for (
int j = 0; j < nSQQstat; ++j) {
151 lower.push_back(ROL_NINF<Real>());
152 upper.push_back(ROL_INF<Real>());
155 else if ( riskString[i] ==
"Entropic Risk" ||
156 riskString[i] ==
"Mean Plus Semi-Deviation From Target" ||
157 riskString[i] ==
"Mean Plus Semi-Deviation" ||
158 riskString[i] ==
"Mean Plus Deviation From Target" ||
159 riskString[i] ==
"Mean Plus Deviation" ||
160 riskString[i] ==
"Mean Plus Variance From Target" ||
161 riskString[i] ==
"Mean Plus Variance" ) {
165 ROL_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
166 ">>> (ROL::RiskMeasureInfo): Invalid risk measure " << riskString[i] <<
"!");
171 ROL_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
172 ">>> (ROL::RiskMeasureInfo): Invalid risk measure " << name <<
"!");
176 if ( printToStream ) {
178 oldFormatState.copyfmt(outStream);
180 outStream << std::endl;
181 outStream << std::scientific << std::setprecision(6);
182 outStream << std::setfill(
'-') << std::setw(80) <<
"-" << std::endl;
183 outStream <<
" RISK MEASURE INFORMATION" << std::endl;
184 outStream << std::setfill(
'-') << std::setw(80) <<
"-" << std::endl;
185 outStream <<
" NAME" << std::endl;
186 outStream <<
" " << name << std::endl;
187 outStream <<
" NUMBER OF STATISTICS" << std::endl;
188 outStream <<
" " << nStatistic << std::endl;
189 outStream <<
" ARE BOUNDS ACTIVATED" << std::endl;
190 outStream <<
" " << (isBoundActivated ?
"TRUE" :
"FALSE") << std::endl;
191 if ( isBoundActivated ) {
192 outStream <<
" STATISTIC LOWER BOUNDS" << std::endl;
193 for (
int i = 0; i < nStatistic-1; ++i) {
194 outStream <<
" " << lower[i] << std::endl;
196 outStream <<
" " << lower[nStatistic-1] << std::endl;
197 outStream <<
" STATISTIC UPPER BOUNDS" << std::endl;
198 for (
int i = 0; i < nStatistic-1; ++i) {
199 outStream <<
" " << upper[i] << std::endl;
201 outStream <<
" " << upper[nStatistic-1] << std::endl;
203 outStream << std::setfill(
'-') << std::setw(80) <<
"-" << std::endl;
204 outStream << std::endl;
206 outStream.copyfmt(oldFormatState);
typename PV< Real >::size_type size_type
void RiskMeasureInfo(ROL::ParameterList &parlist, std::string &name, int &nStatistic, std::vector< Real > &lower, std::vector< Real > &upper, bool &isBoundActivated, const bool printToStream=false, std::ostream &outStream=std::cout)
Contains definitions of custom data types in ROL.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
basic_nullstream< char, char_traits< char >> nullstream