ROL
ROL_Gumbel.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_GUMBEL_HPP
11#define ROL_GUMBEL_HPP
12
13#include "ROL_Distribution.hpp"
14#include "ROL_ParameterList.hpp"
15
16namespace ROL {
17
18template<class Real>
19class Gumbel : public Distribution<Real> {
20private:
21 Real loc_;
22 Real scale_;
23
24 void checkInputs(const Real loc, const Real scale) const {
25 if (scale <= static_cast<Real>(0)) {
26 throw Exception::NotImplemented(">>> (Gumbel::Gumbel): Scale must be greater than zero!");
27 }
28 }
29
30public:
31 Gumbel(const Real loc = 0., const Real scale = 1.)
32 : loc_(loc), scale_(scale) {
34 }
35
36 Gumbel(ROL::ParameterList &parlist) {
37 loc_ = parlist.sublist("SOL").sublist("Distribution").sublist("Gumbel").get("Location",0.);
38 scale_ = parlist.sublist("SOL").sublist("Distribution").sublist("Gumbel").get("Scale",1.);
40 }
41
42 Real evaluatePDF(const Real input) const {
43 Real z = (x-loc_)/scale_;
44 return std::exp(-(z+exp(-z)))/scale_;
45 }
46
47 Real evaluateCDF(const Real input) const {
48 Real z = (x-loc_)/scale_;
49 return std::exp(-std::exp(-z));
50 }
51
52 Real integrateCDF(const Real input) const {
53 throw Exception::NotImplemented(">>> (Gumbel::integrateCDF): Not implemented!");
54 return static_cast<Real>(0);
55 }
56
57 Real invertCDF(const Real input) const {
58 return loc_ - scale_*std::log(-std::log(input));
59 }
60
61 Real moment(const size_t m) const {
62 Real val(0), gamma(0.57721566490153286);
63 if (m==1) {
64 val = loc_+scale_*gamma;
65 }
66 else if (m==2) {
67 Real pi(M_PI), six(6);
68 val = std::pow(scale_*pi,2)/six + std::pow(loc_+scale_*gamma,2);
69 }
70 else {
71 throw Exception::NotImplemented(">>> (Gumbel::moment): Moment is only implemented for m=1,2!");
72 }
73 return val;
74 }
75
76 Real lowerBound(void) const {
77 return ROL_NINF<Real>();
78 }
79
80 Real upperBound(void) const {
81 return ROL_INF<Real>();
82 }
83
84 void test(std::ostream &outStream = std::cout ) const {
85 size_t size = 3;
86 std::vector<Real> X(size,0.);
87 std::vector<int> T(size,0);
88 X[0] = loc_-4.0*(Real)rand()/(Real)RAND_MAX;
89 T[0] = 0;
90 X[1] = loc_;
91 T[1] = 1;
92 X[2] = loc_+4.0*(Real)rand()/(Real)RAND_MAX;
93 T[2] = 0;
94 Distribution<Real>::test(X,T,outStream);
95 }
96};
97
98}
99
100#endif
virtual void test(std::ostream &outStream=std::cout) const
Real moment(const size_t m) const
Real evaluateCDF(const Real input) const
void test(std::ostream &outStream=std::cout) const
Gumbel(const Real loc=0., const Real scale=1.)
Real integrateCDF(const Real input) const
Real invertCDF(const Real input) const
void checkInputs(const Real loc, const Real scale) const
Real evaluatePDF(const Real input) const
Real upperBound(void) const
Gumbel(ROL::ParameterList &parlist)
Real lowerBound(void) const