ROL
ROL_ChebyshevSpectral.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_CHEBYSHEVKUSUOKA_HPP
45 #define ROL_CHEBYSHEVKUSUOKA_HPP
46 
47 #include "ROL_SpectralRisk.hpp"
48 #include "ROL_GaussChebyshev1Quadrature.hpp"
49 #include "ROL_GaussChebyshev2Quadrature.hpp"
50 #include "ROL_GaussChebyshev3Quadrature.hpp"
51 
94 namespace ROL {
95 
96 template<class Real>
97 class ChebyshevSpectral : public SpectralRisk<Real> {
98 private:
99  ROL::Ptr<PlusFunction<Real> > plusFunction_;
100 
101  Real lower_, upper_;
102  int nQuad_;
103  int wType_;
104 
105  std::vector<Real> wts_;
106  std::vector<Real> pts_;
107 
108  void checkInputs(void) const {
109  ROL_TEST_FOR_EXCEPTION(lower_ > upper_, std::invalid_argument,
110  ">>> ERROR (ROL::ChebyshevSpectral): Lower bound exceeds upper!");
111  ROL_TEST_FOR_EXCEPTION(lower_ < static_cast<Real>(0), std::invalid_argument,
112  ">>> ERROR (ROL::ChebyshevSpectral): Lower bound is less than zero!");
113  ROL_TEST_FOR_EXCEPTION(static_cast<Real>(1) < upper_, std::invalid_argument,
114  ">>> ERROR (ROL::ChebyshevSpectral): Upper bound is greater than one!");
115  ROL_TEST_FOR_EXCEPTION((wType_ < 1 || wType_ > 3), std::invalid_argument,
116  ">>> ERROR (ROL::ChebyshevSpectral): Weight must be 1, 2 or 3!");
117  ROL_TEST_FOR_EXCEPTION(plusFunction_ == ROL::nullPtr, std::invalid_argument,
118  ">>> ERROR (ROL::ChebyshevSpectral): PlusFunction pointer is null!");
119  }
120 
121  void initializeQuad(void) {
122  ROL::Ptr<Quadrature1D<Real> > quad;
123  if ( wType_ == 1 ) {
124  quad = ROL::makePtr<GaussChebyshev1Quadrature<Real>>(nQuad_);
125  }
126  else if ( wType_ == 2 ) {
127  quad = ROL::makePtr<GaussChebyshev2Quadrature<Real>>(nQuad_);
128  }
129  else if ( wType_ == 3 ) {
130  quad = ROL::makePtr<GaussChebyshev3Quadrature<Real>>(nQuad_);
131  }
132  // quad->test();
133  quad->get(pts_,wts_);
134  Real sum(0), half(0.5), one(1);
135  for (int i = 0; i < nQuad_; ++i) {
136  sum += wts_[i];
137  }
138  for (int i = 0; i < nQuad_; ++i) {
139  wts_[i] /= sum;
140  pts_[i] = lower_ + (upper_-lower_)*half*(pts_[i] + one);
141  }
143  }
144 
145 public:
158  ChebyshevSpectral( ROL::ParameterList &parlist )
159  : SpectralRisk<Real>() {
160  ROL::ParameterList &list
161  = parlist.sublist("SOL").sublist("Risk Measure").sublist("Chebyshev Spectral Risk");
162  // Grab confidence level and quadrature order
163  lower_ = list.get("Lower Bound",0.0);
164  upper_ = list.get("Upper Bound",1.0);
165  nQuad_ = list.get("Number of Quadrature Points",5);
166  wType_ = list.get("Weight Type",1);
167  plusFunction_ = ROL::makePtr<PlusFunction<Real>>(list);
168  // Check inputs
169  checkInputs();
170  initializeQuad();
171  }
172 
181  ChebyshevSpectral(const Real lower, const Real upper,
182  const int nQuad, const int wType,
183  const ROL::Ptr<PlusFunction<Real> > &pf)
184  : SpectralRisk<Real>(), plusFunction_(pf),
185  lower_(lower), upper_(upper), nQuad_(nQuad), wType_(wType) {
186  // Check inputs
187  checkInputs();
188  initializeQuad();
189  }
190 };
191 
192 }
193 
194 #endif
Provides an interface for the Chebyshev-Spectral risk measure.
void buildMixedQuantile(const std::vector< Real > &pts, const std::vector< Real > &wts, const ROL::Ptr< PlusFunction< Real > > &pf)
ChebyshevSpectral(ROL::ParameterList &parlist)
Constructor.
Provides an interface for spectral risk measures.
ROL::Ptr< PlusFunction< Real > > plusFunction_
ChebyshevSpectral(const Real lower, const Real upper, const int nQuad, const int wType, const ROL::Ptr< PlusFunction< Real > > &pf)
Constructor.