ROL
ROL_RegretMeasureFactory.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_REGRETMEASUREFACTORY_HPP
11 #define ROL_REGRETMEASUREFACTORY_HPP
12 
13 #include "ROL_ParameterList.hpp"
14 #include "ROL_Types.hpp"
17 #include "ROL_MoreauYosidaCVaR.hpp"
24 
25 namespace ROL {
26 
37  };
38 
39  inline std::string ERegretMeasureToString(ERegretMeasure ed) {
40  std::string retString;
41  switch(ed) {
43  retString = "Mean Absolute Loss"; break;
45  retString = "Moreau-Yosida Mean Absolute Loss"; break;
47  retString = "Generalized Moreau-Yosida Mean Absolute Loss"; break;
49  retString = "Exponential"; break;
51  retString = "Mean L2"; break;
53  retString = "Truncated Mean"; break;
55  retString = "Log Quantile"; break;
57  retString = "Smoothed Worst Case"; break;
58  case REGRETMEASURE_LAST:
59  retString = "Last Type (Dummy)"; break;
60  default:
61  retString = "INVALID ERegretMeasure"; break;
62  }
63  return retString;
64  }
65 
67  return( (ed == REGRETMEASURE_MEANABSOLUTELOSS) ||
70  (ed == REGRETMEASURE_EXPONENTIAL) ||
71  (ed == REGRETMEASURE_MEANL2) ||
73  (ed == REGRETMEASURE_LOGQUANTILE) ||
75  }
76 
78  return type = static_cast<ERegretMeasure>(type+1);
79  }
80 
82  ERegretMeasure oldval = type;
83  ++type;
84  return oldval;
85  }
86 
88  return type = static_cast<ERegretMeasure>(type-1);
89  }
90 
92  ERegretMeasure oldval = type;
93  --type;
94  return oldval;
95  }
96 
97  inline ERegretMeasure StringToERegretMeasure(std::string s) {
98  s = removeStringFormat(s);
100  if ( !s.compare(removeStringFormat(ERegretMeasureToString(tr))) ) {
101  return tr;
102  }
103  }
104  return REGRETMEASURE_LAST;
105  }
106 
107  template<class Real>
108  inline Ptr<RandVarFunctional<Real>> RegretMeasureFactory(ParameterList &parlist) {
109  std::string regret = parlist.sublist("SOL").sublist("Regret Measure").get("Name","Mean Absolute Loss");
111  switch(ed) {
113  return makePtr<ExpectationQuadRegret<Real>>(makePtr<QuantileQuadrangle<Real>>(parlist));
115  return makePtr<ExpectationQuadRegret<Real>>(makePtr<MoreauYosidaCVaR<Real>>(parlist));
117  return makePtr<ExpectationQuadRegret<Real>>(makePtr<GenMoreauYosidaCVaR<Real>>(parlist));
119  return makePtr<ExpectationQuadRegret<Real>>(makePtr<LogExponentialQuadrangle<Real>>(parlist));
121  return makePtr<ExpectationQuadRegret<Real>>(makePtr<MeanVarianceQuadrangle<Real>>(parlist));
123  return makePtr<ExpectationQuadRegret<Real>>(makePtr<TruncatedMeanQuadrangle<Real>>(parlist));
125  return makePtr<ExpectationQuadRegret<Real>>(makePtr<LogQuantileQuadrangle<Real>>(parlist));
127  return makePtr<ExpectationQuadRegret<Real>>(makePtr<SmoothedWorstCaseQuadrangle<Real>>(parlist));
128  default:
129  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
130  "Invalid regret measure type " << regret << "!");
131  }
132  }
133 }
134 #endif
EPolyProjAlgo & operator++(EPolyProjAlgo &type)
Contains definitions of custom data types in ROL.
std::string removeStringFormat(std::string s)
Definition: ROL_Types.hpp:215
Ptr< RandVarFunctional< Real > > RegretMeasureFactory(ParameterList &parlist)
int isValidRegretMeasure(ERegretMeasure ed)
EPolyProjAlgo & operator--(EPolyProjAlgo &type)
std::string ERegretMeasureToString(ERegretMeasure ed)
ERegretMeasure StringToERegretMeasure(std::string s)