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