32 #ifndef VSMC_RNG_NORMAL_DISTRIBUTION_HPP 33 #define VSMC_RNG_NORMAL_DISTRIBUTION_HPP 45 template <
typename RealType>
55 template <
typename RealType>
64 return -std::numeric_limits<result_type>::max
VSMC_MNE();
69 return std::numeric_limits<result_type>::max
VSMC_MNE();
81 if (dist1.param_ != dist2.param_)
85 if (dist1.saved_ && !dist2.saved_)
87 if (!dist1.saved_ && dist2.saved_)
95 return dist1.param_ != dist2.param_;
98 template <
typename CharT,
typename Traits>
102 os << dist.param_ <<
' ';
103 os << dist.v_ <<
' ';
109 template <
typename CharT,
typename Traits>
116 is >> std::ws >> param;
118 is >> std::ws >> saved;
132 template <
typename RNGType>
142 result_type u2 = const_pi_2<result_type>() * runif(rng);
155 template <std::
size_t K,
typename RealType,
typename RNGType>
157 RNGType &rng, std::size_t n, RealType *r, RealType mean, RealType stddev)
160 const std::size_t nu = n / 2;
161 RealType *
const u1 = r;
162 RealType *
const u2 = r + nu;
165 mul(nu, static_cast<RealType>(-2), s, s);
167 mul(nu, const_pi_2<RealType>(), u2, u2);
169 mul(nu, stddev, s, s);
170 fma(nu, s, u1, mean, u1);
171 fma(nu, s, u2, mean, u2);
178 template <
typename RealType,
typename RNGType>
180 RNGType &rng, std::size_t n, RealType *r, RealType mean, RealType stddev)
182 const std::size_t k = 1000;
183 const std::size_t m = n / k;
184 const std::size_t l = n % k;
185 for (std::size_t i = 0; i != m; ++i, r += k)
186 internal::normal_distribution_impl<k>(rng, k, r, mean, stddev);
187 internal::normal_distribution_impl<k>(rng, l, r, mean, stddev);
190 RealType u = runif(rng);
191 RealType v = runif(rng);
194 std::cos(const_pi_2<RealType>() * v);
198 template <
typename RealType,
typename RNGType>
200 std::size_t n, RealType *r)
207 #endif // VSMC_RNG_NORMAL_DISTRIBUTION_HPP
Standard uniform distribution with open/closed variants.
void mul(std::size_t n, const float *a, const float *b, float *y)
NormalDistribution< RealType > distribution_type
void sqrt(std::size_t n, const float *a, float *y)
bool is_equal(const T &a, const T &b)
void normal_distribution_impl(RNGType &rng, std::size_t n, RealType *r, RealType mean, RealType stddev)
void rng_rand(RNGType &rng, BernoulliDistribution< IntType > &dist, std::size_t n, IntType *r)
result_type stddev() const
friend bool operator!=(const distribution_type &dist1, const distribution_type &dist2)
void normal_distribution(RNGType &, std::size_t, RealType *, RealType, RealType)
Generating normal random variates.
#define VSMC_DEFINE_RNG_DISTRIBUTION_2(Name, name, T, T1, p1, v1, T2, p2, v2)
void cos(std::size_t n, const float *a, float *y)
bool normal_distribution_check_param(RealType, RealType stddev)
friend std::basic_istream< CharT, Traits > & operator>>(std::basic_istream< CharT, Traits > &is, distribution_type &dist)
void fma(std::size_t n, const T *a, const T *b, const T *c, T *y)
For , compute .
void sincos(std::size_t n, const float *a, float *y, float *z)
void sin(std::size_t n, const float *a, float *y)
friend bool operator==(const distribution_type &dist1, const distribution_type &dist2)
void u01_oc_distribution(RNGType &rng, std::size_t n, RealType *r)
Generate standard uniform random variates on open-closed interval.
void log(std::size_t n, const float *a, float *y)
friend std::basic_ostream< CharT, Traits > & operator<<(std::basic_ostream< CharT, Traits > &os, const distribution_type &dist)