Debian Codegraph @

man/QUnif.Rd

raw
1 \name{QUnif}
2 \title{Quasi Randum Numbers via Halton Sequences}
3 \alias{QUnif}
4 \alias{sHalton}
5 %
6 \concept{Quasi Monte Carlo}
7 \concept{low discrepancy sequence}
8 \concept{space filling}
9 %
10 \description{
11 These functions provide quasi random numbers or \emph{space filling} or
12 \emph{low discrepancy} sequences in the \eqn{p}-dimensional unit cube.
13 }
14 \usage{
15 sHalton(n.max, n.min = 1, base = 2, leap = 1)
16 QUnif (n, min = 0, max = 1, n.min = 1, p, leap = 1, silent = FALSE)
17 }
18 \arguments{
19 \item{n.max}{maximal (sequence) number.}
20 \item{n.min}{minimal sequence number.}
21 \item{n}{number of \eqn{p}-dimensional points generated in
22 \code{QUnif}. By default, \code{n.min = 1, leap = 1} and
23 the maximal sequence number is \code{n.max = n.min + (n-1)*leap}.}
24 \item{base}{integer \eqn{\ge 2}{>= 2}: The base with respect to which
25 the Halton sequence is built.}
26 \item{min, max}{lower and upper limits of the univariate intervals.
27 Must be of length 1 or \code{p}.}
28 \item{p}{dimensionality of space (the unit cube) in which points are
29 generated.}
30 \item{leap}{integer indicating (if \eqn{> 1}) if the series should be
31 leaped, i.e., only every \code{leap}th entry should be taken.}
32 \item{silent}{logical asking to suppress the message about enlarging
33 the prime table for large \code{p}.}
34 }
35 \value{
36 \code{sHalton(n,m)} returns a numeric vector of length \code{n-m+1} of
37 values in \eqn{[0,1]}.
38
39 \code{QUnif(n, min, max, n.min, p=p)} generates \code{n-n.min+1}
40 p-dimensional points in \eqn{[min,max]^p} returning a numeric matrix
41 with p columns.
42 }
43 \note{
44 For \code{leap} Kocis and Whiten recommend values of
45 \eqn{L=31,61,149,409}, and particularly the \eqn{L=409} for dimensions
46 up to 400.
47 }
48 \references{
49 James Gentle (1998)
50 \emph{Random Number Generation and Monte Carlo Simulation}; sec.\ 6.3.
51 Springer.
52
53 Kocis, L. and Whiten, W.J. (1997)
54 Computational Investigations of Low-Discrepancy Sequences.
55 \emph{ACM Transactions of Mathematical Software} \bold{23}, 2, 266--294.
56 }
57 \author{Martin Maechler}
58 \examples{
59 32*sHalton(20, base=2)
60
61 stopifnot(sHalton(20, base=3, leap=2) ==
62 sHalton(20, base=3)[1+2*(0:9)])
63 ## ------- a 2D Visualization -------
64
65 Uplot <- function(xy, axes=FALSE, xlab="", ylab="", ...) {
66 plot(xy, xaxs="i", yaxs="i", xlim=0:1, ylim=0:1, xpd = FALSE,
67 axes=axes, xlab=xlab, ylab=ylab, ...)
68 box(lty=2, col="gray40")
69 }
70
71 do4 <- function(n, ...) {
72 op <- mult.fig(4, main=paste("n =", n,": Quasi vs. (Pseudo) Random"),
73 marP=c(-2,-2,-1,0))$old.par
74 on.exit(par(op))
75 for(i in 1:2) {
76 Uplot(QUnif(n, p=2), main="QUnif", ...)
77 Uplot(cbind(runif(n), runif(n)), main="runif", ...)
78 }
79 }
80 do4(100)
81 do4(500)
82 do4(1000, cex = 0.8, col="slateblue")
83 do4(10000, pch= ".", col="slateblue")
84 do4(40000, pch= ".", col="slateblue")
85 }
86 \keyword{math}
87 \keyword{multivariate}
88 \keyword{datagen}