32 #ifndef MCKL_RANDOM_STABLE_DISTRIBUTION_HPP 33 #define MCKL_RANDOM_STABLE_DISTRIBUTION_HPP 42 template <
typename RealType>
44 RealType alpha, RealType beta, RealType, RealType b)
70 template <typename RealType>
75 RealType alpha = 1, RealType beta = 0, RealType = 0, RealType b = 1)
84 RealType zeta = -beta *
std::tan(const_pi_by2<RealType>() * alpha);
88 xi_ = const_pi_by2<RealType>();
89 c_ = 1 / const_pi_by2<RealType>() *
std::log(b);
93 c_ =
std::pow(1 + zeta * zeta, 1 / (2 * alpha));
98 RealType
xi()
const {
return xi_; }
99 RealType
c()
const {
return c_; }
107 if (c1.xi_ != c2.xi_) {
110 if (c1.c_ != c2.c_) {
113 if (c1.algorithm_ != c2.algorithm_) {
128 template <std::
size_t K,
typename RealType,
typename RNGType>
130 RealType *r, RealType, RealType beta, RealType, RealType,
134 const RealType xi = constant.
xi();
135 const RealType c = constant.
c();
136 RealType *
const u = s.data();
137 RealType *
const w = s.data() + n;
138 RealType *
const t = s.data() + n * 2;
140 muladd(n, u, const_pi<RealType>(), -const_pi_by2<RealType>(), u);
143 mul(n, -const_one<RealType>(), w, w);
144 muladd(n, u, beta, const_pi_by2<RealType>(), t);
149 div(n, const_pi_by2<RealType>(), t, t);
151 muladd(n, t, -beta, r, r);
152 muladd(n, r, 1 / xi, c, r);
155 template <std::
size_t K,
typename RealType,
typename RNGType>
157 RealType *r, RealType alpha, RealType, RealType, RealType,
161 const RealType xi = constant.
xi();
162 const RealType c = constant.
c();
163 RealType *
const u = s.data();
164 RealType *
const w = s.data() + n;
165 RealType *
const p = s.data() + n * 2;
166 RealType *
const t = s.data() + n * 3;
168 muladd(n, u, const_pi<RealType>(), -const_pi_by2<RealType>(), u);
171 mul(n, -const_one<RealType>(), w, w);
172 muladd(n, u, alpha, alpha * xi, t);
175 pow(n, p, 1 / alpha, p);
180 pow(n, p, (1 - alpha) / alpha, p);
185 template <std::
size_t K,
typename RealType,
typename RNGType>
187 RealType alpha, RealType beta, RealType a, RealType b)
192 stable_distribution_impl_1<K>(
193 rng, n, r, alpha, beta, a, b, constant);
196 stable_distribution_impl_a<K>(
197 rng, n, r, alpha, beta, a, b, constant);
206 alpha, RealType, beta, RealType, a, RealType, b)
208 template <
typename RealType>
215 alpha, 1,
result_type, beta, 0,
result_type, a, 0,
result_type, b, 1)
220 return std::numeric_limits<result_type>::lowest();
228 alpha(), beta(), a(), b());
236 return constant_ == other.constant_;
239 template <
typename CharT,
typename Traits>
240 void ostream(std::basic_ostream<CharT, Traits> &)
const 244 template <
typename CharT,
typename Traits>
245 void istream(std::basic_istream<CharT, Traits> &)
250 template <
typename RNGType>
253 if (param == param_) {
254 return generate(rng, param_, constant_);
258 param.
alpha(), param.
beta(), param.
a(), param.
b());
260 return generate(rng, param, constant);
263 template <
typename RNGType>
270 r = generate_1(rng, param, constant);
273 r = generate_a(rng, param, constant);
277 return param.
a() + param.
b() * r;
280 template <
typename RNGType>
286 u01(rng) * const_pi<result_type>() - const_pi_by2<result_type>();
290 t = (const_pi_by2<result_type>() / t) * (w *
std::cos(u));
291 r -= param.
beta() * t;
293 return r / constant.
xi() + constant.
c();
296 template <
typename RNGType>
302 u01(rng) * const_pi<result_type>() - const_pi_by2<result_type>();
311 return r * constant.
c();
319 #endif // MCKL_RANDOM_STABLE_DISTRIBUTION_HPP StableDistributionAlgorithm
void pow(std::size_t n, const float *a, const float *b, float *y)
StableDistributionAlgorithm algorithm() const
void mul(std::size_t n, const float *a, const float *b, float *y)
void tan(std::size_t n, const float *a, float *y)
#define MCKL_PUSH_CLANG_WARNING(warning)
friend bool operator==(const StableDistributionConstant< RealType > &c1, const StableDistributionConstant< RealType > &c2)
void sin(std::size_t n, const float *a, float *y)
void log(std::size_t n, const float *a, float *y)
void stable_distribution_impl(RNGType &rng, std::size_t n, RealType *r, RealType alpha, RealType beta, RealType a, RealType b)
void u01_oo_distribution(RNGType &rng, std::size_t n, RealType *r)
#define MCKL_DEFINE_RANDOM_DISTRIBUTION_RAND(Name, T)
RealType u01(UIntType u)
Convert uniform unsigned integers to floating points within [0, 1].
std::basic_ostream< CharT, Traits > & ostream(std::basic_ostream< CharT, Traits > &os, const std::array< T, N > &ary)
void stable_distribution_impl_a(RNGType &rng, std::size_t n, RealType *r, RealType alpha, RealType, RealType, RealType, const StableDistributionConstant< RealType > &constant)
void sub(std::size_t n, const float *a, const float *b, float *y)
Standard uniform distribution on (0, 1)
#define MCKL_PUSH_INTEL_WARNING(wid)
StableDistributionConstant(RealType alpha=1, RealType beta=0, RealType=0, RealType b=1)
void stable_distribution_impl_1(RNGType &rng, std::size_t n, RealType *r, RealType, RealType beta, RealType, RealType, const StableDistributionConstant< RealType > &constant)
void cos(std::size_t n, const float *a, float *y)
void atan(std::size_t n, const float *a, float *y)
#define MCKL_DEFINE_RANDOM_DISTRIBUTION_4( Name, name, T, T1, p1, v1, T2, p2, v2, T3, p3, v3, T4, p4, v4)
#define MCKL_POP_CLANG_WARNING
#define MCKL_ALIGNMENT
The default alignment for scalar type.
bool is_equal(const float &v1, const float &v2)
#define MCKL_DEFINE_RANDOM_DISTRIBUTION_ASSERT_REAL_TYPE(Name)
std::basic_istream< CharT, Traits > & istream(std::basic_istream< CharT, Traits > &is, std::array< T, N > &ary)
#define MCKL_DEFINE_RANDOM_DISTRIBUTION_BATCH_4( Name, name, T, T1, p1, T2, p2, T3, p3, T4, p4)
result_type alpha() const
bool stable_distribution_check_param(RealType alpha, RealType beta, RealType, RealType b)
void div(std::size_t n, const float *a, const float *b, float *y)
#define MCKL_POP_INTEL_WARNING