ROL
ROL_Kumaraswamy.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_KUMARASWAMY_HPP
45 #define ROL_KUMARASWAMY_HPP
46 
47 #include "ROL_Distribution.hpp"
48 #include "ROL_ParameterList.hpp"
49 
50 #include <math.h>
51 
52 namespace ROL {
53 
54 template<class Real>
55 class Kumaraswamy : public Distribution<Real> {
56 private:
57  Real a_;
58  Real b_;
59  Real exp1_;
60  Real exp2_;
61  Real bGAMMAb_;
62 
63  size_t nchoosek(const size_t n, const size_t k) const {
64  return ((k==0) ? 1 : (n*nchoosek(n-1,k-1))/k);
65  }
66 
67 public:
68  Kumaraswamy(const Real a = 0., const Real b = 1.,
69  const Real exp1 = 0.5, const Real exp2 = 0.5)
70  : a_(std::min(a,b)), b_(std::max(a,b)),
71  exp1_((exp1>0.) ? exp1 : 0.5), exp2_((exp2>0.) ? exp2 : 0.5) {
72  bGAMMAb_ = exp2_*tgamma(exp2_);
73  }
74 
75  Kumaraswamy(ROL::ParameterList &parlist) {
76  a_ = parlist.sublist("SOL").sublist("Distribution").sublist("Kumaraswamy").get("Lower Bound",0.);
77  b_ = parlist.sublist("SOL").sublist("Distribution").sublist("Kumaraswamy").get("Upper Bound",1.);
78  Real tmp = a_;
79  a_ = std::min(a_,b_);
80  b_ = std::max(b_,tmp);
81 
82  exp1_ = parlist.sublist("SOL").sublist("Distribution").sublist("Kumaraswamy").get("Exponent 1",0.5);
83  exp2_ = parlist.sublist("SOL").sublist("Distribution").sublist("Kumaraswamy").get("Exponent 2",0.5);
84  exp1_ = (exp1_ > 0.) ? exp1_ : 0.5;
85  exp2_ = (exp2_ > 0.) ? exp2_ : 0.5;
86 
87  bGAMMAb_ = exp2_*tgamma(exp2_);
88  }
89 
90  Real evaluatePDF(const Real input) const {
91  Real x = (input - a_)/(b_-a_);
92  return ((x <= 0.) ? 0. : ((x >= 1.) ? 0. :
93  exp1_*exp2_*std::pow(x,exp1_-1)*std::pow(1.-std::pow(x,exp1_),exp2_-1)));
94  }
95 
96  Real evaluateCDF(const Real input) const {
97  Real x = (input - a_)/(b_-a_);
98  return ((x <= 0.) ? 0. : ((x >= 1.) ? 1. : 1.-std::pow(1.-std::pow(x,exp1_),exp2_)));
99  }
100 
101  Real integrateCDF(const Real input) const {
102  ROL_TEST_FOR_EXCEPTION( true, std::invalid_argument,
103  ">>> ERROR (ROL::Kumaraswamy): Kumaraswamy integrateCDF not implemented!");
104  }
105 
106  Real invertCDF(const Real input) const {
107  Real x = std::pow(1.-std::pow(1.-input,1./exp2_),1./exp1_);
108  return x*(b_-a_) + a_;
109  }
110 
111  Real moment(const size_t m) const {
112  Real val = 0., binom = 0., moment = 0.;
113  for (size_t i = 0; i < m+1; i++) {
114  moment = bGAMMAb_*tgamma(1.+(Real)i/exp1_)/tgamma(1.+exp2_+(Real)i/exp1_);
115  binom = (Real)nchoosek(m,i);
116  val += binom*std::pow(a_,m-i)*std::pow(b_-a_,i+1)*moment;
117  }
118  return val;
119  }
120 
121  Real lowerBound(void) const {
122  return a_;
123  }
124 
125  Real upperBound(void) const {
126  return b_;
127  }
128 
129  void test(std::ostream &outStream = std::cout ) const {
130  size_t size = 5;
131  std::vector<Real> X(size,0.);
132  std::vector<int> T(size,0);
133  X[0] = a_-4.*(Real)rand()/(Real)RAND_MAX;
134  T[0] = 0;
135  X[1] = a_;
136  T[1] = 1;
137  X[2] = (b_-a_)*(Real)rand()/(Real)RAND_MAX + a_;
138  T[2] = 0;
139  X[3] = b_;
140  T[3] = 1;
141  X[4] = b_+4.0*(Real)rand()/(Real)RAND_MAX;
142  T[4] = 0;
143  Distribution<Real>::test(X,T,outStream);
144  }
145 };
146 
147 }
148 
149 #endif
Kumaraswamy(ROL::ParameterList &parlist)
Kumaraswamy(const Real a=0., const Real b=1., const Real exp1=0.5, const Real exp2=0.5)
Real invertCDF(const Real input) const
Real integrateCDF(const Real input) const
Real moment(const size_t m) const
size_t nchoosek(const size_t n, const size_t k) const
Real lowerBound(void) const
virtual void test(std::ostream &outStream=std::cout) const
Real upperBound(void) const
Real evaluatePDF(const Real input) const
void test(std::ostream &outStream=std::cout) const
Real evaluateCDF(const Real input) const