ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
sol
function
distribution
ROL_Exponential.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_EXPONENTIAL_HPP
11
#define ROL_EXPONENTIAL_HPP
12
13
#include "
ROL_Distribution.hpp
"
14
#include "ROL_ParameterList.hpp"
15
16
namespace
ROL
{
17
18
template
<
class
Real>
19
class
Exponential
:
public
Distribution
<Real> {
20
private
:
21
Real
loc_
;
22
Real
scale_
;
23
24
size_t
compute_coeff
(
const
size_t
m,
const
size_t
k)
const
{
25
if
( k == 0 || m == 0 || m == 1 ) {
26
return
1;
27
}
28
size_t
val = 1;
29
for
(
size_t
i = m-k; i < m; i++) {
30
val *= (i+1);
31
}
32
return
val;
33
}
34
35
public
:
36
Exponential
(
const
Real loc = 0.,
const
Real scale = 1.)
37
:
loc_
(loc),
scale_
((scale>0.) ? scale : 1.) {}
38
39
Exponential
(ROL::ParameterList &parlist) {
40
loc_
= parlist.sublist(
"SOL"
).sublist(
"Distribution"
).sublist(
"Exponential"
).get(
"Location"
,0.);
41
scale_
= parlist.sublist(
"SOL"
).sublist(
"Distribution"
).sublist(
"Exponential"
).get(
"Scale"
,1.);
42
scale_
= (
scale_
> 0.) ?
scale_
: 1.;
43
}
44
45
Real
evaluatePDF
(
const
Real input)
const
{
46
return
((input >=
loc_
) ?
scale_
*std::exp(-
scale_
*(input-
loc_
)) : 0.);
47
}
48
49
Real
evaluateCDF
(
const
Real input)
const
{
50
return
((input >=
loc_
) ? 1.-std::exp(-
scale_
*(input-
loc_
)) : 0.);
51
}
52
53
Real
integrateCDF
(
const
Real input)
const
{
54
return
((input >=
loc_
) ?
55
(input-
loc_
) - (1.-std::exp(-
scale_
*(input-
loc_
)))/
scale_
: 0.);
56
}
57
58
Real
invertCDF
(
const
Real input)
const
{
59
return
-std::log(1.-input)/
scale_
;
60
}
61
62
Real
moment
(
const
size_t
m)
const
{
63
Real val = 0., coeff = 0.;
64
for
(
size_t
i = 0; i < m+1; i++) {
65
coeff =
compute_coeff
(m,i);
66
val += coeff*std::pow(
loc_
,(Real)(m-i))/std::pow(
scale_
,(Real)i);
67
}
68
return
val;
69
}
70
71
Real
lowerBound
(
void
)
const
{
72
return
0.;
73
}
74
75
Real
upperBound
(
void
)
const
{
76
return
ROL_INF<Real>
();
77
}
78
79
void
test
(std::ostream &outStream = std::cout )
const
{
80
size_t
size = 3;
81
std::vector<Real> X(size,0.);
82
std::vector<int> T(size,0);
83
X[0] =
loc_
-4.0*(Real)rand()/(Real)RAND_MAX;
84
T[0] = 0;
85
X[1] =
loc_
;
86
T[1] = 1;
87
X[2] =
loc_
+4.0*(Real)rand()/(Real)RAND_MAX;
88
T[2] = 0;
89
Distribution<Real>::test
(X,T,outStream);
90
}
91
};
92
93
}
94
95
#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::Exponential::integrateCDF
Real integrateCDF(const Real input) const
Definition
ROL_Exponential.hpp:53
ROL::Exponential::invertCDF
Real invertCDF(const Real input) const
Definition
ROL_Exponential.hpp:58
ROL::Exponential::moment
Real moment(const size_t m) const
Definition
ROL_Exponential.hpp:62
ROL::Exponential::evaluatePDF
Real evaluatePDF(const Real input) const
Definition
ROL_Exponential.hpp:45
ROL::Exponential::Exponential
Exponential(const Real loc=0., const Real scale=1.)
Definition
ROL_Exponential.hpp:36
ROL::Exponential::compute_coeff
size_t compute_coeff(const size_t m, const size_t k) const
Definition
ROL_Exponential.hpp:24
ROL::Exponential::upperBound
Real upperBound(void) const
Definition
ROL_Exponential.hpp:75
ROL::Exponential::loc_
Real loc_
Definition
ROL_Exponential.hpp:21
ROL::Exponential::lowerBound
Real lowerBound(void) const
Definition
ROL_Exponential.hpp:71
ROL::Exponential::Exponential
Exponential(ROL::ParameterList &parlist)
Definition
ROL_Exponential.hpp:39
ROL::Exponential::scale_
Real scale_
Definition
ROL_Exponential.hpp:22
ROL::Exponential::evaluateCDF
Real evaluateCDF(const Real input) const
Definition
ROL_Exponential.hpp:49
ROL::Exponential::test
void test(std::ostream &outStream=std::cout) const
Definition
ROL_Exponential.hpp:79
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::ROL_INF
Real ROL_INF(void)
Definition
ROL_Types.hpp:71
Generated by
1.17.0