ROL
ROL_Parabolic.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_PARABOLIC_HPP
45 #define ROL_PARABOLIC_HPP
46 
47 #include "ROL_Distribution.hpp"
48 #include "ROL_ParameterList.hpp"
49 
50 namespace ROL {
51 
52 template<class Real>
53 class Parabolic : public Distribution<Real> {
54 private:
55  Real a_;
56  Real b_;
57 
58 public:
59  Parabolic(const Real a = 0., const Real b = 1.)
60  : a_(std::min(a,b)), b_(std::max(a,b)) {}
61 
62  Parabolic(ROL::ParameterList &parlist) {
63  a_ = parlist.sublist("SOL").sublist("Distribution").sublist("Parabolic").get("Lower Bound",0.);
64  b_ = parlist.sublist("SOL").sublist("Distribution").sublist("Parabolic").get("Upper Bound",1.);
65  Real tmp = a_;
66  a_ = std::min(a_,b_);
67  b_ = std::max(b_,tmp);
68  }
69 
70  Real evaluatePDF(const Real input) const {
71  Real scale = 6.0/std::pow(b_-a_,3.0);
72  return ((input >= a_ && input <= b_) ? scale*(input-a_)*(b_-input) : 0.);
73  }
74 
75  Real evaluateCDF(const Real input) const {
76  Real d1 = b_-a_, d2 = d1*d1, d3 = d2*d1;
77  Real v1 = input-a_, v2 = v1*v1, v3 = v1*v2;
78  return ((input < a_) ? 0. : ((input > b_) ? 1. :
79  3.0*v2/d2 - 2.0*v3/d3));
80  }
81 
82  Real integrateCDF(const Real input) const {
83  Real d0 = b_+a_, d1 = b_-a_, d2 = d1*d1, d3 = d2*d1;
84  Real v1 = input-a_, v2 = v1*v1, v3 = v1*v2, v4 = v1*v3;
85  return ((input < a_) ? 0. :
86  ((input > b_) ? input - 0.5*d0 :
87  v3/d2 - 0.5*v4/d3));
88  }
89 
90  Real invertCDF(const Real input) const {
91  Real a = a_-b_, b = a_+b_, c = 0.;
92  Real fa = evaluateCDF(a) - input;
93  Real fc = 0.;
94  Real sa = ((fa < 0.) ? -1. : ((fa > 0.) ? 1. : 0.));
95  Real sc = 0.;
96  for (size_t i = 0; i < 100; i++) {
97  c = (a+b)*0.5;
98  fc = evaluateCDF(c) - input;
99  sc = ((fc < 0.) ? -1. : ((fc > 0.) ? 1. : 0.));
100  if ( fc == 0. || (b-a)*0.5 < ROL_EPSILON<Real>() ) {
101  break;
102  }
103  if ( sc == sa ) { a = c; fa = fc; sa = sc; }
104  else { b = c; }
105  }
106  return c;
107  }
108 
109  Real moment(const size_t m) const {
110  Real p = (Real)m;
111  Real a1 = std::pow(a_,p+1), b1 = std::pow(b_,p+1);
112  Real a2 = a1*a_, b2 = b1*b_;
113  Real a3 = a2*a_, b3 = b2*b_;
114  return 6./std::pow(b_-a_,3)
115  * (-(b3-a3)/(p+3) + (a_+b_)*(b2-a2)/(p+2) - a_*b_*(b1-a1)/(p+1));
116  }
117 
118  Real lowerBound(void) const {
119  return a_;
120  }
121 
122  Real upperBound(void) const {
123  return b_;
124  }
125 
126  void test(std::ostream &outStream = std::cout ) const {
127  size_t size = 5;
128  std::vector<Real> X(size,0.);
129  std::vector<int> T(size,0);
130  X[0] = a_-4.0*(Real)rand()/(Real)RAND_MAX;
131  T[0] = 0;
132  X[1] = a_;
133  T[1] = 1;
134  X[2] = (b_-a_)*(Real)rand()/(Real)RAND_MAX + a_;
135  T[2] = 0;
136  X[3] = b_;
137  T[3] = 1;
138  X[4] = b_+4.0*(Real)rand()/(Real)RAND_MAX;
139  T[4] = 0;
140  Distribution<Real>::test(X,T,outStream);
141  }
142 };
143 
144 }
145 
146 #endif
Parabolic(const Real a=0., const Real b=1.)
Real moment(const size_t m) const
Real lowerBound(void) const
Real integrateCDF(const Real input) const
Real evaluatePDF(const Real input) const
virtual void test(std::ostream &outStream=std::cout) const
Real invertCDF(const Real input) const
Real evaluateCDF(const Real input) const
void test(std::ostream &outStream=std::cout) const
Parabolic(ROL::ParameterList &parlist)
Real upperBound(void) const