vSMC
vSMC: Scalable Monte Carlo
|
Generate a fixed length sequence of uniform \([0,1)\) random variates by sorting. More...
#include <vsmc/rng/u01_sequence.hpp>
Public Types | |
using | result_type = RealType |
Public Member Functions | |
U01SequenceSorted (std::size_t N, RNGType &rng) | |
result_type | operator() (std::size_t n) |
result_type | operator[] (std::size_t n) |
Generate a fixed length sequence of uniform \([0,1)\) random variates by sorting.
This is primarily used in resampling algorithms within the library but can be used for other purposes. It deals with the usage case similar to the following,
In the above example, one want N uniform random variates, and having them sorted. The sorted sequence is accessed sequentially. There are two undesired effects. First the program has a runtime cost \(O(N\log N)\). Second, it has a memory cost \(O(N)\). The presented class can be used in place of the temporary vector in the following fashion.
The above program will has a runtime cost \(O(N)\) and a memory cost \(O(1)\). However, the overloaded operator[]
has a few restrictions. Most importantly, it is a forward one-pass operation. More specifically, let n
be the calling argument and nlast
be the calling argument of the last time it is called.
n
can only be either 0
, nlast
, or nlast + 1
n
can be at most N - 1
. Definition at line 131 of file u01_sequence.hpp.
using vsmc::U01SequenceSorted< RNGType, RealType >::result_type = RealType |
Definition at line 134 of file u01_sequence.hpp.
|
inline |
Definition at line 136 of file u01_sequence.hpp.
|
inline |
Definition at line 155 of file u01_sequence.hpp.
|
inline |
Definition at line 141 of file u01_sequence.hpp.