Learn R Programming

LatticeKrig (version 9.3.0)

LKDist: Find all pairwise distances within a maximum distance.

Description

These are the lower level functions to compute the distances among two sets of locations but being limited to distances less than a maximum threshold (see delta below ). These functions are useful for generating a sparse matrix on distances and evaluating a compactly supported function (such as the Wendland). The location - location method supports the distance metrics: Euclidean, spherical, component-wise and Manhattan. LKDistComponent and LKDistComponentGrid return the coordinate-wise distances and are useful for evaluating a tensor product basis functions.

Usage

LKDist(x1, x2, delta, max.points = NULL, mean.neighbor = 50,
             distance.type = "Euclidean")
LKDistComponents(x1, x2, delta, max.points = NULL, mean.neighbor = 50, 
    distance.type = "Euclidean")
    
LKDistGrid(x1, gridList, delta, max.points = NULL, mean.neighbor = NULL,
distance.type = "Euclidean", periodic)

LKDistGridComponents( x1, gridList, delta, max.points = NULL, mean.neighbor = NULL, distance.type = "Euclidean")

LKGridCheck(distance.type, x1, gridList )

LKGridFindNmax(n1, max.points, mean.neighbor, delta, gridList)

Value

LKDist and LKDistGrid a list representing a sparse matrix in spind format.

LKDistComponent andLKDistGridComponent a list representing a sparse matrix using the spind format except the ra component is now a matrix. The columns of ra being the individual distances for each coordinate.

directionCosine a matrix where rows index the different points and columns index x,y,z.

LKGridFindNmax returns the maximum number of nonzero elements expected in a pairwise distance matrix.

LKGridFindNmax checks that the calling arguments are compatible with the pairwise distance computation.

Arguments

gridList

A list with each component vector that specifies the grid points for an equally spaced grid. Can have class gridList. (See also help on gridlist).

n1

Number of rows of x1.

x1

A matrix with rows indexing locations and columns indexing coordinates.

x2

A matrix with rows indexing locations and columns indexing coordinates.

delta

The maximum distance to find pairwise distances.

max.points

Used for dynamically assigning matrix size this should be larger than the total number of pairwise distances less than delta.

mean.neighbor

Used for dynamically assigning matrix size this is the average number of points that are less that delta in distance to the x1 locations.

periodic

A logical vector with length ncol( x1). If a component is TRUE then that dimension is treated as periodic.

distance.type

A text string either "Euclidean", "GreatCircle", "Chordal", "Manhattan".

Author

Doug Nychka

See Also

spind2spam, spind2full

Examples

Run this code
set.seed( 123)	
x<- matrix( runif(100*2), 100,2)

DMatrix<- LKDist( x,x, delta=.1)
# coerce to spam matrix format
DMatrix2<- spind2spam( DMatrix)

# a grid
gridL<- list( x1= seq(0,1,.2), x2= seq( 0,2,.2) , x3= seq( -1,1,.2))
class(gridL)<- "gridList"	
x1<- cbind( runif( 100), runif(100)*2, 2*(runif( 100) -.5) )
look<- LKDistGrid( x1, gridL, delta=.45)
# check against rdist.
# look2<- rdist( x1, make.surface.grid(gridL))
# look2[ look2 >= .45] <- 0
# max( abs(look- look2)[look>0] )

# test of periodic option
 gridL<- structure(
            list( x1= seq(0,1,.02),
                  x2= seq( 0,1,.02)),
            class="gridList")
 look1<- LKDistGrid( rbind(c(0,0)), gridL, delta=.35,
                     periodic=c(TRUE,FALSE))
 look2<- spind2full(look1)
 image.plot( as.surface( gridL, look2) )
 
 look1<- LKDistGrid( rbind(c(0,0)), gridL, delta=.35,
                      periodic=c(TRUE,TRUE))
 look2<- spind2full(look1)
 image.plot( as.surface( gridL, look2) )  

Run the code above in your browser using DataLab