📄 qrng.texi
字号:
@cindex quasi-random sequences@cindex low discrepancy sequences@cindex Sobol sequence@cindex Niederreiter sequenceThis chapter describes functions for generating quasi-random sequencesin arbitrary dimensions. A quasi-random sequence progressively covers a@math{d}-dimensional space with a set of points that are uniformlydistributed. Quasi-random sequences are also known as low-discrepancysequences. The quasi-random sequence generators use an interface thatis similar to the interface for random number generators, except thatseeding is not required---each generator produces a single sequence.The functions described in this section are declared in the header file@file{gsl_qrng.h}.@menu* Quasi-random number generator initialization:: * Sampling from a quasi-random number generator:: * Auxiliary quasi-random number generator functions:: * Saving and resorting quasi-random number generator state:: * Quasi-random number generator algorithms:: * Quasi-random number generator examples:: * Quasi-random number references:: @end menu@node Quasi-random number generator initialization@section Quasi-random number generator initialization@deftypefun {gsl_qrng *} gsl_qrng_alloc (const gsl_qrng_type * @var{T}, unsigned int @var{d})This function returns a pointer to a newly-created instance of aquasi-random sequence generator of type @var{T} and dimension @var{d}.If there is insufficient memory to create the generator then thefunction returns a null pointer and the error handler is invoked with anerror code of @code{GSL_ENOMEM}.@end deftypefun@deftypefun void gsl_qrng_free (gsl_qrng * @var{q})This function frees all the memory associated with the generator@var{q}.@end deftypefun@deftypefun void gsl_qrng_init (gsl_qrng * @var{q})This function reinitializes the generator @var{q} to its starting point.Note that quasi-random sequences do not use a seed and always producethe same set of values.@end deftypefun@node Sampling from a quasi-random number generator@section Sampling from a quasi-random number generator@deftypefun int gsl_qrng_get (const gsl_qrng * @var{q}, double @var{x}[])This function stores the next point from the sequence generator @var{q}in the array @var{x}. The space available for @var{x} must match thedimension of the generator. The point @var{x} will lie in the range@math{0 < x_i < 1} for each @math{x_i}.@end deftypefun@node Auxiliary quasi-random number generator functions@section Auxiliary quasi-random number generator functions@deftypefun {const char *} gsl_qrng_name (const gsl_qrng * @var{q})This function returns a pointer to the name of the generator.@end deftypefun @deftypefun size_t gsl_qrng_size (const gsl_qrng * @var{q})@deftypefunx {void *} gsl_qrng_state (const gsl_qrng * @var{q})These functions return a pointer to the state of generator @var{r} andits size. You can use this information to access the state directly. Forexample, the following code will write the state of a generator to astream,@examplevoid * state = gsl_qrng_state (q);size_t n = gsl_qrng_size (q);fwrite (state, n, 1, stream);@end example@end deftypefun@node Saving and resorting quasi-random number generator state@section Saving and resorting quasi-random number generator state@deftypefun int gsl_qrng_memcpy (gsl_qrng * @var{dest}, const gsl_qrng * @var{src})This function copies the quasi-random sequence generator @var{src} into thepre-existing generator @var{dest}, making @var{dest} into an exact copyof @var{src}. The two generators must be of the same type.@end deftypefun@deftypefun {gsl_qrng *} gsl_qrng_clone (const gsl_qrng * @var{q})This function returns a pointer to a newly created generator which is anexact copy of the generator @var{q}.@end deftypefun@node Quasi-random number generator algorithms@section Quasi-random number generator algorithmsThe following quasi-random sequence algorithms are available,@deffn {Generator} gsl_qrng_niederreiter_2This generator uses the algorithm described in Bratley, Fox,Niederreiter, @cite{ACM Trans. Model. Comp. Sim.} 2, 195 (1992). It isvalid up to 12 dimensions.@end deffn@deffn {Generator} gsl_qrng_sobolThis generator uses the Sobol sequence described in Antonov, Saleev,@cite{USSR Comput. Maths. Math. Phys.} 19, 252 (1980). It is valid up to40 dimensions.@end deffn@node Quasi-random number generator examples@section ExamplesThe following program prints the first 1024 points of the 2-dimensionalSobol sequence.@example@verbatiminclude examples/qrng.c@end example@noindentHere is the output from the program,@example$ ./a.out0.50000 0.500000.75000 0.250000.25000 0.750000.37500 0.375000.87500 0.875000.62500 0.125000.12500 0.62500....@end example@noindentIt can be seen that successive points progressively fill-in the spacesbetween previous points. @iftex@need 4000The following plot shows the distribution in the x-y plane of the first1024 points from the Sobol sequence,@sp 1@center @image{qrng,3.4in}@sp 1@center Distribution of the first 1024 points @center from the quasi-random Sobol sequence@end iftex@node Quasi-random number references@section ReferencesThe implementations of the quasi-random sequence routines are based onthe algorithms described in the following paper,@itemize @asisP. Bratley and B.L. Fox and H. Niederreiter, ``Algorithm 738: Programsto Generate Niederreiter's Low-discrepancy Sequences'', @cite{ACMTransactions on Mathematical Software}, Vol.@: 20, No.@: 4, December, 1994,p.@: 494--495.@end itemize
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -