44 #ifndef ROL_RISKMEASUREINFO_HPP
45 #define ROL_RISKMEASUREINFO_HPP
47 #include "ROL_ParameterList.hpp"
54 int &nStatistic, std::vector<Real> &lower,
55 std::vector<Real> &upper,
bool &isBoundActivated,
56 const bool printToStream =
false,
57 std::ostream &outStream = std::cout) {
58 name = parlist.sublist(
"SOL").sublist(
"Risk Measure").get<std::string>(
"Name");
60 lower.clear(); upper.clear();
61 nStatistic = 0; isBoundActivated =
false;
62 if ( name ==
"CVaR" ||
64 name ==
"Moreau-Yosida CVaR" ||
65 name ==
"Generalized Moreau-Yosida CVaR" ||
66 name ==
"Log Quantile" ||
67 name ==
"Smoothed Worst Case" ||
68 name ==
"Safety Margin" ||
69 name ==
"Log Exponential" ||
70 name ==
"Truncated Mean" ) {
72 lower.resize(nStatistic,ROL_NINF<Real>());
73 upper.resize(nStatistic,ROL_INF<Real>());
75 else if ( name ==
"Quantile Radius" ) {
77 lower.resize(nStatistic,ROL_NINF<Real>());
78 upper.resize(nStatistic,ROL_INF<Real>());
80 else if ( name ==
"Coherent Entropic Risk" ||
81 name ==
"KL Divergence" ) {
83 isBoundActivated =
true;
84 lower.resize(nStatistic,zero);
85 upper.resize(nStatistic,ROL_INF<Real>());
87 else if ( name ==
"Chi-Squared Divergence" ) {
89 isBoundActivated =
true;
90 lower.resize(nStatistic,ROL_NINF<Real>()); lower[0] =
zero;
91 upper.resize(nStatistic,ROL_INF<Real>());
93 else if ( name ==
"Mixed CVaR" ) {
94 ROL::ParameterList &list
95 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mixed CVaR");
96 std::vector<Real> prob
97 = ROL::getArrayFromStringParameter<Real>(list,
"Probability Array");
98 nStatistic = prob.size();
99 lower.resize(nStatistic,ROL_NINF<Real>());
100 upper.resize(nStatistic,ROL_INF<Real>());
102 else if ( name ==
"Second Order CVaR" ||
103 name ==
"Chebyshev Spectral Risk" ||
104 name ==
"Spectral Risk" ) {
105 ROL::ParameterList &list
106 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(name);
107 nStatistic = list.get(
"Number of Quadrature Points",5);
108 lower.resize(nStatistic,ROL_NINF<Real>());
109 upper.resize(nStatistic,ROL_INF<Real>());
111 else if ( name ==
"Entropic Risk" ||
112 name ==
"Mean Plus Semi-Deviation From Target" ||
113 name ==
"Mean Plus Semi-Deviation" ||
114 name ==
"Mean Plus Deviation From Target" ||
115 name ==
"Mean Plus Deviation" ||
116 name ==
"Mean Plus Variance From Target" ||
117 name ==
"Mean Plus Variance" ) {
120 else if ( name ==
"Convex Combination Risk Measure" ) {
121 ROL::ParameterList &list
122 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Convex Combination Risk Measure");
124 std::vector<Real> lambda
125 = ROL::getArrayFromStringParameter<Real>(list,
"Convex Combination Parameters");
127 std::vector<std::string> riskString;
129 std::ostringstream convert;
131 std::string si = convert.str();
132 ROL::ParameterList &ilist = list.sublist(si);
133 std::string namei = ilist.get<std::string>(
"Name");
134 riskString.push_back(namei);
137 if ( riskString[i] ==
"CVaR" ||
138 riskString[i] ==
"HMCR" ||
139 riskString[i] ==
"Moreau-Yosida CVaR" ||
140 riskString[i] ==
"Generalized Moreau-Yosida CVaR" ||
141 riskString[i] ==
"Log Quantile" ||
142 riskString[i] ==
"Smoothed Worst Case" ||
143 riskString[i] ==
"Safety Margin" ||
144 riskString[i] ==
"Log Exponential" ||
145 riskString[i] ==
"Truncated Mean" ) {
147 lower.push_back(ROL_NINF<Real>());
148 upper.push_back(ROL_INF<Real>());
150 else if ( riskString[i] ==
"Quantile Radius" ) {
152 lower.push_back(ROL_NINF<Real>()); lower.push_back(ROL_NINF<Real>());
153 upper.push_back(ROL_INF<Real>()); upper.push_back(ROL_INF<Real>());
155 else if ( riskString[i] ==
"Coherent Entropic Risk" ||
156 riskString[i] ==
"KL Divergence" ) {
158 isBoundActivated =
true;
159 lower.push_back(zero);
160 upper.push_back(ROL_INF<Real>());
162 else if ( riskString[i] ==
"Chi-Squared Divergence" ) {
164 isBoundActivated =
true;
165 lower.push_back(zero); lower.push_back(ROL_NINF<Real>());
166 upper.push_back(ROL_INF<Real>()); upper.push_back(ROL_INF<Real>());
168 else if ( riskString[i] ==
"Mixed CVaR" ) {
169 ROL::ParameterList &MQlist = list.sublist(
"Mixed CVaR");
170 std::vector<Real> prob
171 = ROL::getArrayFromStringParameter<Real>(MQlist,
"Probability Array");
172 nStatistic += prob.size();
174 lower.push_back(ROL_NINF<Real>());
175 upper.push_back(ROL_INF<Real>());
178 else if ( riskString[i] ==
"Second Order CVaR" ||
179 riskString[i] ==
"Chebyshev Spectral Risk" ||
180 riskString[i] ==
"Spectral Risk" ) {
181 ROL::ParameterList &SQlist = list.sublist(riskString[i]);
182 int nSQQstat = SQlist.get(
"Number of Quadrature Points",5);
183 nStatistic += nSQQstat;
184 for (
int j = 0; j < nSQQstat; ++j) {
185 lower.push_back(ROL_NINF<Real>());
186 upper.push_back(ROL_INF<Real>());
189 else if ( riskString[i] ==
"Entropic Risk" ||
190 riskString[i] ==
"Mean Plus Semi-Deviation From Target" ||
191 riskString[i] ==
"Mean Plus Semi-Deviation" ||
192 riskString[i] ==
"Mean Plus Deviation From Target" ||
193 riskString[i] ==
"Mean Plus Deviation" ||
194 riskString[i] ==
"Mean Plus Variance From Target" ||
195 riskString[i] ==
"Mean Plus Variance" ) {
199 ROL_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
200 ">>> (ROL::RiskMeasureInfo): Invalid risk measure " << riskString[i] <<
"!");
205 ROL_TEST_FOR_EXCEPTION(
true,std::invalid_argument,
206 ">>> (ROL::RiskMeasureInfo): Invalid risk measure " << name <<
"!");
210 if ( printToStream ) {
212 oldFormatState.copyfmt(outStream);
214 outStream << std::endl;
215 outStream << std::scientific << std::setprecision(6);
216 outStream << std::setfill(
'-') << std::setw(80) <<
"-" << std::endl;
217 outStream <<
" RISK MEASURE INFORMATION" << std::endl;
218 outStream << std::setfill(
'-') << std::setw(80) <<
"-" << std::endl;
219 outStream <<
" NAME" << std::endl;
220 outStream <<
" " << name << std::endl;
221 outStream <<
" NUMBER OF STATISTICS" << std::endl;
222 outStream <<
" " << nStatistic << std::endl;
223 outStream <<
" ARE BOUNDS ACTIVATED" << std::endl;
224 outStream <<
" " << (isBoundActivated ?
"TRUE" :
"FALSE") << std::endl;
225 if ( isBoundActivated ) {
226 outStream <<
" STATISTIC LOWER BOUNDS" << std::endl;
227 for (
int i = 0; i < nStatistic-1; ++i) {
228 outStream <<
" " << lower[i] << std::endl;
230 outStream <<
" " << lower[nStatistic-1] << std::endl;
231 outStream <<
" STATISTIC UPPER BOUNDS" << std::endl;
232 for (
int i = 0; i < nStatistic-1; ++i) {
233 outStream <<
" " << upper[i] << std::endl;
235 outStream <<
" " << upper[nStatistic-1] << std::endl;
237 outStream << std::setfill(
'-') << std::setw(80) <<
"-" << std::endl;
238 outStream << std::endl;
240 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