32 #ifndef VSMC_RNG_U01_SEQUENCE_HPP 33 #define VSMC_RNG_U01_SEQUENCE_HPP 38 #define VSMC_RUNTIME_ASSERT_RNG_U01_SEQUENCE(Method) \ 39 VSMC_RUNTIME_ASSERT((n < N_ && (n == n_ || n == n_ + 1 || n_ == N_)), \ 40 "**U01Sequence" #Method "::operator[]** INVALID INDEX") 53 template <
typename RealType>
54 inline void u01_sorted(std::size_t N,
const RealType *u01, RealType *u01seq)
58 for (std::size_t i = 0; i != N; ++i) {
59 lmax += u01seq[i] / (N - i);
67 template <
typename RealType>
69 std::size_t N,
const RealType *u01, RealType *u01seq)
71 RealType delta = 1 /
static_cast<RealType
>(N);
72 for (std::size_t i = 0; i != N; ++i)
73 u01seq[i] = u01[i] * delta + i * delta;
79 template <
typename RealType>
85 RealType delta = 1.0 /
static_cast<RealType
>(N);
86 u01seq[0] = u01 * delta;
87 for (std::size_t i = 1; i != N; ++i)
88 u01seq[i] = u01seq[i - 1] + delta;
130 template <
typename RNGType,
typename RealType =
double>
137 : N_(N), n_(N), u_(0), lmax_(0), rng_(rng)
148 lmax_ +=
std::log(runif_(rng_)) / (N_ - n);
176 template <
typename RNGType,
typename RealType =
double>
199 u_ = runif_(rng_) * delta_ + n * delta_;
225 template <
typename RNGType,
typename RealType =
double>
232 : N_(N), n_(N), u_(0), u0_(0), delta_(1 / static_cast<
result_type>(N))
235 u0_ = runif(rng) * delta_;
246 u_ = u0_ + n * delta_;
263 #endif // VSMC_RNG_U01_SEQUENCE_HPP
Standard uniform distribution with open/closed variants.
result_type operator()(std::size_t n)
U01SequenceStratified(std::size_t N, RNGType &rng)
Generate a fixed length sequence of uniform random variates by stratified sampling.
result_type operator[](std::size_t n)
Generate a fixed length sequence of uniform random variates by systematic sampling.
result_type operator[](std::size_t n)
void u01_systematic(std::size_t N, RealType u01, RealType *u01seq)
Transform a single standard uniform random number to a systematic sequence.
void u01_stratified(std::size_t N, const RealType *u01, RealType *u01seq)
Transform a sequence of standard uniform random numbers to a stratified sequence. ...
U01SequenceSorted(std::size_t N, RNGType &rng)
void exp(std::size_t n, const float *a, float *y)
result_type operator[](std::size_t n)
Generate a fixed length sequence of uniform random variates by sorting.
result_type operator()(std::size_t n)
#define VSMC_RUNTIME_ASSERT_RNG_U01_SEQUENCE(Method)
void u01_sorted(std::size_t N, const RealType *u01, RealType *u01seq)
Tranform a sequence of standard uniform random numbers to sorted sequence.
result_type operator()(std::size_t n)
U01SequenceSystematic(std::size_t N, RNGType &rng)
void log(std::size_t n, const float *a, float *y)