ROL
ROL_RiskMeasureFactory.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_RISKMEASUREFACTORY_HPP
11 #define ROL_RISKMEASUREFACTORY_HPP
12 
13 #include "ROL_ParameterList.hpp"
14 
15 #include "ROL_Types.hpp"
16 
17 // Standard Risk Measure Implementations
18 #include "ROL_CVaR.hpp"
19 #include "ROL_MixedCVaR.hpp"
20 #include "ROL_SecondOrderCVaR.hpp"
22 #include "ROL_SpectralRisk.hpp"
23 #include "ROL_QuantileRadius.hpp"
24 #include "ROL_HMCR.hpp"
25 #include "ROL_EntropicRisk.hpp"
28 #include "ROL_MeanDeviation.hpp"
30 #include "ROL_MeanVariance.hpp"
33 
34 // Risk Quadrangle Risk Measure Implementations
39 #include "ROL_MoreauYosidaCVaR.hpp"
43 
44 // F-Divergence Distributionally Robust Risk Measure Implementations
45 #include "ROL_Chi2Divergence.hpp"
46 #include "ROL_KLDivergence.hpp"
47 
48 namespace ROL {
49 
50  enum ERiskMeasure {
76  };
77 
78  inline std::string ERiskMeasureToString(ERiskMeasure ed) {
79  std::string retString;
80  switch(ed) {
81  case RISKMEASURE_CVAR:
82  retString = "CVaR"; break;
84  retString = "Moreau-Yosida CVaR"; break;
86  retString = "Generalized Moreau-Yosida CVaR"; break;
88  retString = "Mixed CVaR"; break;
90  retString = "Spectral Risk"; break;
92  retString = "Second Order CVaR"; break;
94  retString = "Chebyshev Spectral Risk"; break;
96  retString = "Quantile Radius"; break;
97  case RISKMEASURE_HMCR:
98  retString = "HMCR"; break;
100  retString = "Entropic Risk"; break;
102  retString = "Coherent Entropic Risk"; break;
104  retString = "Mean Plus Semi-Deviation"; break;
106  retString = "Mean Plus Semi-Deviation From Target"; break;
108  retString = "Mean Plus Deviation From Target"; break;
110  retString = "Mean Plus Deviation"; break;
112  retString = "Mean Plus Variance From Target"; break;
114  retString = "Mean Plus Variance"; break;
116  retString = "Truncated Mean"; break;
118  retString = "Log Quantile"; break;
120  retString = "Smoothed Worst Case"; break;
122  retString = "Log Exponential"; break;
124  retString = "Safety Margin"; break;
126  retString = "Chi-Squared Divergence"; break;
128  retString = "KL Divergence"; break;
129  case RISKMEASURE_LAST:
130  retString = "Last Type (Dummy)"; break;
131  default:
132  retString = "INVALID ERiskMeasure"; break;
133  }
134  return retString;
135  }
136 
138  return( (ed == RISKMEASURE_CVAR) ||
141  (ed == RISKMEASURE_MIXEDCVAR) ||
142  (ed == RISKMEASURE_SPECTRALRISK) ||
143  (ed == RISKMEASURE_SECONDORDERCVAR) ||
145  (ed == RISKMEASURE_QUANTILERADIUS) ||
146  (ed == RISKMEASURE_HMCR) ||
147  (ed == RISKMEASURE_ENTROPICRISK) ||
152  (ed == RISKMEASURE_MEANDEVIATION) ||
154  (ed == RISKMEASURE_MEANVARIANCE) ||
155  (ed == RISKMEASURE_TRUNCATEDMEAN) ||
156  (ed == RISKMEASURE_LOGQUANTILE) ||
158  (ed == RISKMEASURE_LOGEXPONENTIAL) ||
159  (ed == RISKMEASURE_SAFETYMARGIN) ||
160  (ed == RISKMEASURE_CHI2DIVERGENCE) ||
161  (ed == RISKMEASURE_KLDIVERGENCE));
162  }
163 
165  return type = static_cast<ERiskMeasure>(type+1);
166  }
167 
168  inline ERiskMeasure operator++(ERiskMeasure &type, int) {
169  ERiskMeasure oldval = type;
170  ++type;
171  return oldval;
172  }
173 
175  return type = static_cast<ERiskMeasure>(type-1);
176  }
177 
178  inline ERiskMeasure operator--(ERiskMeasure &type, int) {
179  ERiskMeasure oldval = type;
180  --type;
181  return oldval;
182  }
183 
184  inline ERiskMeasure StringToERiskMeasure(std::string s) {
185  s = removeStringFormat(s);
186  for ( ERiskMeasure tr = RISKMEASURE_CVAR; tr < RISKMEASURE_LAST; tr++ ) {
187  if ( !s.compare(removeStringFormat(ERiskMeasureToString(tr))) ) {
188  return tr;
189  }
190  }
191  return RISKMEASURE_LAST;
192  }
193 
194  template<class Real>
195  inline Ptr<RandVarFunctional<Real>> RiskMeasureFactory(ParameterList &parlist) {
196  std::string risk = parlist.sublist("SOL").sublist("Risk Measure").get("Name","CVaR");
198  switch(ed) {
199  case RISKMEASURE_CVAR:
200  return makePtr<CVaR<Real>>(parlist);
202  return makePtr<ExpectationQuadRisk<Real>>(makePtr<MoreauYosidaCVaR<Real>>(parlist));
204  return makePtr<ExpectationQuadRisk<Real>>(makePtr<GenMoreauYosidaCVaR<Real>>(parlist));
206  return makePtr<MixedCVaR<Real>>(parlist);
208  return makePtr<SpectralRisk<Real>>(parlist);
210  return makePtr<SecondOrderCVaR<Real>>(parlist);
212  return makePtr<ChebyshevSpectral<Real>>(parlist);
214  return makePtr<QuantileRadius<Real>>(parlist);
215  case RISKMEASURE_HMCR:
216  return makePtr<HMCR<Real>>(parlist);
218  return makePtr<EntropicRisk<Real>>(parlist);
220  return makePtr<CoherentEntropicRisk<Real>>();
222  return makePtr<MeanSemiDeviation<Real>>(parlist);
224  return makePtr<MeanSemiDeviationFromTarget<Real>>(parlist);
226  return makePtr<MeanDeviationFromTarget<Real>>(parlist);
228  return makePtr<MeanDeviation<Real>>(parlist);
230  return makePtr<MeanVarianceFromTarget<Real>>(parlist);
232  return makePtr<MeanVariance<Real>>(parlist);
234  return makePtr<ExpectationQuadRisk<Real>>(makePtr<TruncatedMeanQuadrangle<Real>>(parlist));
236  return makePtr<ExpectationQuadRisk<Real>>(makePtr<LogQuantileQuadrangle<Real>>(parlist));
238  return makePtr<ExpectationQuadRisk<Real>>(makePtr<SmoothedWorstCaseQuadrangle<Real>>(parlist));
240  return makePtr<ExpectationQuadRisk<Real>>(makePtr<LogExponentialQuadrangle<Real>>(parlist));
242  return makePtr<ExpectationQuadRisk<Real>>(makePtr<MeanVarianceQuadrangle<Real>>(parlist));
244  return makePtr<Chi2Divergence<Real>>(parlist);
246  return makePtr<KLDivergence<Real>>(parlist);
247  default:
248  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
249  "Invalid risk measure type " << risk << "!");
250  }
251  }
252 }
253 #endif
EPolyProjAlgo & operator++(EPolyProjAlgo &type)
Contains definitions of custom data types in ROL.
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:215
ERiskMeasure StringToERiskMeasure(std::string s)
int isValidRiskMeasure(ERiskMeasure ed)
EPolyProjAlgo & operator--(EPolyProjAlgo &type)
std::string ERiskMeasureToString(ERiskMeasure ed)
Ptr< RandVarFunctional< Real > > RiskMeasureFactory(ParameterList &parlist)