20template <
typename RealType>
28 double halfNoncentrality = 0;
32 explicit RiceRand(
double offset = 0,
double scale = 1);
34 [[nodiscard]] std::string
Name()
const override;
36 [[nodiscard]] RealType
MinValue()
const override {
return 0; }
37 [[nodiscard]] RealType
MaxValue()
const override {
return INFINITY; }
40 [[nodiscard]]
double GetOffset() const noexcept {
return nu; }
41 [[nodiscard]]
double GetScale() const noexcept {
return sigma; }
43 [[nodiscard]]
double f(
const RealType &x)
const override;
44 [[nodiscard]]
double logf(
const RealType &x)
const override;
45 [[nodiscard]]
double F(
const RealType &x)
const override;
46 [[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
Mode()
const override;
56 std::complex<double> CFImpl(
double t)
const override;
64template <
typename RealType>
67 SetParameters(offset, scale);
70template <
typename RealType>
73 return "Rice(" + this->toStringWithPrecision(nu) +
", " + this->toStringWithPrecision(sigma) +
")";
76template <
typename RealType>
79 if (!(offset >= 0) || !std::isfinite(offset))
80 throw std::invalid_argument(
"Rice distribution: offset should be finite and non-negative");
81 if (!(scale > 0) || !std::isfinite(scale))
82 throw std::invalid_argument(
"Rice distribution: scale should be finite and positive");
85 const double standardizedOffset = nu / sigma;
86 halfNoncentrality = 0.5 * standardizedOffset * standardizedOffset;
87 logSigma = std::log(sigma);
90template <
typename RealType>
93 return (x > 0 && std::isfinite(x)) ? std::exp(logf(x)) : 0;
96template <
typename RealType>
99 if (!(x > 0) || !std::isfinite(x))
101 const double standardizedDifference = (
static_cast<double>(x) - nu) / sigma;
102 const double z = (
static_cast<double>(x) / sigma) * (nu / sigma);
103 double scaledLogBessel;
105 const double inverseZ = 1 / z;
106 const double series =
107 1 + inverseZ * (1.0 / 8 + inverseZ * (9.0 / 128 + inverseZ * (225.0 / 3072 + inverseZ * 11025.0 / 98304)));
112 return std::log(
static_cast<double>(x)) - 2 * logSigma - 0.5 * standardizedDifference * standardizedDifference +
116template <
typename RealType>
123 const double standardizedX =
static_cast<double>(x) / sigma;
124 const double halfX = 0.5 * standardizedX * standardizedX;
125 if (halfNoncentrality == 0)
126 return -std::expm1(-halfX);
130template <
typename RealType>
137 const double standardizedX =
static_cast<double>(x) / sigma;
138 const double halfX = 0.5 * standardizedX * standardizedX;
139 if (halfNoncentrality == 0)
140 return std::exp(-halfX);
144template <
typename RealType>
145template <std::uniform_random_bit_generator G>
150 return std::hypot(y, z);
153template <
typename RealType>
156 for (RealType &value : outputData)
160template <
typename RealType>
163 const long double k = halfNoncentrality;
164 const long double h = 0.5L * k;
167 static constexpr long double HANKEL_ARGUMENT = 50;
168 long double scaledI0 = 0, ratio = 0;
169 if (h > HANKEL_ARGUMENT) {
170 const long double logSeries0 = math::detail::logHankelSeries<long double>(0, h, -1);
171 scaledI0 = std::exp(logSeries0) / std::sqrt(2 *
static_cast<long double>(
randlib::consts::pi) * h);
172 ratio = std::exp(math::detail::logHankelSeries<long double>(1, h, -1) - logSeries0);
175 scaledI0 = std::exp(logI0 - h);
178 return static_cast<long double>(sigma) * std::sqrt(
randlib::consts::pi / 2.0L) * scaledI0 * (1 + k + k * ratio);
181template <
typename RealType>
184 const long double mean = Mean();
185 return 2 *
static_cast<long double>(sigma) * sigma +
static_cast<long double>(nu) * nu - mean * mean;
188template <
typename RealType>
194template <
typename RealType>
197 return this->integrateCharacteristicFunction(t);
The ContinuousDistribution class Abstract class for all continuous distributions.
Definition continuous.hpp:22
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition continuous.hpp:285
Rice distribution.
Definition rice.hpp:22
RiceRand(double offset=0, double scale=1)
Definition rice.hpp:65
RealType MinValue() const override
Definition rice.hpp:36
RealType operator()(G &g) const
Definition rice.hpp:146
std::string Name() const override
Definition rice.hpp:71
long double Variance() const override
Definition rice.hpp:182
Support SupportType() const override
Definition rice.hpp:35
double logf(const RealType &x) const override
Definition rice.hpp:97
RealType Mode() const override
Mode is the value, which has the largest probability to happen, or, in the case of continuous distrib...
Definition rice.hpp:189
double f(const RealType &x) const override
Definition rice.hpp:91
double GetOffset() const noexcept
Definition rice.hpp:40
double F(const RealType &x) const override
Definition rice.hpp:117
long double Mean() const override
Definition rice.hpp:161
RealType MaxValue() const override
Definition rice.hpp:37
double S(const RealType &x) const override
Definition rice.hpp:131
double GetScale() const noexcept
Definition rice.hpp:41
void SetParameters(double offset, double scale)
Definition rice.hpp:77
The EngineRef class Non-owning, type-erased reference to any uniform random bit generator.
Definition engine/uniform.hpp:116
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 logBesselI(std::type_identity_t< Real > nu, Real x)
Calculates logarithm of modified Bessel function of the 1st kind.
Definition functions.hpp:577
Real MarcumP(std::type_identity_t< Real > mu, Real x, std::type_identity_t< Real > y, std::type_identity_t< Real > sqrtX, std::type_identity_t< Real > sqrtY, std::type_identity_t< Real > logX, std::type_identity_t< Real > logY)
Definition functions.hpp:1023
Real MarcumQ(std::type_identity_t< Real > mu, Real x, std::type_identity_t< Real > y, std::type_identity_t< Real > sqrtX, std::type_identity_t< Real > sqrtY, std::type_identity_t< Real > logX, std::type_identity_t< Real > logY)
Definition functions.hpp:1079
Definition bivariate_normal.hpp:10
Support
Shape of the support of a univariate distribution.
Definition univariate.hpp:15