22template <
typename RealType>
34 [[nodiscard]] std::string
Name()
const override;
36 [[nodiscard]] RealType
MinValue()
const override {
return -INFINITY; }
37 [[nodiscard]] RealType
MaxValue()
const override {
return INFINITY; }
41 [[nodiscard]]
inline double GetLocation() const noexcept {
return mu; }
42 [[nodiscard]]
inline double GetScale() const noexcept {
return s; }
44 [[nodiscard]]
double f(
const RealType &x)
const override;
45 [[nodiscard]]
double logf(
const RealType &x)
const override;
46 [[nodiscard]]
double F(
const RealType &x)
const override;
47 [[nodiscard]]
double S(
const RealType &x)
const override;
48 template <std::uniform_random_bit_generator G>
51 [[nodiscard]]
long double Mean()
const override;
52 [[nodiscard]]
long double Variance()
const override;
53 [[nodiscard]] RealType
Median()
const override;
54 [[nodiscard]] RealType
Mode()
const override;
55 [[nodiscard]]
long double Skewness()
const override;
59 RealType quantileImpl(
double p)
const override;
60 RealType quantileImpl1m(
double p)
const override;
62 std::complex<double> CFImpl(
double t)
const override;
65 [[nodiscard]]
long double Entropy()
const;
81template <
typename RealType>
84 SetLocation(location);
88template <
typename RealType>
91 return "Logistic(" + this->toStringWithPrecision(GetLocation()) +
", " + this->toStringWithPrecision(GetScale()) +
95template <
typename RealType>
98 if (!std::isfinite(location))
99 throw std::invalid_argument(
"Logistic distribution: location should be finite");
103template <
typename RealType>
107 throw std::invalid_argument(
"Logistic distribution: scale of should be positive");
112template <
typename RealType>
116 double expMinusAbsZ = std::exp(-std::fabs(x - mu) / s);
117 double denominator = 1 + expMinusAbsZ;
118 return expMinusAbsZ / (denominator * denominator * s);
121template <
typename RealType>
124 double x0 = (mu - x) / s;
131template <
typename RealType>
134 double expX = std::exp((mu - x) / s);
135 return 1.0 / (1 + expX);
138template <
typename RealType>
141 double expX = std::exp((mu - x) / s);
142 return expX / (1 + expX);
145template <
typename RealType>
146template <std::uniform_random_bit_generator G>
153template <
typename RealType>
159template <
typename RealType>
163 return sPi * sPi / 3;
166template <
typename RealType>
170 std::complex<double> y(0.0, t * mu);
173 y /= std::sinh(pist);
177template <
typename RealType>
183template <
typename RealType>
186 return mu - s * (std::log1pl(-p) - std::log(p));
189template <
typename RealType>
190RealType LogisticRand<RealType>::quantileImpl1m(
double p)
const
192 return mu - s * (std::log(p) - std::log1pl(-p));
195template <
typename RealType>
201template <
typename RealType>
207template <
typename RealType>
213template <
typename RealType>
219template <
typename RealType>
222 double nHalf = 0.5 * sample.size();
224 if (!math::findRootNewtonFirstOrder<RealType>(
225 [
this, sample, nHalf](RealType m) {
226 double f1 = 0, f2 = 0;
227 for (
const RealType &x : sample) {
228 double aux = std::exp((m - x) / s);
229 double denom = 1.0 + aux;
The ContinuousDistribution class Abstract class for all continuous distributions.
Definition continuous.hpp:22
The LogisticRand class Logistic distribution.
Definition logistic.hpp:24
double logf(const RealType &x) const override
Definition logistic.hpp:122
double F(const RealType &x) const override
Definition logistic.hpp:132
long double Skewness() const override
Definition logistic.hpp:208
long double ExcessKurtosis() const override
Definition logistic.hpp:214
void FitLocation(std::span< const RealType > sample)
fit location parameter via maximum-likelihood
Definition logistic.hpp:220
double GetScale() const noexcept
Definition logistic.hpp:42
double S(const RealType &x) const override
Definition logistic.hpp:139
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition logistic.hpp:202
long double Variance() const override
Definition logistic.hpp:160
long double Entropy() const
Definition logistic.hpp:178
void SetLocation(double location)
Definition logistic.hpp:96
long double Mean() const override
Definition logistic.hpp:154
RealType Median() const override
Definition logistic.hpp:196
double GetLocation() const noexcept
Definition logistic.hpp:41
RealType MinValue() const override
Definition logistic.hpp:36
double f(const RealType &x) const override
Definition logistic.hpp:113
RealType MaxValue() const override
Definition logistic.hpp:37
std::string Name() const override
Definition logistic.hpp:89
Support SupportType() const override
Definition logistic.hpp:35
RealType operator()(G &g) const
Definition logistic.hpp:147
void SetScale(double scale)
Definition logistic.hpp:104
LogisticRand(double location=0, double scale=1)
Definition logistic.hpp:82
virtual void sample(detail::EngineRef g, std::span< T > outputData) const
Fills the output with variate(g); distributions with a faster bulk algorithm override it.
Definition distribution.hpp:66
The EngineRef class Non-owning, type-erased reference to any uniform random bit generator.
Definition engine/uniform.hpp:116
#define RANDLIB_DEPRECATED_FIT_MEMBER
Definition fwd.hpp:9
constexpr long double pi
Definition constants.hpp:22
Real standardNormal(G &g)
Ziggurat algorithm of Marsaglia and Tsang with 256 layers and an explicit sign bit.
Definition variates.hpp:45
Real softplus(Real x)
Definition functions.hpp:252
Definition bivariate_normal.hpp:10
@ Undefined
any other failure
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15
Pair< double > DoublePair
Definition fwd.hpp:39