ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
distribution
ROL_TruncatedExponential.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_TRUNCATEDEXPONENTIAL_HPP
11
#define ROL_TRUNCATEDEXPONENTIAL_HPP
12
13
#include "
ROL_Distribution.hpp
"
14
#include "ROL_ParameterList.hpp"
15
16
namespace
ROL
{
17
18
template
<
class
Real>
19
class
TruncatedExponential
:
public
Distribution
<Real> {
20
private
:
21
Real
a_
;
22
Real
b_
;
23
Real
scale_
;
24
Real
expa_
;
25
Real
expb_
;
26
Real
diff_
;
27
Real
coeff_
;
28
29
size_t
compute_coeff
(
const
size_t
m,
const
size_t
k)
const
{
30
if
( k == m || m == 0 || m == 1 ) {
31
return
1;
32
}
33
size_t
val = 1;
34
for
(
size_t
i = k; i < m; i++) {
35
val *= (i+1);
36
}
37
return
val;
38
}
39
40
public
:
41
TruncatedExponential
(
const
Real a = 0.,
const
Real b = 1.,
const
Real scale = 1.)
42
:
a_
(std::min(a,b)),
b_
(std::max(a,b)),
scale_
((scale>0.) ? scale : 1.) {
43
expa_
= std::exp(-
scale_
*
a_
);
44
expb_
= std::exp(-
scale_
*
b_
);
45
diff_
=
expa_
-
expb_
;
46
coeff_
=
scale_
/
diff_
;
47
}
48
49
TruncatedExponential
(ROL::ParameterList &parlist) {
50
ROL::ParameterList TElist
51
= parlist.sublist(
"SOL"
).sublist(
"Distribution"
).sublist(
"Truncated Exponential"
);
52
a_
= TElist.get(
"Lower Bound"
,0.);
53
b_
= TElist.get(
"Upper Bound"
,1.);
54
Real tmp =
a_
;
55
a_
= std::min(
a_
,
b_
);
56
b_
= std::max(
b_
,tmp);
57
scale_
= TElist.get(
"Scale"
,1.);
58
scale_
= (
scale_
> 0.) ?
scale_
: 1.;
59
expa_
= std::exp(-
scale_
*
a_
);
60
expb_
= std::exp(-
scale_
*
b_
);
61
diff_
=
expa_
-
expb_
;
62
coeff_
=
scale_
/
diff_
;
63
}
64
65
Real
evaluatePDF
(
const
Real input)
const
{
66
return
((input >=
a_
) ? ((input <=
b_
) ?
coeff_
*std::exp(-
scale_
*input) : 0.) : 0.);
67
}
68
69
Real
evaluateCDF
(
const
Real input)
const
{
70
return
((input >
a_
) ? ((input <
b_
) ? (
expa_
-std::exp(-
scale_
*input))/
diff_
: 1.) : 0.);
71
}
72
73
Real
integrateCDF
(
const
Real input)
const
{
74
return
((input >
a_
) ? ((input <
b_
) ?
75
(
expa_
*(input-
a_
) - (
expa_
- std::exp(-
scale_
*input))/
scale_
)/
diff_
:
76
(
expa_
*(
b_
-
a_
) - (
expa_
-
expb_
)/
scale_
)/
diff_
+ (input -
b_
)) : 0.);
77
}
78
79
Real
invertCDF
(
const
Real input)
const
{
80
return
((input > 0.) ? ((input < 1.) ? -std::log(
expa_
-
diff_
*input)/
scale_
:
b_
) :
a_
);
81
}
82
83
Real
moment
(
const
size_t
m)
const
{
84
Real val = 0., coeff = 0.;
85
for
(
size_t
i = 0; i < m+1; i++) {
86
coeff =
compute_coeff
(m,i);
87
val += coeff*(std::pow(
a_
,i)*
expa_
-std::pow(
b_
,i)*
expb_
)/std::pow(
scale_
,m-i+1);
88
}
89
return
coeff_
*val;
90
}
91
92
Real
lowerBound
(
void
)
const
{
93
return
a_
;
94
}
95
96
Real
upperBound
(
void
)
const
{
97
return
b_
;
98
}
99
100
void
test
(std::ostream &outStream = std::cout )
const
{
101
size_t
size = 5;
102
std::vector<Real> X(size,0.);
103
std::vector<int> T(size,0);
104
X[0] =
a_
-4.0*(Real)rand()/(Real)RAND_MAX;
105
T[0] = 0;
106
X[1] =
a_
;
107
T[1] = 1;
108
X[2] = (
b_
-
a_
)*(Real)rand()/(Real)RAND_MAX +
a_
;
109
T[2] = 0;
110
X[3] =
b_
;
111
T[3] = 1;
112
X[4] =
b_
+4.0*(Real)rand()/(Real)RAND_MAX;
113
T[4] = 0;
114
Distribution<Real>::test
(X,T,outStream);
115
}
116
};
117
118
}
119
120
#endif
ROL_Distribution.hpp
ROL::Distribution
Definition
ROL_Distribution.hpp:21
ROL::Distribution::test
virtual void test(std::ostream &outStream=std::cout) const
Definition
ROL_Distribution.hpp:60
ROL::TruncatedExponential::b_
Real b_
Definition
ROL_TruncatedExponential.hpp:22
ROL::TruncatedExponential::integrateCDF
Real integrateCDF(const Real input) const
Definition
ROL_TruncatedExponential.hpp:73
ROL::TruncatedExponential::diff_
Real diff_
Definition
ROL_TruncatedExponential.hpp:26
ROL::TruncatedExponential::upperBound
Real upperBound(void) const
Definition
ROL_TruncatedExponential.hpp:96
ROL::TruncatedExponential::moment
Real moment(const size_t m) const
Definition
ROL_TruncatedExponential.hpp:83
ROL::TruncatedExponential::invertCDF
Real invertCDF(const Real input) const
Definition
ROL_TruncatedExponential.hpp:79
ROL::TruncatedExponential::compute_coeff
size_t compute_coeff(const size_t m, const size_t k) const
Definition
ROL_TruncatedExponential.hpp:29
ROL::TruncatedExponential::test
void test(std::ostream &outStream=std::cout) const
Definition
ROL_TruncatedExponential.hpp:100
ROL::TruncatedExponential::lowerBound
Real lowerBound(void) const
Definition
ROL_TruncatedExponential.hpp:92
ROL::TruncatedExponential::scale_
Real scale_
Definition
ROL_TruncatedExponential.hpp:23
ROL::TruncatedExponential::expb_
Real expb_
Definition
ROL_TruncatedExponential.hpp:25
ROL::TruncatedExponential::coeff_
Real coeff_
Definition
ROL_TruncatedExponential.hpp:27
ROL::TruncatedExponential::TruncatedExponential
TruncatedExponential(const Real a=0., const Real b=1., const Real scale=1.)
Definition
ROL_TruncatedExponential.hpp:41
ROL::TruncatedExponential::evaluateCDF
Real evaluateCDF(const Real input) const
Definition
ROL_TruncatedExponential.hpp:69
ROL::TruncatedExponential::expa_
Real expa_
Definition
ROL_TruncatedExponential.hpp:24
ROL::TruncatedExponential::a_
Real a_
Definition
ROL_TruncatedExponential.hpp:21
ROL::TruncatedExponential::evaluatePDF
Real evaluatePDF(const Real input) const
Definition
ROL_TruncatedExponential.hpp:65
ROL::TruncatedExponential::TruncatedExponential
TruncatedExponential(ROL::ParameterList &parlist)
Definition
ROL_TruncatedExponential.hpp:49
ROL
Definition
ROL_ElementwiseVector.hpp:27
Generated by
1.17.0