Description Usage Arguments Details Value Note Author(s) References Examples
Shepard's (modified) quadratic interpolation method.
1 2 3 4 5 6 |
X |
Design matrix. A matrix with n rows and d columns where n is the number of nodes and d is the dimension. |
y |
Numeric vector of length n containing the function values at design points. |
XNew |
Numeric matrix of new design points where interpolation is computed. It must have d columns. |
nQ |
Number of points used in the local polynomial fit. This
is the parameter |
nW |
Number of nodes within (and defining) the radii of
influence, which enter into the weights. This is parameter
|
nR |
Number of divisions in each dimension for the cell grid
defined in the subroutine |
checkX |
If |
deriv |
Logical or integer value in |
Shepard's modified interpolation method works for scattered data in arbitrary dimension. It relies on a local polynomial fit and the quadratic version uses a polynomial of degree 2 (a quadratic form) as local approximation of the function.
A list with several objects related to the computation
method. The vector of interpolated value is in the list element
named yNew
.
This function is an R interface to the qshepmd
routine in the SHEPPACK Fortran package available on netlib
http://www.netlib.org as algorithm 905A.
The qshepInt
function is an interface for the
QSHEPMD
Fortran routine, while qshepInt2d
and
qshepInt3d
are interfaces to the QSHEPM2D
and
QSHEPM3D
Fortran routines. The general interpolation of
qshepInt
can be used also for the dimensions 2 and
3. However, this function does not allow the computation of
the derivatives as qshepInt2d
and qshepInt3d
do.
Fortran code by William I. Thacker; Jingwei Zhang; Layne T. Watson; Jeffrey B. Birch; Manjula A. Iyer; Michael W. Berry. See References below. The Fortran code is a translation of M.W Berry's C++ code.
Code adaptation and R interface by Yves Deville.
W.I. Thacker, J. Zhang, L.T. Watson, J.B. Birch, M.A. Iyer and M.W. Berry (2010). Algorithm 905: SHEPPACK: Modified Shepard Algorithm for Interpolation of Scattered Multivariate Data ACM Trans. on Math. Software (TOMS) Vol. 37, n. 3. link
M.W. Berry and K.S. Minser (1999). Algorithm 798: High-dimensional interpolation using the modified Shepard method. ACM Trans. Math. Software (TOMS) Vol. 25, n. 3, pp. 353-366. link
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | n <- 1500; nNew <- 100; d <- 4
fTest <- function(x)((x[1] + 2 * x[2] + 3 * x[3] + 4 * x[4]) / 12)^2
set.seed(12345)
X <- matrix(runif(n*d), nrow = n, ncol = d)
y <- apply(X, 1, FUN = fTest)
XNew <- matrix(runif(nNew * d), nrow = nNew, ncol = d)
yNew <- apply(XNew, 1, FUN = fTest)
system.time(res <- qsheppInt(X = X, XNew = XNew, y = y, nQ = 40,
checkX = FALSE))
## check errors
max(abs(res$yNew - yNew))
##=========================================================================
## Use SHEPPACK test functions see Thacker et al. section 7 'PERFORMANCE'
##=========================================================================
## Not run:
set.seed(1234)
d <- 3
k <- 0:4; n0 <- 100 * 2^k; n1 <- 4
GD <- Grid(nlevels = rep(n1, d))
XNew <- as.matrix(GD)
RMSE <- array(NA, dim = c(5, length(k)),
dimnames = list(fun = 1:5, k = k))
for (iFun in 1:5) {
yNew <- apply(XNew, 1, ShepFuns[[iFun]])
for (iN in 1:length(n0)) {
X <- matrix(runif(n0[iN] * d), ncol = d)
y <- apply(X, 1, ShepFuns[[iFun]])
res <- qsheppInt(X = X, XNew = XNew, y = y, nQ = 40, checkX = FALSE)
RMSE[iFun, iN] <- mean((res$yNew - yNew)^2)
}
}
cols <- c("black", "SteelBlue2", "orangered", "SpringGreen3", "purple")
pchs <- c(16, 21, 22, 23, 24)
matplot(k, t(RMSE), type = "o", lwd = 2, lty = 1,
col = cols, xaxt = "n", pch = pchs, cex = 1.4,
bg = "white",
main = sprintf("dim = %d SHEPPACK test functions", d),
xlab = "number of nodes", ylab = "RMSE")
axis(side = 1, at = k, labels = n0)
legend("topright", legend = paste("shepFun", 1:5),
col = cols, pch = pchs, lwd = 2, pt.lwd = 2, pt.bg = "white")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.