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