hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_rand_quasi_init (g05yl)

Purpose

nag_rand_quasi_init (g05yl) initializes a quasi-random generator prior to calling nag_rand_quasi_normal (g05yj), nag_rand_quasi_lognormal (g05yk) or nag_rand_quasi_uniform (g05ym).

Syntax

[iref, ifail] = g05yl(genid, idim, iskip)
[iref, ifail] = nag_rand_quasi_init(genid, idim, iskip)

Description

nag_rand_quasi_init (g05yl) selects a quasi-random number generator through the input value of genid and initializes the iref communication array for use by the functions nag_rand_quasi_normal (g05yj), nag_rand_quasi_lognormal (g05yk) or nag_rand_quasi_uniform (g05ym).
One of three types of quasi-random generator may be chosen, allowing the low-discrepancy sequences proposed by Sobol, Faure or Niederreiter to be generated.
Two sets of Sobol sequences are supplied, the first, is based on the work of Joe and Kuo (2008). The second, referred to in the documentation as "Sobol (A659)", is based on Algorithm 659 of Bratley and Fox (1988) with the extension to 1111 dimensions proposed by Joe and Kuo (2003). Both sets of Sobol sequences should satisfy the so-called Property A, up to 11111111 dimensions, but the first set should have better two-dimensional projections than those produced using Algorithm 659.

References

Bratley P and Fox B L (1988) Algorithm 659: implementing Sobol's quasirandom sequence generator ACM Trans. Math. Software 14(1) 88–100
Fox B L (1986) Algorithm 647: implementation and relative efficiency of quasirandom sequence generators ACM Trans. Math. Software 12(4) 362–376
Joe S and Kuo F Y (2003) Remark on Algorithm 659: implementing Sobol's quasirandom sequence generator ACM Trans. Math. Software (TOMS) 29 49–57
Joe S and Kuo F Y (2008) Constructing Sobol sequences with better two-dimensional projections SIAM J. Sci. Comput. 30 2635–2654

Parameters

Compulsory Input Parameters

1:     genid – int64int32nag_int scalar
Must identify the quasi-random generator to use.
genid = 1genid=1
Sobol generator.
genid = 2genid=2
Sobol (A659) generator.
genid = 3genid=3
Niederreiter generator.
genid = 4genid=4
Faure generator.
Constraint: genid = 1genid=1, 22, 33 or 44.
2:     idim – int64int32nag_int scalar
The number of dimensions required.
Constraints:
  • if genid = 1genid=1, 1idim100001idim10000;
  • if genid = 2genid=2, 1idim11111idim1111;
  • if genid = 3genid=3, 1idim3181idim318;
  • if genid = 4genid=4, 1idim401idim40.
3:     iskip – int64int32nag_int scalar
The number of terms of the sequence to skip on initialization for the Sobol and Niederreiter generators. If genid = 4genid=4, iskip is ignored.
Constraint: if genid = 1genid=1, 22 or 33, 0iskip2300iskip230.

Optional Input Parameters

None.

Input Parameters Omitted from the MATLAB Interface

liref

Output Parameters

1:     iref(liref) – int64int32nag_int array
Contains initialization information for use by the generator functions nag_rand_quasi_normal (g05yj), nag_rand_quasi_lognormal (g05yk) and nag_rand_quasi_uniform (g05ym). iref must not be altered in any way between initialization and calls of the generator functions.
2:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,genid < 1genid<1,
orgenid > 4genid>4.
  ifail = 2ifail=2
On entry,idim < 1idim<1,
oridim is too large.
  ifail = 4ifail=4
On entry, liref is too small.
  ifail = 5ifail=5
The value of iskip < 0iskip<0 or iskip is too large.

Accuracy

Not applicable.

Further Comments

The primitive polynomials and direction numbers used for the Sobol generator (genid = 1genid=1) were calculated by Joe and Kuo (2008) using the search critera D(6)D(6).

Example

function nag_rand_quasi_init_example
% Initialize the Sobol generator
genid = int64(1);
idim = 8;
% Skip the first few variates in the sequence
iskip = int64(1000);

