Learn R Programming

SDraw (version 2.1.13)

halton.lattice: Halton lattice inside a rectangle

Description

Constructs a lattice of Halton boxes (a Halton lattice) inside a rectangular box.

Usage

halton.lattice(
  box = matrix(c(0, 0, 1, 1), 2),
  N = 10000,
  J = NULL,
  eta = rep(1, nrow(box)),
  triangular = FALSE,
  bases = NULL
)

Arguments

box

A DX2 matrix containing coordinates of the box. One row per dimension. Column 1 is the minimum, column 2 is the maximum. box[1,] contains c(min,max) coordinates of the box in dimension 1 (horizontal). box[2,] contains c(min,max) coordinates of the box in dimension 2 (vertical). Etc for higher dimensions. Default is the 2D unit box.

N

Approximate number of points to place in the whole box. If J is specified, it takes precedence. If J is NULL, the algorithm attempts to place N points in the bounding box using Halton boxes that are as close to square as possible. N is not exact, but is a target.

J

A DX1 vector of base powers which determines the size and shape of the Halton boxes. Elements of J less than or equal to 1 are re-set to 1. See additional description in help for hip.polygon function.

eta

A DX1 vector of the number of points to add inside each Halton box. e.g., if eta = c(3,2), a small grid of 3 by 2 points is added inside each Halton box. eta[1] is for the horizontal dimension, eta[2] is for the vertical dimension, etc for higher dimensions.

triangular

boolean, if TRUE, construct a triangular grid. If FALSE, construct rectangular grid. See help for hip.polygon.

bases

A DX1 vector of Halton bases. These must be co-prime.

Value

A data frame containing coordinates in the Halton lattice. Names of the coordinates are dimnames(box)[1]. If box does not have dimnames, names of the coordinates are c("d1", "d2", ...) (d1 is horizontal, d2 is vertical, etc).

In addition, return has following attributes:

  • J: the J vector used to construct the lattice. This is either the input J or the computed J when only N is specified.

  • eta: the eta vector used in the lattice.

  • bases: Bases of the van der Corput sequences used in the lattice, one per dimension.

  • triangular: Whether the lattice is triangular or square.

  • hl.bbox: The input box. If box does not have dimnames, this attribute will be assigned dimnames of list(c("d1","d2"),c("min","max")).

Details

This is designed to be called with the bounding box of a spatial object. See examples.

Definition of Halton lattice: A Halton lattice has the same number of points in every Halton box. Halton boxes are the bases[1]^J[1] X bases[2]^J[2] matrix of rectangles over a square. Each Halton box contains prod(eta) points.

See Also

halton.lattice, hip.polygon

Examples

Run this code
# NOT RUN {
# Lattice of 2^3*3^2 = 72 points in unit box
hl <- halton.lattice( J=c(3,2) )

# Plot
hl.J <- attr(hl,"J")
hl.b <- attr(hl,"bases")
hl.bb <- attr(hl,"hl.bbox") 

plot( hl.bb[1,], hl.bb[2,], type="n", pty="s")
points( hl[,1], hl[,2], pch=16, cex=.75, col="red")

for(d in 1:ncol(hl)){
  tmp2 <- hl.bb[d,1] + (0:(hl.b[d]^hl.J[d]))*(diff(hl.bb[d,]))/(hl.b[d]^hl.J[d])
  if( d == 1){
      abline(v=tmp2)
  } else{
      abline(h=tmp2)
  }
}

# Lattice of approx 1000 points over bounding box of spatial object
hl <- halton.lattice( bbox(HI.coast), N=1000 )
# }

Run the code above in your browser using DataLab