ROL
ROL_RiskMeasureFactory.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
44 #ifndef ROL_RISKMEASUREFACTORY_HPP
45 #define ROL_RISKMEASUREFACTORY_HPP
46 
47 #include "ROL_ParameterList.hpp"
48 
49 #include "ROL_Types.hpp"
50 
51 // Standard Risk Measure Implementations
52 #include "ROL_CVaR.hpp"
53 #include "ROL_MixedCVaR.hpp"
54 #include "ROL_SecondOrderCVaR.hpp"
56 #include "ROL_SpectralRisk.hpp"
57 #include "ROL_QuantileRadius.hpp"
58 #include "ROL_HMCR.hpp"
59 #include "ROL_EntropicRisk.hpp"
62 #include "ROL_MeanDeviation.hpp"
64 #include "ROL_MeanVariance.hpp"
67 
68 // Risk Quadrangle Risk Measure Implementations
73 #include "ROL_MoreauYosidaCVaR.hpp"
77 
78 // F-Divergence Distributionally Robust Risk Measure Implementations
79 #include "ROL_Chi2Divergence.hpp"
80 #include "ROL_KLDivergence.hpp"
81 
82 namespace ROL {
83 
84  enum ERiskMeasure {
110  };
111 
112  inline std::string ERiskMeasureToString(ERiskMeasure ed) {
113  std::string retString;
114  switch(ed) {
115  case RISKMEASURE_CVAR:
116  retString = "CVaR"; break;
118  retString = "Moreau-Yosida CVaR"; break;
120  retString = "Generalized Moreau-Yosida CVaR"; break;
122  retString = "Mixed CVaR"; break;
124  retString = "Spectral Risk"; break;
126  retString = "Second Order CVaR"; break;
128  retString = "Chebyshev Spectral Risk"; break;
130  retString = "Quantile Radius"; break;
131  case RISKMEASURE_HMCR:
132  retString = "HMCR"; break;
134  retString = "Entropic Risk"; break;
136  retString = "Coherent Entropic Risk"; break;
138  retString = "Mean Plus Semi-Deviation"; break;
140  retString = "Mean Plus Semi-Deviation From Target"; break;
142  retString = "Mean Plus Deviation From Target"; break;
144  retString = "Mean Plus Deviation"; break;
146  retString = "Mean Plus Variance From Target"; break;
148  retString = "Mean Plus Variance"; break;
150  retString = "Truncated Mean"; break;
152  retString = "Log Quantile"; break;
154  retString = "Smoothed Worst Case"; break;
156  retString = "Log Exponential"; break;
158  retString = "Safety Margin"; break;
160  retString = "Chi-Squared Divergence"; break;
162  retString = "KL Divergence"; break;
163  case RISKMEASURE_LAST:
164  retString = "Last Type (Dummy)"; break;
165  default:
166  retString = "INVALID ERiskMeasure"; break;
167  }
168  return retString;
169  }
170 
172  return( (ed == RISKMEASURE_CVAR) ||
175  (ed == RISKMEASURE_MIXEDCVAR) ||
176  (ed == RISKMEASURE_SPECTRALRISK) ||
177  (ed == RISKMEASURE_SECONDORDERCVAR) ||
179  (ed == RISKMEASURE_QUANTILERADIUS) ||
180  (ed == RISKMEASURE_HMCR) ||
181  (ed == RISKMEASURE_ENTROPICRISK) ||
186  (ed == RISKMEASURE_MEANDEVIATION) ||
188  (ed == RISKMEASURE_MEANVARIANCE) ||
189  (ed == RISKMEASURE_TRUNCATEDMEAN) ||
190  (ed == RISKMEASURE_LOGQUANTILE) ||
192  (ed == RISKMEASURE_LOGEXPONENTIAL) ||
193  (ed == RISKMEASURE_SAFETYMARGIN) ||
194  (ed == RISKMEASURE_CHI2DIVERGENCE) ||
195  (ed == RISKMEASURE_KLDIVERGENCE));
196  }
197 
199  return type = static_cast<ERiskMeasure>(type+1);
200  }
201 
202  inline ERiskMeasure operator++(ERiskMeasure &type, int) {
203  ERiskMeasure oldval = type;
204  ++type;
205  return oldval;
206  }
207 
209  return type = static_cast<ERiskMeasure>(type-1);
210  }
211 
212  inline ERiskMeasure operator--(ERiskMeasure &type, int) {
213  ERiskMeasure oldval = type;
214  --type;
215  return oldval;
216  }
217 
218  inline ERiskMeasure StringToERiskMeasure(std::string s) {
219  s = removeStringFormat(s);
220  for ( ERiskMeasure tr = RISKMEASURE_CVAR; tr < RISKMEASURE_LAST; tr++ ) {
221  if ( !s.compare(removeStringFormat(ERiskMeasureToString(tr))) ) {
222  return tr;
223  }
224  }
225  return RISKMEASURE_LAST;
226  }
227 
228  template<class Real>
229  inline Ptr<RandVarFunctional<Real> > RiskMeasureFactory(ROL::ParameterList &parlist) {
230  std::string risk = parlist.sublist("SOL").sublist("Risk Measure").get("Name","CVaR");
232  switch(ed) {
233  case RISKMEASURE_CVAR:
234  return makePtr<CVaR<Real>>(parlist);
236  return makePtr<ExpectationQuadRisk<Real>>(makePtr<MoreauYosidaCVaR<Real>>(parlist));
238  return makePtr<ExpectationQuadRisk<Real>>(makePtr<GenMoreauYosidaCVaR<Real>>(parlist));
240  return makePtr<MixedCVaR<Real>>(parlist);
242  return makePtr<SpectralRisk<Real>>(parlist);
244  return makePtr<SecondOrderCVaR<Real>>(parlist);
246  return makePtr<ChebyshevSpectral<Real>>(parlist);
248  return makePtr<QuantileRadius<Real>>(parlist);
249  case RISKMEASURE_HMCR:
250  return makePtr<HMCR<Real>>(parlist);
252  return makePtr<EntropicRisk<Real>>(parlist);
254  return makePtr<CoherentEntropicRisk<Real>>();
256  return makePtr<MeanSemiDeviation<Real>>(parlist);
258  return makePtr<MeanSemiDeviationFromTarget<Real>>(parlist);
260  return makePtr<MeanDeviationFromTarget<Real>>(parlist);
262  return makePtr<MeanDeviation<Real>>(parlist);
264  return makePtr<MeanVarianceFromTarget<Real>>(parlist);
266  return makePtr<MeanVariance<Real>>(parlist);
268  return makePtr<ExpectationQuadRisk<Real>>(makePtr<TruncatedMeanQuadrangle<Real>>(parlist));
270  return makePtr<ExpectationQuadRisk<Real>>(makePtr<LogQuantileQuadrangle<Real>>(parlist));
272  return makePtr<ExpectationQuadRisk<Real>>(makePtr<SmoothedWorstCaseQuadrangle<Real>>(parlist));
274  return makePtr<ExpectationQuadRisk<Real>>(makePtr<LogExponentialQuadrangle<Real>>(parlist));
276  return makePtr<ExpectationQuadRisk<Real>>(makePtr<MeanVarianceQuadrangle<Real>>(parlist));
278  return makePtr<Chi2Divergence<Real>>(parlist);
280  return makePtr<KLDivergence<Real>>(parlist);
281  default:
282  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
283  "Invalid risk measure type " << risk << "!");
284  }
285  }
286 }
287 #endif
EKrylov & operator++(EKrylov &type)
Contains definitions of custom data types in ROL.
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:247
ERiskMeasure StringToERiskMeasure(std::string s)
int isValidRiskMeasure(ERiskMeasure ed)
Ptr< RandVarFunctional< Real > > RiskMeasureFactory(ROL::ParameterList &parlist)
std::string ERiskMeasureToString(ERiskMeasure ed)
EKrylov & operator--(EKrylov &type)