ROL
ROL_Arcsine.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_ARCSINE_HPP
11 #define ROL_ARCSINE_HPP
12 
13 #include "ROL_Distribution.hpp"
14 #include "ROL_ParameterList.hpp"
15 
16 namespace ROL {
17 
18 template<class Real>
19 class Arcsine : public Distribution<Real> {
20 private:
21  Real a_;
22  Real b_;
23 
24 public:
25  Arcsine(const Real a = 0., const Real b = 1.)
26  : a_(std::min(a,b)), b_(std::max(a,b)) {}
27 
28  Arcsine(ROL::ParameterList &parlist) {
29  a_ = parlist.sublist("SOL").sublist("Distribution").sublist("Arcsine").get("Lower Bound",0.);
30  b_ = parlist.sublist("SOL").sublist("Distribution").sublist("Arcsine").get("Upper Bound",1.);
31  Real tmp = a_;
32  a_ = std::min(a_,b_);
33  b_ = std::max(b_,tmp);
34  }
35 
36  Real evaluatePDF(const Real input) const {
37  return ((input <= a_) ? 0. : ((input >= b_) ? 0. :
38  1./(ROL::ScalarTraits<Real>::pi()*std::sqrt((input-a_)*(b_-input)))));
39  }
40 
41  Real evaluateCDF(const Real input) const {
42  return ((input <= a_) ? 0. : ((input >= b_) ? 1. :
43  2./ROL::ScalarTraits<Real>::pi() * asin(std::sqrt((input-a_)/(b_-a_)))));
44  }
45  Real integrateCDF(const Real input) const {
46  ROL_TEST_FOR_EXCEPTION( true, std::invalid_argument,
47  ">>> ERROR (ROL::Arcsine): Arcsine integrateCDF not implemented!");
48  }
49 
50  Real invertCDF(const Real input) const {
51  Real x = std::pow(std::sin(0.5*ROL::ScalarTraits<Real>::pi()*input),2);
52  return x*(b_-a_) + a_;
53  }
54 
55  Real moment(const size_t m) const {
56  Real mean = 0.5*(a_+b_);
57  Real val = 0.0;
58  switch(m) {
59  case 1: val = mean; break;
60  case 2: val = std::pow(b_-a_,2)/8. + mean*mean; break;
61  default:
62  ROL_TEST_FOR_EXCEPTION( true, std::invalid_argument,
63  ">>> ERROR (ROL::Arcsine): Arcsine moment not implemented for m > 2!");
64  }
65  return val;
66  }
67 
68  Real lowerBound(void) const {
69  return a_;
70  }
71 
72  Real upperBound(void) const {
73  return b_;
74  }
75 
76  void test(std::ostream &outStream = std::cout ) const {
77  size_t size = 5;
78  std::vector<Real> X(size,0.);
79  std::vector<int> T(size,0);
80  X[0] = a_-4.*(Real)rand()/(Real)RAND_MAX;
81  T[0] = 0;
82  X[1] = a_;
83  T[1] = 1;
84  X[2] = (b_-a_)*(Real)rand()/(Real)RAND_MAX + a_;
85  T[2] = 0;
86  X[3] = b_;
87  T[3] = 1;
88  X[4] = b_+4.*(Real)rand()/(Real)RAND_MAX;
89  T[4] = 0;
90  Distribution<Real>::test(X,T,outStream);
91  }
92 };
93 
94 }
95 
96 #endif
Arcsine(ROL::ParameterList &parlist)
Definition: ROL_Arcsine.hpp:28
Arcsine(const Real a=0., const Real b=1.)
Definition: ROL_Arcsine.hpp:25
Real evaluateCDF(const Real input) const
Definition: ROL_Arcsine.hpp:41
Real lowerBound(void) const
Definition: ROL_Arcsine.hpp:68
void test(std::ostream &outStream=std::cout) const
Definition: ROL_Arcsine.hpp:76
Real integrateCDF(const Real input) const
Definition: ROL_Arcsine.hpp:45
Real evaluatePDF(const Real input) const
Definition: ROL_Arcsine.hpp:36
Real moment(const size_t m) const
Definition: ROL_Arcsine.hpp:55
virtual void test(std::ostream &outStream=std::cout) const
Real upperBound(void) const
Definition: ROL_Arcsine.hpp:72
Real invertCDF(const Real input) const
Definition: ROL_Arcsine.hpp:50