gridIntCB | R Documentation |
***************************************************************************** Grid linear interpolation in arbitrary dimension through Cardinal Basis.
gridIntCB(
X,
Y,
Xout,
interpCB = function(x, xout) {
cardinalBasis_lagrange(x = x, xout = xout)$CB
},
intOrder = NULL,
trace = 1L,
out_of_bounds = stop,
...
)
X |
An object that can be coerced into |
Y |
Response to be interpolated. It must be a vector of
length |
Xout |
Interpolation locations. Can be a vector or a
matrix. In the first case, the length of the vector must be equal
to the spatial dimension |
interpCB |
Function evaluating the interpolation Cardinal
Basis. This function must have as its first 2 formals 'x', and
'xout'. It must return a matrix with |
intOrder |
Order of the one-dimensional interpolations. Must
be a permutation of |
trace |
Level of verbosity. |
out_of_bounds |
Function to handle Xout outside x (default is stop). Then Xout will be bounded by x range. |
... |
Further arguments to be passed to |
This is a grid interpolation as in gridInt
but it is
required here that the one-dimensional interpolation method is
linear w.r.t. the vector of interpolated values. For each
dimension, a one-dimensional interpolation is carried out,
leading to a collection of interpolation problems each with a
dimension reduced by one. The same cardinal basis can be
used for all interpolations w.r.t. the same variable, so the
number of call to the interpCB
function is equal to the
interpolation dimension, making this method very fast compared to
the general grid interpolation as implemented in
gridInt
, see the Examples section.
A single interpolated value if Xout
is a vector or
a row matrix. If Xout
is a matrix with several rows, the
result is a vector of interpolated values, in the order of the
rows of Xout
.
Yves Deville
## Natural spline for use through Cardinal Basis in 'gridIntCB'
myInterpCB <- function(x, xout) cardinalBasis_natSpline(x = x, xout = xout)$CB
## Natural spline for use through Cardinal Basis
myInterp <- function(x, y, xout) {
spline(x = x, y = y, n = 3 * length(x), method = "natural", xout = xout)$y
}
## generate Grid and function
set.seed(2468)
d <- 5
nLev <- 4L + rpois(d, lambda = 4)
a <- runif(d)
myFun2 <- function(x) exp(-crossprod(a, x^2))
myGD2 <- Grid(nlevels = nLev)
Y2 <- apply_Grid(myGD2, myFun2)
n <- 10
Xout3 <- matrix(runif(n * d), ncol = d)
t1 <- system.time(GI1 <- gridInt(X = myGD2, Y = Y2, Xout = Xout3, interpFun = myInterp))
t2 <- system.time(GI2 <- gridInt(X = myGD2, Y = Y2, Xout = Xout3, interpFun = myInterp,
useC = FALSE))
t3 <- system.time(GI3 <- gridIntCB(X = myGD2, Y = Y2, Xout = Xout3, interpCB = myInterpCB))
df <- data.frame(true = apply(Xout3, 1, myFun2),
gridInt_C = GI1, gridInt_R = GI2, gridIntCB = GI3)
head(df)
rbind(gridInt_C = t1, gridInt_C = t2, gridIntCB = t3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.