help mata halton()
-------------------------------------------------------------------------------
Title
[M-5] halton() -- Generate a Halton or Hammersley set
Syntax
real matrix halton(real scalar n, real scalar d)
real matrix halton(real scalar n, real scalar d, real scalar start)
real matrix halton(real scalar n, real scalar d, real scalar start,
real scalar hammersley)
void _halton(real matrix x)
void _halton(real matrix x, real scalar start)
void _halton(real matrix x, real scalar start, real scalar
hammersley)
real colvector ghalton(real scalar n, real scalar base, real scalar
u)
Description
halton(n, d) returns an n x d matrix containing a Halton set of length n
and dimension d.
halton(n, d, start) does the same thing, but the first row of the
returned matrix contains the sequences starting at index start. The
default is start = 1.
halton(n, d, start, hammersley), with hammersley != 0, returns a
Hammersley set of length n and dimension d with the first row of the
returned matrix containing the sequences starting at index start.
_halton(x) modifies the n x d matrix x so that it contains a Halton set
of dimension d of length n.
_halton(x, start) does the same thing, but the first row of the returned
matrix contains the sequences starting at index start. The default is
start = 1.
_halton(x, start, hammersley), with hammersley != 0, returns a Hammersley
set of length n and dimension d with the first row of the returned matrix
containing the sequences starting at index start.
ghalton(n, base, u) returns an n x 1 vector containing a (generalized)
Halton sequence using base base and starting from scalar 0 <= u < 1. For
u = 0, the standard Halton sequence is generated. If u is uniform (0,1),
a randomized Halton sequence is generated.
Remarks
The Halton sequences are generated from the first d primes and generally
have more uniform coverage over the unit cube of dimension d than that of
sequences generated from pseudouniform random numbers. However, Halton
sequences based on large primes (d > 10) can be highly correlated, and
their coverage can be worse than that of the pseudorandom uniform
sequences.
The Hammersley set contains the sequence (2 * i - 1)/(2 * n), i = 1, ...,
n, in the first dimension and Halton sequences for dimensions 2, ..., d.
_halton() modifies x and can be used when repeated calls are made to
generate long sequences in blocks. Here update the start index between
calls by using start = start + rows(x).
ghalton() uses the base base, preferably a prime, and generates a Halton
sequence using 0 <= u < 1 as a starting value. If u is uniform (0,1),
the sequence is a randomized Halton sequence. For u = 0, the sequence is
the standard Halton sequence. Blocks of sequences can be generated by
ghalton() by using the last value in the vector returned from a previous
call as u. For example,
x = J(n,1,0)
for (i=1; i<=k; i++) {
x[.] = ghalton(n, base, x[n])
...
}
Conformability
halton(n, d, start, hammersley):
input:
n: 1 x 1
d: 1 x 1
start: 1 x 1 (optional)
hammersley: 1 x 1 (optional)
output:
result: n x d
_halton(x, start, hammersley):
input:
x: n x d
start: 1 x 1 (optional)
hammersley: 1 x 1 (optional)
output:
x: n x d
ghalton(n, base, u):
input:
n: 1 x 1
base: 1 x 1
u: 1 x 1
output:
result: n x 1
Diagnostics
The maximum dimension, d, is 20. The scalar index start must be a
positive integer, and the scalar u must be such that 0 <= u < 1.
Source code
halton.mata for halton() and _halton().
ghalton() is built in.
Also see
Manual: [M-5] halton()
Help: [M-4] mathematical