Last data update: 2014.03.03

R: Two dimensional radial and tensor basis functions based on a...
Radial.basisR Documentation

Two dimensional radial and tensor basis functions based on a Wendland function.

Description

Two dimensional radial basis and tensor functions based on a Wendland function and using sparse matrix format to reduce the storage.

Usage

Radial.basis(x1, centers, basis.delta, max.points = NULL,
                  mean.neighbor = 50,
                  BasisFunction = "WendlandFunction",
                  distance.type = "Euclidean",
                        verbose = FALSE)

Tensor.basis(x1, centers, basis.delta, max.points = NULL, mean.neighbor = 50, 
   BasisFunction = "WendlandFunction", distance.type = "Euclidean") 

WendlandFunction(d)    

triWeight(d)

Arguments

x1

A matrix of locations to evaluate the basis functions. Each row of x1 is a location.

centers

A matrix specifying the basis function centers.

d

A vector of distances.

basis.delta

A vector of scale parameters for the basis functions.

max.points

Maximum number of nonzero entries expected for the returned matrix.

distance.type

The distance metric. See LKrigDistance for details.

mean.neighbor

Average number of centers that are within delta of each x1 location. For centers on a regular grid this is often easy to estimate.

BasisFunction

A function that will take a nonnegative argument and be zero outside [0,1]. This is applied to distance(s) to generate the basis functions. For tensor basis functions, the function is applied to the distance components for each dimension.

verbose

Print out debugging information if TRUE.

Details

This function finds the pairwise distances between the points x1 and centers and evaluates the function RadialBasisFunction at these distances scaled by delta. In most applications delta is constant, but a variable delta could be useful for lon/lat regular grids. The Wendland function is for 2 dimensions and smoothness order 2. See WendlandFunction for the polynomial form. This code has a very similar function to the fields function wendland.cov.

In pseudo R code for delta a scalar Radial.basis evaluates as

  BigD<- rdist( x1,centers)
  WendlandFunction(BigD/basis.delta)

The actual code uses a FORTRAN subroutine to search over distances less than delta and also returns the matrix in sparse format.

The function Tensor.basis has similar function as the radial option. The main difference is that a slightly different distance function is used to return the component distances for each dimension. In pseudo R code for delta a scalar and for just two dimensions Tensor.basis evaluates as

  BigD1<- rdist( x1[,1],centers[,1])
  BigD2<- rdist( x1[,2],centers[,2])
  WendlandFunction(BigD1/basis.delta) *WendlandFunction(BigD1/basis.delta)

The function LKrig.cyl transforms coordinates on a cylinder, e.g. lon/lat when taken as a Mercator projection, and returns the 3-d coordinates. It is these 3-d coordinates that are used to find distances to define the radial basis functions. For points that are close this "chordal" type distance will be close to the geodesic distance on a cylinder but not identical.

Value

For Wendland.basis a matrix in sparse format with number of rows equal to nrow(x1) and columns equal to nrow(center).

Author(s)

Doug Nychka

See Also

LKrig.basis

Examples

set.seed(12)
x<- cbind( runif(100), runif(100))
center<- expand.grid( seq( 0,1,,5), seq(0,1,,5))
# coerce to matrix
center<- as.matrix(center)

  PHI1<- Radial.basis(x, center, basis.delta = .5)
  PHI2<- Tensor.basis( x, center, basis.delta = .5 )
# similarity of radial and tensor product forms  
  plot( c(0,1.1), c(0,1.1), type="p")
  for( k in 1:25){
	points( PHI1[,k], PHI2[,k])
	}
	
# LKrig with a different radial basis function. 
# 
  data(ozone2)  
  x<-ozone2$lon.lat
  y<- ozone2$y[16,]
# Find location that are not 'NA'.
# (LKrig is not set up to handle missing observations.)
  good <-  !is.na( y)
  x<- x[good,]
  y<- y[good]
  obj<- LKrig(x,y,NC=30,nlevel=1, alpha=1, lambda=.01, a.wght=5)
    
  obj1<- LKrig(x,y,NC=30,nlevel=1, alpha=1, 
    lambda=.01, a.wght=5, BasisFunction="triWeight", overlap=1.8)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(LatticeKrig)
Loading required package: spam
Loading required package: grid
Spam version 1.3-0 (2015-10-24) is loaded.
Type 'help( Spam)' or 'demo( spam)' for a short introduction 
and overview of this package.
Help for individual functions is also obtained by adding the
suffix '.spam' to the function name, e.g. 'help( chol.spam)'.

Attaching package: 'spam'

The following objects are masked from 'package:base':

    backsolve, forwardsolve

Loading required package: fields
Loading required package: maps

 # maps v3.1: updated 'world': all lakes moved to separate new #
 # 'lakes' database. Type '?world' or 'news(package="maps")'.  #


> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/LatticeKrig/Radial.Basis.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Radial.basis
> ### Title: Two dimensional radial and tensor basis functions based on a
> ###   Wendland function.
> ### Aliases: Radial.basis LKrig.cyl WendlandFunction Tensor.basis triWeight
> ### Keywords: spatial
> 
> ### ** Examples
> 
> set.seed(12)
> x<- cbind( runif(100), runif(100))
> center<- expand.grid( seq( 0,1,,5), seq(0,1,,5))
> # coerce to matrix
> center<- as.matrix(center)
> 
>   PHI1<- Radial.basis(x, center, basis.delta = .5)
>   PHI2<- Tensor.basis( x, center, basis.delta = .5 )
> # similarity of radial and tensor product forms  
>   plot( c(0,1.1), c(0,1.1), type="p")
>   for( k in 1:25){
+ 	points( PHI1[,k], PHI2[,k])
+ 	}
> 	
> # LKrig with a different radial basis function. 
> # 
>   data(ozone2)  
>   x<-ozone2$lon.lat
>   y<- ozone2$y[16,]
> # Find location that are not 'NA'.
> # (LKrig is not set up to handle missing observations.)
>   good <-  !is.na( y)
>   x<- x[good,]
>   y<- y[good]
>   obj<- LKrig(x,y,NC=30,nlevel=1, alpha=1, lambda=.01, a.wght=5)
>     
>   obj1<- LKrig(x,y,NC=30,nlevel=1, alpha=1, 
+     lambda=.01, a.wght=5, BasisFunction="triWeight", overlap=1.8)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>