ROL
ROL_Smale.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_SMALE_HPP
11#define ROL_SMALE_HPP
12
13#include "ROL_Distribution.hpp"
14#include "ROL_ParameterList.hpp"
15
16namespace ROL {
17
18template<class Real>
19class Smale : public Distribution<Real> {
20private:
21 Real a_;
22 Real b_;
23
24public:
25 Smale(const Real a = 0., const Real b = 1.)
26 : a_(std::min(a,b)), b_(std::max(a,b)) {}
27
28 Smale(ROL::ParameterList &parlist) {
29 a_ = parlist.sublist("SOL").sublist("Distribution").sublist("Smale").get("Lower Bound",0.);
30 b_ = parlist.sublist("SOL").sublist("Distribution").sublist("Smale").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 Real val = std::pow(input-a_,2)+4.*b_*b_;
38 Real root = std::sqrt(val);
39 return 2.0*b_*b_/(val*root);
40 }
41
42 Real evaluateCDF(const Real input) const {
43 Real val = std::pow(input-a_,2)+4.*b_*b_;
44 Real root = std::sqrt(val);
45 return 0.5*(1.0+input/root);
46 }
47
48 Real integrateCDF(const Real input) const {
49 Real val = std::pow(input-a_,2)+4.*b_*b_;
50 Real root = std::sqrt(val);
51 return 0.5*(input+root);
52 }
53
54 Real invertCDF(const Real input) const {
55 Real x = a_;
56 Real fx = evaluateCDF(x)-input;
57 Real s = 0.0;
58 Real xs = 0.0;
59 Real a = 1.0;
60 Real tmp = 0.0;
61 for (int i = 0; i < 100; i++) {
62 if ( std::abs(fx) < ROL_EPSILON<Real>() ) { break; }
63 s = -fx/evaluatePDF(x);
64 a = 1.0;
65 xs = x + a*s;
66 tmp = fx;
67 fx = evaluateCDF(xs)-input;
68 while ( std::abs(fx) > (1.0 - 1.e-4*a)*std::abs(tmp) ) {
69 a *= 0.5;
70 xs = x + a*s;
71 fx = evaluateCDF(xs)-input;
72 }
73 x = xs;
74 }
75 return x;
76 }
77
78 Real moment(const size_t m) const {
79 ROL_TEST_FOR_EXCEPTION( true, std::invalid_argument,
80 ">>> ERROR (ROL::Smale): Smale moment is not implemented!");
81 }
82
83 Real lowerBound(void) const {
84 return ROL_NINF<Real>();
85 }
86
87 Real upperBound(void) const {
88 return ROL_INF<Real>();
89 }
90
91 void test(std::ostream &outStream = std::cout ) const {
92 size_t size = 1;
93 std::vector<Real> X(size,4.*(Real)rand()/(Real)RAND_MAX - 2.);
94 std::vector<int> T(size,0);
95 Distribution<Real>::test(X,T,outStream);
96 }
97};
98
99}
100
101#endif
virtual void test(std::ostream &outStream=std::cout) const
Real upperBound(void) const
Definition ROL_Smale.hpp:87
Real lowerBound(void) const
Definition ROL_Smale.hpp:83
Smale(ROL::ParameterList &parlist)
Definition ROL_Smale.hpp:28
Smale(const Real a=0., const Real b=1.)
Definition ROL_Smale.hpp:25
void test(std::ostream &outStream=std::cout) const
Definition ROL_Smale.hpp:91
Real integrateCDF(const Real input) const
Definition ROL_Smale.hpp:48
Real evaluateCDF(const Real input) const
Definition ROL_Smale.hpp:42
Real evaluatePDF(const Real input) const
Definition ROL_Smale.hpp:36
Real moment(const size_t m) const
Definition ROL_Smale.hpp:78
Real invertCDF(const Real input) const
Definition ROL_Smale.hpp:54