ROL
ROL_ErrorMeasureFactory.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_ERRORMEASUREFACTORY_HPP
11 #define ROL_ERRORMEASUREFACTORY_HPP
12 
13 #include "ROL_ParameterList.hpp"
14 
15 #include "ROL_Types.hpp"
16 
17 // Risk Quadrangle Implementations
20 #include "ROL_MoreauYosidaCVaR.hpp"
27 
28 namespace ROL {
29 
40  };
41 
42  inline std::string EErrorMeasureToString(EErrorMeasure ed) {
43  std::string retString;
44  switch(ed) {
46  retString = "Least Squares"; break;
48  retString = "Huber"; break;
50  retString = "Koenker-Bassett"; break;
52  retString = "Moreau-Yosida-Koenker-Bassett"; break;
54  retString = "Generalized Moreau-Yosida-Koenker-Bassett"; break;
56  retString = "Exponential"; break;
58  retString = "Log Quantile"; break;
60  retString = "Smoothed Worst Case"; break;
61  case ERRORMEASURE_LAST:
62  retString = "Last Type (Dummy)"; break;
63  default:
64  retString = "INVALID EErrorMeasure"; break;
65  }
66  return retString;
67  }
68 
70  return( (ed == ERRORMEASURE_MEANVARIANCEQUADRANGLE) ||
78  }
79 
81  return type = static_cast<EErrorMeasure>(type+1);
82  }
83 
84  inline EErrorMeasure operator++(EErrorMeasure &type, int) {
85  EErrorMeasure oldval = type;
86  ++type;
87  return oldval;
88  }
89 
91  return type = static_cast<EErrorMeasure>(type-1);
92  }
93 
94  inline EErrorMeasure operator--(EErrorMeasure &type, int) {
95  EErrorMeasure oldval = type;
96  --type;
97  return oldval;
98  }
99 
100  inline EErrorMeasure StringToEErrorMeasure(std::string s) {
101  s = removeStringFormat(s);
103  if ( !s.compare(removeStringFormat(EErrorMeasureToString(tr))) ) {
104  return tr;
105  }
106  }
107  return ERRORMEASURE_LAST;
108  }
109 
110  template<class Real>
111  inline Ptr<RandVarFunctional<Real>> ErrorMeasureFactory(ParameterList &parlist) {
112  std::string error = parlist.sublist("SOL").sublist("Error Measure").get("Name","Least Squares");
114  switch(ed) {
116  return makePtr<ExpectationQuadError<Real>>(makePtr<MeanVarianceQuadrangle<Real>>(parlist));
118  return makePtr<ExpectationQuadError<Real>>(makePtr<TruncatedMeanQuadrangle<Real>>(parlist));
120  return makePtr<ExpectationQuadError<Real>>(makePtr<QuantileQuadrangle<Real>>(parlist));
122  return makePtr<ExpectationQuadError<Real>>(makePtr<MoreauYosidaCVaR<Real>>(parlist));
124  return makePtr<ExpectationQuadError<Real>>(makePtr<GenMoreauYosidaCVaR<Real>>(parlist));
126  return makePtr<ExpectationQuadError<Real>>(makePtr<LogExponentialQuadrangle<Real>>(parlist));
128  return makePtr<ExpectationQuadError<Real>>(makePtr<LogQuantileQuadrangle<Real>>(parlist));
130  return makePtr<ExpectationQuadError<Real>>(makePtr<SmoothedWorstCaseQuadrangle<Real>>(parlist));
131  default:
132  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
133  "Invalid error measure type " << error << "!");
134  }
135  }
136 }
137 #endif
std::string EErrorMeasureToString(EErrorMeasure ed)
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 > > ErrorMeasureFactory(ParameterList &parlist)
EPolyProjAlgo & operator--(EPolyProjAlgo &type)
int isValidErrorMeasure(EErrorMeasure ed)
EErrorMeasure StringToEErrorMeasure(std::string s)