n = 200;

[iref, ifail] = nag_rand_quasi_init(genid, int64(idim), iskip);

% Generate N quasi-random variates
[quas, iref, ifail] = nag_rand_quasi_uniform(int64(n), iref);

% Evaluate the function, and sum
sum = 0;
for i=1:n
  tmp = 1;
  for d=1:idim
    tmp = tmp*abs(4*quas(d,i)-2);
  end
  sum = sum + tmp;
end

% Convert sum to mean value
vsbl = sum/double(n);
fprintf('\nValue of integral = %8.4f\n', vsbl);
fprintf('\nFirst 10 variates\n');
for i = 1:10
  fprintf(' %3d', i);
  for j=1:idim
    fprintf(' %8.4f', quas(j,i));
  end
  fprintf('\n');
end
 

Value of integral =   1.0410

First 10 variates
   1   0.7197   0.5967   0.0186   0.1768   0.7803   0.4072   0.5459   0.3994
   2   0.9697   0.3467   0.7686   0.9268   0.5303   0.1572   0.2959   0.1494
   3   0.4697   0.8467   0.2686   0.4268   0.0303   0.6572   0.7959   0.6494
   4   0.3447   0.4717   0.1436   0.3018   0.1553   0.7822   0.4209   0.0244
   5   0.8447   0.9717   0.6436   0.8018   0.6553   0.2822   0.9209   0.5244
   6   0.5947   0.2217   0.3936   0.0518   0.9053   0.0322   0.1709   0.7744
   7   0.0947   0.7217   0.8936   0.5518   0.4053   0.5322   0.6709   0.2744
   8   0.0635   0.1904   0.0498   0.4580   0.6240   0.2510   0.9521   0.8057
   9   0.5635   0.6904   0.5498   0.9580   0.1240   0.7510   0.4521   0.3057
  10   0.8135   0.4404   0.2998   0.2080   0.3740   0.5010   0.7021   0.0557

function g05yl_example
% Initialize the Sobol generator
genid = int64(1);
idim = 8;
% Skip the first few variates in the sequence
iskip = int64(1000);

n = 200;

[iref, ifail] = g05yl(genid, int64(idim), iskip);

% Generate N quasi-random variates
[quas, iref, ifail] = g05ym(int64(n), iref);

% Evaluate the function, and sum
sum = 0;
for i=1:n
  tmp = 1;
  for d=1:idim
    tmp = tmp*abs(4*quas(d,i)-2);
  end
  sum = sum + tmp;
end

% Convert sum to mean value
vsbl = sum/double(n);
fprintf('\nValue of integral = %8.4f\n', vsbl);
fprintf('\nFirst 10 variates\n');
for i = 1:10
  fprintf(' %3d', i);
  for j=1:idim
    fprintf(' %8.4f', quas(j,i));
  end
  fprintf('\n');
end
 

Value of integral =   1.0410

First 10 variates
   1   0.7197   0.5967   0.0186   0.1768   0.7803   0.4072   0.5459   0.3994
   2   0.9697   0.3467   0.7686   0.9268   0.5303   0.1572   0.2959   0.1494
   3   0.4697   0.8467   0.2686   0.4268   0.0303   0.6572   0.7959   0.6494
   4   0.3447   0.4717   0.1436   0.3018   0.1553   0.7822   0.4209   0.0244
   5   0.8447   0.9717   0.6436   0.8018   0.6553   0.2822   0.9209   0.5244
   6   0.5947   0.2217   0.3936   0.0518   0.9053   0.0322   0.1709   0.7744
   7   0.0947   0.7217   0.8936   0.5518   0.4053   0.5322   0.6709   0.2744
   8   0.0635   0.1904   0.0498   0.4580   0.6240   0.2510   0.9521   0.8057
   9   0.5635   0.6904   0.5498   0.9580   0.1240   0.7510   0.4521   0.3057
  10   0.8135   0.4404   0.2998   0.2080   0.3740   0.5010   0.7021   0.0557


PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013