ROL
ROL_SecondOrderCVaR.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_SUPERQUANTILEQUADRANGLE_HPP
45 #define ROL_SUPERQUANTILEQUADRANGLE_HPP
46 
47 #include "ROL_SpectralRisk.hpp"
48 #include "ROL_GaussLegendreQuadrature.hpp"
49 #include "ROL_Fejer2Quadrature.hpp"
50 
82 namespace ROL {
83 
84 template<class Real>
85 class SecondOrderCVaR : public SpectralRisk<Real> {
86 private:
87  ROL::Ptr<PlusFunction<Real> > plusFunction_;
88 
89  Real alpha_;
90  int nQuad_;
91  bool useGauss_;
92 
93  std::vector<Real> wts_;
94  std::vector<Real> pts_;
95 
96  void checkInputs(void) const {
97  ROL_TEST_FOR_EXCEPTION((alpha_ < 0 || alpha_ >= 1), std::invalid_argument,
98  ">>> ERROR (ROL::SecondOrderCVaR): Confidence level not between 0 and 1!");
99  ROL_TEST_FOR_EXCEPTION(plusFunction_ == ROL::nullPtr, std::invalid_argument,
100  ">>> ERROR (ROL::SecondOrderCVaR): PlusFunction pointer is null!");
101  }
102 
103  void initializeQuad(void) {
104  ROL::Ptr<Quadrature1D<Real> > quad;
105  if ( useGauss_ ) {
106  quad = ROL::makePtr<GaussLegendreQuadrature<Real>>(nQuad_);
107  }
108  else {
109  quad = ROL::makePtr<Fejer2Quadrature<Real>>(nQuad_);
110  }
111  // quad->test();
112  quad->get(pts_,wts_);
113  Real sum(0), half(0.5), one(1);
114  for (int i = 0; i < nQuad_; ++i) {
115  sum += wts_[i];
116  }
117  for (int i = 0; i < nQuad_; ++i) {
118  wts_[i] /= sum;
119  pts_[i] = one - alpha_*(half*(pts_[i] + one));
120  }
122  }
123 
124 public:
125 
126  SecondOrderCVaR( ROL::ParameterList &parlist )
127  : SpectralRisk<Real>() {
128  ROL::ParameterList &list
129  = parlist.sublist("SOL").sublist("Risk Measure").sublist("Second Order CVaR");
130  // Grab confidence level and quadrature order
131  alpha_ = list.get<Real>("Confidence Level");
132  nQuad_ = list.get("Number of Quadrature Points",5);
133  useGauss_ = list.get("Use Gauss-Legendre Quadrature",true);
134  plusFunction_ = ROL::makePtr<PlusFunction<Real>>(list);
135  // Check inputs
136  checkInputs();
137  initializeQuad();
138  }
139 
140  SecondOrderCVaR(const Real alpha,
141  const int nQuad,
142  const ROL::Ptr<PlusFunction<Real> > &pf,
143  const bool useGauss = true)
144  : SpectralRisk<Real>(), plusFunction_(pf),
145  alpha_(alpha), nQuad_(nQuad), useGauss_(useGauss) {
146  // Check inputs
147  checkInputs();
148  initializeQuad();
149  }
150 };
151 
152 }
153 
154 #endif
void buildMixedQuantile(const std::vector< Real > &pts, const std::vector< Real > &wts, const ROL::Ptr< PlusFunction< Real > > &pf)
std::vector< Real > wts_
SecondOrderCVaR(ROL::ParameterList &parlist)
SecondOrderCVaR(const Real alpha, const int nQuad, const ROL::Ptr< PlusFunction< Real > > &pf, const bool useGauss=true)
Provides an interface for spectral risk measures.
std::vector< Real > pts_
void checkInputs(void) const
ROL::Ptr< PlusFunction< Real > > plusFunction_
Provides an interface for the risk measure associated with the super quantile quadrangle.