ROL
ROL_RiskMeasureInfo.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_RISKMEASUREINFO_HPP
45 #define ROL_RISKMEASUREINFO_HPP
46 
47 #include "Teuchos_ParameterList.hpp"
48 #include "ROL_Types.hpp"
49 
50 namespace ROL {
51 
52 template<class Real>
53 inline void RiskMeasureInfo(Teuchos::ParameterList &parlist, std::string &name,
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");
59  Real zero(0);
60  lower.clear(); upper.clear();
61  nStatistic = 0; isBoundActivated = false;
62  if ( name == "CVaR" ||
63  name == "HMCR" ||
64  name == "Moreau-Yosida CVaR" ||
65  name == "Generalized Moreau-Yosida CVaR" ||
66  name == "Log-Exponential Quadrangle" ||
67  name == "Log-Quantile Quadrangle" ||
68  name == "Mean-Variance Quadrangle" ||
69  name == "Quantile-Based Quadrangle" ||
70  name == "Smoothed Worst-Case Quadrangle" ||
71  name == "Truncated Mean Quadrangle" ) {
72  nStatistic = 1;
73  lower.resize(nStatistic,ROL_NINF<Real>());
74  upper.resize(nStatistic,ROL_INF<Real>());
75  }
76  else if ( name == "Quantile-Radius Quadrangle" ) {
77  nStatistic = 2;
78  lower.resize(nStatistic,ROL_NINF<Real>());
79  upper.resize(nStatistic,ROL_INF<Real>());
80  }
81  else if ( name == "Coherent Exponential Utility" ||
82  name == "KL Divergence" ) {
83  nStatistic = 1;
84  isBoundActivated = true;
85  lower.resize(nStatistic,zero);
86  upper.resize(nStatistic,ROL_INF<Real>());
87  }
88  else if ( name == "Chi-Squared Divergence" ) {
89  nStatistic = 2;
90  isBoundActivated = true;
91  lower.resize(nStatistic,ROL_NINF<Real>()); lower[0] = zero;
92  upper.resize(nStatistic,ROL_INF<Real>());
93  }
94  else if ( name == "Mixed-Quantile Quadrangle" ) {
95  Teuchos::ParameterList &list
96  = parlist.sublist("SOL").sublist("Risk Measure").sublist("Mixed-Quantile Quadrangle");
97  Teuchos::Array<Real> prob
98  = Teuchos::getArrayFromStringParameter<Real>(list,"Probability Array");
99  nStatistic = prob.size();
100  lower.resize(nStatistic,ROL_NINF<Real>());
101  upper.resize(nStatistic,ROL_INF<Real>());
102  }
103  else if ( name == "Super Quantile Quadrangle" ||
104  name == "Chebyshev-Kusuoka" ||
105  name == "Spectral Risk" ) {
106  Teuchos::ParameterList &list
107  = parlist.sublist("SOL").sublist("Risk Measure").sublist(name);
108  nStatistic = list.get("Number of Quadrature Points",5);
109  lower.resize(nStatistic,ROL_NINF<Real>());
110  upper.resize(nStatistic,ROL_INF<Real>());
111  }
112  else if ( name == "Exponential Utility" ||
113  name == "Mean Plus Deviation From Target" ||
114  name == "Mean Plus Deviation" ||
115  name == "Mean Plus Variance From Target" ||
116  name == "Mean Plus Variance" ) {
117  nStatistic = 0;
118  }
119  else if ( name == "Convex Combination Risk Measure" ) {
120  Teuchos::ParameterList &list
121  = parlist.sublist("SOL").sublist("Risk Measure").sublist("Convex Combination Risk Measure");
122  // Get convex combination parameters
123  Teuchos::Array<Real> lambda
124  = Teuchos::getArrayFromStringParameter<Real>(list,"Convex Combination Parameters");
125  // Build risk measures
126  std::vector<std::string> riskString;
127  for (typename Teuchos::Array<Real>::size_type i = 0; i < lambda.size(); ++i) {
128  std::ostringstream convert;
129  convert << i;
130  std::string si = convert.str();
131  Teuchos::ParameterList &ilist = list.sublist(si);
132  std::string name = ilist.get<std::string>("Name");
133  riskString.push_back(name);
134  }
135  for (typename std::vector<Real>::size_type i = 0; i < riskString.size(); ++i) {
136  if ( riskString[i] == "CVaR" ||
137  riskString[i] == "HMCR" ||
138  riskString[i] == "Moreau-Yosida CVaR" ||
139  riskString[i] == "Generalized Moreau-Yosida CVaR" ||
140  riskString[i] == "Log-Exponential Quadrangle" ||
141  riskString[i] == "Log-Quantile Quadrangle" ||
142  riskString[i] == "Mean-Variance Quadrangle" ||
143  riskString[i] == "Quantile-Based Quadrangle" ||
144  riskString[i] == "Smoothed Worst-Case Quadrangle" ||
145  riskString[i] == "Truncated Mean Quadrangle" ) {
146  nStatistic += 1;
147  lower.push_back(ROL_NINF<Real>());
148  upper.push_back(ROL_INF<Real>());
149  }
150  else if ( riskString[i] == "Quantile-Radius Quadrangle" ) {
151  nStatistic += 2;
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>());
154  }
155  else if ( riskString[i] == "Coherent Exponential Utility" ||
156  riskString[i] == "KL Divergence" ) {
157  nStatistic += 1;
158  isBoundActivated = true;
159  lower.push_back(zero);
160  upper.push_back(ROL_INF<Real>());
161  }
162  else if ( riskString[i] == "Chi-Squared Divergence" ) {
163  nStatistic += 2;
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>());
167  }
168  else if ( riskString[i] == "Mixed-Quantile Quadrangle" ) {
169  Teuchos::ParameterList &MQlist = list.sublist("Mixed-Quantile Quadrangle");
170  Teuchos::Array<Real> prob
171  = Teuchos::getArrayFromStringParameter<Real>(MQlist,"Probability Array");
172  nStatistic += prob.size();
173  for (typename Teuchos::Array<Real>::size_type j = 0; j < prob.size(); ++j) {
174  lower.push_back(ROL_NINF<Real>());
175  upper.push_back(ROL_INF<Real>());
176  }
177  }
178  else if ( riskString[i] == "Super Quantile Quadrangle" ||
179  riskString[i] == "Chebyshev-Kusuoka" ||
180  riskString[i] == "Spectral Risk" ) {
181  Teuchos::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>());
187  }
188  }
189  else if ( riskString[i] == "Exponential Utility" ||
190  riskString[i] == "Mean Plus Deviation From Target" ||
191  riskString[i] == "Mean Plus Deviation" ||
192  riskString[i] == "Mean Plus Variance From Target" ||
193  riskString[i] == "Mean Plus Variance" ) {
194  nStatistic += 0;
195  }
196  else {
197  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
198  ">>> (ROL::RiskMeasureInfo): Invalid risk measure " << riskString[i] << "!");
199  }
200  }
201  }
202  else {
203  TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,
204  ">>> (ROL::RiskMeasureInfo): Invalid risk measure " << name << "!");
205  }
206 
207  // Print Information
208  if ( printToStream ) {
209  Teuchos::oblackholestream oldFormatState;
210  oldFormatState.copyfmt(outStream);
211 
212  outStream << std::endl;
213  outStream << std::scientific << std::setprecision(6);
214  outStream << std::setfill('-') << std::setw(80) << "-" << std::endl;
215  outStream << " RISK MEASURE INFORMATION" << std::endl;
216  outStream << std::setfill('-') << std::setw(80) << "-" << std::endl;
217  outStream << " NAME" << std::endl;
218  outStream << " " << name << std::endl;
219  outStream << " NUMBER OF STATISTICS" << std::endl;
220  outStream << " " << nStatistic << std::endl;
221  outStream << " ARE BOUNDS ACTIVATED" << std::endl;
222  outStream << " " << (isBoundActivated ? "TRUE" : "FALSE") << std::endl;
223  if ( isBoundActivated ) {
224  outStream << " STATISTIC LOWER BOUNDS" << std::endl;
225  for (int i = 0; i < nStatistic-1; ++i) {
226  outStream << " " << lower[i] << std::endl;
227  }
228  outStream << " " << lower[nStatistic-1] << std::endl;
229  outStream << " STATISTIC UPPER BOUNDS" << std::endl;
230  for (int i = 0; i < nStatistic-1; ++i) {
231  outStream << " " << upper[i] << std::endl;
232  }
233  outStream << " " << upper[nStatistic-1] << std::endl;
234  }
235  outStream << std::setfill('-') << std::setw(80) << "-" << std::endl;
236  outStream << std::endl;
237 
238  outStream.copyfmt(oldFormatState);
239  }
240 }
241 
242 }
243 #endif
Contains definitions of custom data types in ROL.
void RiskMeasureInfo(Teuchos::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)