g05 Chapter Contents
g05 Chapter Introduction
NAG C Library Manual

# NAG Library Function Documentnag_quasi_random_uniform (g05yac)

## 1  Purpose

To generate multidimensional quasi-random sequences with a uniform probability distribution.

## 2  Specification

 #include #include
 void nag_quasi_random_uniform (Nag_QuasiRandom_State state, Nag_QuasiRandom_Sequence seq, Integer iskip, Integer idim, double quasi[], Nag_QuasiRandom *gf, NagError *fail)

## 3  Description

Low discrepancy (quasi-random) sequences are used in numerical integration, simulation and optimization. Like pseudorandom numbers they are uniformly distributed but they are not statistically independent, rather they are designed to give more even distribution in multidimensional space (uniformity). Therefore they are often more efficient than pseudorandom numbers in multidimensional Monte–Carlo methods.
nag_quasi_random_uniform (g05yac) generates a set of points ${x}^{1},{x}^{2},\dots ,{x}^{N}$ with high uniformity in the $S$-dimensional unit cube ${I}^{S}={\left[0,1\right]}^{S}$. One measure of the uniformity is the discrepancy which is defined as follows:
• Given a set of points ${x}^{1},{x}^{2},\dots ,{x}^{N}\in {I}^{S}$ and a subset $G\subset {I}^{S}$, define the counting function ${S}_{N}\left(G\right)$ as the number of points ${x}^{i}\in G$. For each $x=\left({x}_{1},{x}_{2},\dots ,{x}_{S}\right)\in {I}^{S}$, let ${G}_{x}$ be the rectangular $s$-dimensional region
 $G x = 0, x 1 × 0, x 2 ×⋯× 0, x S$
with volume ${x}_{1},{x}_{2},\dots ,{x}_{S}$. Then the discrepancy of the points ${x}^{1},{x}^{2},\dots ,{x}^{N}$ is
 $DN* x1,x2,…,xN = sup x∈IS SN Gx - N x1 , x2 , … , xS .$
The discrepancy of the first $N$ terms of such a sequence has the form
 $DN*x1,x2,…,xN≤CSlog⁡NS+Olog⁡NS-1 for all N≥2.$
The principal aim in the construction of low-discrepancy sequences is to find sequences of points in ${I}^{S}$ with a bound of this form where the constant ${C}_{S}$ is as small as possible.
nag_quasi_random_uniform (g05yac) generates the low-discrepancy sequences proposed by Sobol, Faure and Niederreiter.

## 4  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

## 5  Arguments

1:     stateNag_QuasiRandom_StateInput
On entry: the type of operation to perform.
${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Init}$
The first call for initialization, and there is no output via array quasi.
${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Cont}$
The sequence has been initialized by a prior call to nag_quasi_random_uniform (g05yac) with ${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Init}$. Random numbers are output via array quasi.
${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Finish}$
The final call to release memory, and no further random numbers are required for output via array quasi.
Constraint: ${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Init}$, $\mathrm{Nag_QuasiRandom_Cont}$ or $\mathrm{Nag_QuasiRandom_Finish}$.
2:     seqNag_QuasiRandom_SequenceInput
On entry: the type of sequence to generate.
${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Sobol}$
A Sobol sequence.
${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Nied}$
A Niederreiter sequence.
${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Faure}$
A Faure sequence.
Constraint: ${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Sobol}$, $\mathrm{Nag_QuasiRandom_Nied}$ or $\mathrm{Nag_QuasiRandom_Faure}$.
3:     iskipIntegerInput
On entry: the number of terms in the sequence to skip on initialization.
${\mathbf{iskip}}=0$
All the terms of the sequence are generated.
${\mathbf{iskip}}=k$
The first $k$ terms of the sequence are ignored and the first term of the sequence now corresponds to the $k$th term of the sequence when ${\mathbf{iskip}}=0$.
If ${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Faure}$, iskip is not referenced.
Constraint: if ${\mathbf{seq}}=\mathrm{Nag_QuasiRandom_Nied}$ or $\mathrm{Nag_QuasiRandom_Sobol}$ and ${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Init}$, ${\mathbf{iskip}}\ge 0$.
4:     idimIntegerInput
On entry: the number of dimensions required.
Constraint: $1\le {\mathbf{idim}}\le 40$.
5:     quasi[idim]doubleOutput
On exit: the random numbers.
If ${\mathbf{state}}=\mathrm{Nag_QuasiRandom_Cont}$, ${\mathbf{quasi}}\left[k-1\right]$ contains the random number for the $k$th dimension.
6:     gfNag_QuasiRandom *Communication Structure
Workspace used to communicate information between calls to nag_quasi_random_uniform (g05yac). The contents of this structure should not be changed between calls.
7:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

On entry, seq is not valid: ${\mathbf{seq}}="〈\mathit{\text{value}}〉"$.
NE_INITIALIZATION
Incorrect initialization.
NE_INT
On entry, ${\mathbf{idim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{idim}}\le 40$.
On entry, ${\mathbf{idim}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{idim}}\ge 1$.
On entry, ${\mathbf{iskip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{iskip}}\ge 0$.
On entry, value of skip too large: ${\mathbf{iskip}}=〈\mathit{\text{value}}〉$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
NE_TOO_MANY_CALLS
Too many calls to generator.

## 7  Accuracy

Not applicable.

The maximum length of the generated sequences is ${2}^{29}-1$, this should be adequate for practical purposes. In the case of the Niederreiter generator nag_quasi_random_uniform (g05yac) jumps to the appropriate starting point, while for the Sobol generator it simply steps through the sequence. In consequence the Sobol generator with large values of iskip will take a significant amount of time.

## 9  Example

This example approximates the integral
 $∫01 ⋯ ∫01 ∏ i=1 s 4xi-2 dx1, dx2, …, dxs = 1 ,$
where $s$ is the number of dimensions.

### 9.1  Program Text

Program Text (g05yace.c)

None.

### 9.3  Program Results

Program Results (g05yace.r)