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 "Teuchos_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 
62  size_t nchoosek(const size_t n, const size_t k) const {
63  return ((k==0) ? 1 : (n*nchoosek(n-1,k-1))/k);
64  }
65 
66 public:
67  Kumaraswamy(const Real a = 0., const Real b = 1.,
68  const Real exp1 = 0.5, const Real exp2 = 0.5)
69  : a_(std::min(a,b)), b_(std::max(a,b)),
70  exp1_((exp1>0.) ? exp1 : 0.5), exp2_((exp2>0.) ? exp2 : 0.5) {}
71 
72  Kumaraswamy(Teuchos::ParameterList &parlist) {
73  a_ = parlist.sublist("SOL").sublist("Distribution").sublist("Kumaraswamy").get("Lower Bound",0.);
74  b_ = parlist.sublist("SOL").sublist("Distribution").sublist("Kumaraswamy").get("Upper Bound",1.);
75  Real tmp = a_;
76  a_ = std::min(a_,b_);
77  b_ = std::max(b_,tmp);
78 
79  exp1_ = parlist.sublist("SOL").sublist("Distribution").sublist("Kumaraswamy").get("Exponent 1",0.5);
80  exp1_ = parlist.sublist("SOL").sublist("Distribution").sublist("Kumaraswamy").get("Exponent 2",0.5);
81  exp1_ = (exp1_ > 0.) ? exp1_ : 0.5;
82  exp2_ = (exp2_ > 0.) ? exp2_ : 0.5;
83  }
84 
85  Real evaluatePDF(const Real input) const {
86  Real x = (input - a_)/(b_-a_);
87  return ((x <= 0.) ? 0. : ((x >= 1.) ? 0. :
88  exp1_*exp2_*std::pow(x,exp1_-1)*std::pow(1.-std::pow(x,exp1_),exp2_-1)));
89  }
90 
91  Real evaluateCDF(const Real input) const {
92  Real x = (input - a_)/(b_-a_);
93  return ((x <= 0.) ? 0. : ((x >= 1.) ? 1. : 1.-std::pow(1.-std::pow(x,exp1_),exp2_)));
94  }
95 
96  Real integrateCDF(const Real input) const {
97  TEUCHOS_TEST_FOR_EXCEPTION( true, std::invalid_argument,
98  ">>> ERROR (ROL::Kumaraswamy): Kumaraswamy integrateCDF not implemented!");
99  return ((input < 0.5*(a_+b_)) ? 0.0 : input - 0.5*(a_+b_));
100  }
101 
102  Real invertCDF(const Real input) const {
103  Real x = std::pow(1.-std::pow(1.-input,1./exp2_),1./exp1_);
104  return x*(b_-a_) + a_;
105  }
106 
107  Real moment(const size_t m) const {
108  Real val = 0., binom = 0., moment = 0.;
109  for (size_t i = 0; i < m; i++) {
110  moment = exp2_*tgamma(1.+(Real)i/exp1_)*tgamma(exp2_)/tgamma(1.+exp2_+(Real)i/exp1_);
111  binom = (Real)nchoosek(m,i);
112  val += binom*std::pow(a_,m-i)*std::pow(b_-a_,i+1)*moment;
113  }
114  return val;
115  }
116 
117  void test(std::ostream &outStream = std::cout ) const {
118  size_t size = 5;
119  std::vector<Real> X(size,0.);
120  std::vector<int> T(size,0);
121  X[0] = a_-4.*(Real)rand()/(Real)RAND_MAX;
122  T[0] = 0;
123  X[1] = a_;
124  T[1] = 1;
125  X[2] = (b_-a_)*(Real)rand()/(Real)RAND_MAX + a_;
126  T[2] = 0;
127  X[3] = b_;
128  T[3] = 1;
129  X[4] = b_+4.0*(Real)rand()/(Real)RAND_MAX;
130  T[4] = 0;
131  Distribution<Real>::test(X,T,outStream);
132  }
133 };
134 
135 }
136 
137 #endif
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
virtual void test(std::ostream &outStream=std::cout) const
Real evaluatePDF(const Real input) const
void test(std::ostream &outStream=std::cout) const
Real evaluateCDF(const Real input) const
Kumaraswamy(Teuchos::ParameterList &parlist)