RandLib 2.0.0
Probability distributions, fitting, and heavy-tail tools for C++20
Loading...
Searching...
No Matches
sech.hpp
Go to the documentation of this file.
1#pragma once
2
7
8namespace randlib
9{
10
17template <typename RealType>
18class SechRand final : public ContinuousDistribution<RealType>
19{
20 RealType variate(detail::EngineRef g) const override { return (*this)(g); }
21
22public:
23 SechRand();
24
25 [[nodiscard]] std::string Name() const override;
26 [[nodiscard]] Support SupportType() const override { return Support::Infinite; }
27 [[nodiscard]] RealType MinValue() const override { return -INFINITY; }
28 [[nodiscard]] RealType MaxValue() const override { return INFINITY; }
29
30 [[nodiscard]] double f(const RealType &x) const override;
31 [[nodiscard]] double logf(const RealType &x) const override;
32 [[nodiscard]] double F(const RealType &x) const override;
33 template <std::uniform_random_bit_generator G>
34 [[nodiscard]] RealType operator()(G &g) const;
35
36 [[nodiscard]] long double Mean() const override;
37 [[nodiscard]] long double Variance() const override;
38 [[nodiscard]] RealType Median() const override;
39 [[nodiscard]] RealType Mode() const override;
40 [[nodiscard]] long double Skewness() const override;
41 [[nodiscard]] long double ExcessKurtosis() const override;
42
43private:
44 RealType quantileImpl(double p) const override;
45 RealType quantileImpl1m(double p) const override;
46
47 std::complex<double> CFImpl(double t) const override;
48
49public:
50 [[nodiscard]] long double Entropy() const;
51};
52
53} // namespace randlib
54
56
57namespace randlib
58{
59
60template <typename RealType>
64
65template <typename RealType>
66std::string SechRand<RealType>::Name() const
67{
68 return "Hyperbolic secant";
69}
70
71template <typename RealType>
72double SechRand<RealType>::f(const RealType &x) const
73{
74 return 0.5 / std::cosh(randlib::consts::half_pi * x);
75}
76
77template <typename RealType>
78double SechRand<RealType>::logf(const RealType &x) const
79{
81}
82
83template <typename RealType>
84double SechRand<RealType>::F(const RealType &x) const
85{
86 double y = std::exp(randlib::consts::half_pi * x);
88}
89
90template <typename RealType>
91template <std::uniform_random_bit_generator G>
93{
94 RealType y = std::fabs(CauchyRand<RealType>::StandardVariate(g));
95 return randlib::consts::two_inv_pi * std::log(y);
96}
97
98template <typename RealType>
99long double SechRand<RealType>::Mean() const
100{
101 return 0.0;
102}
103
104template <typename RealType>
106{
107 return 1.0;
108}
109
110template <typename RealType>
111std::complex<double> SechRand<RealType>::CFImpl(double t) const
112{
113 return 1.0 / std::cosh(t);
114}
115
116template <typename RealType>
117RealType SechRand<RealType>::quantileImpl(double p) const
118{
119 RealType x = randlib::consts::half_pi * p;
120 x = std::tan(x);
121 x = std::log(x);
123}
124
125template <typename RealType>
126RealType SechRand<RealType>::quantileImpl1m(double p) const
127{
128 RealType x = randlib::consts::half_pi * p;
129 x = std::tan(x);
130 x = -std::log(x);
132}
133
134template <typename RealType>
136{
137 return 0.0;
138}
139
140template <typename RealType>
142{
143 return 0.0;
144}
145
146template <typename RealType>
148{
149 return 0.0;
150}
151
152template <typename RealType>
154{
155 return 2.0;
156}
157
158template <typename RealType>
163
164} // namespace randlib
The CauchyRand class Cauchy distribution.
Definition cauchy.hpp:26
The ContinuousDistribution class Abstract class for all continuous distributions.
Definition continuous.hpp:22
The SechRand class Hyperbolic secant distribution.
Definition sech.hpp:19
RealType MinValue() const override
Definition sech.hpp:27
RealType Median() const override
Definition sech.hpp:135
long double ExcessKurtosis() const override
Definition sech.hpp:153
RealType MaxValue() const override
Definition sech.hpp:28
long double Skewness() const override
Definition sech.hpp:147
double f(const RealType &x) const override
Definition sech.hpp:72
Support SupportType() const override
Definition sech.hpp:26
long double Mean() const override
Definition sech.hpp:99
double F(const RealType &x) const override
Definition sech.hpp:84
RealType operator()(G &g) const
Definition sech.hpp:92
std::string Name() const override
Definition sech.hpp:66
long double Variance() const override
Definition sech.hpp:105
double logf(const RealType &x) const override
Definition sech.hpp:78
long double Entropy() const
Definition sech.hpp:159
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition sech.hpp:141
SechRand()
Definition sech.hpp:61
The EngineRef class Non-owning, type-erased reference to any uniform random bit generator.
Definition engine/uniform.hpp:116
constexpr long double half_pi
Definition constants.hpp:23
constexpr long double catalan
Definition constants.hpp:38
constexpr long double pi
Definition constants.hpp:22
constexpr long double two_inv_pi
Definition constants.hpp:25
Real atan(Real x)
Definition functions.hpp:238
Real softplus(Real x)
Definition functions.hpp:252
Definition bivariate_normal.hpp:10
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15
@ Infinite
(-∞, ∞)