Interpolation {RTMB} | R Documentation |
Interpolation
Description
Some interpolation methods are available to be used as part of 'RTMB' objective functions.
Usage
interpol1Dfun(z, xlim = c(1, length(z)), ...)
interpol2Dfun(z, xlim = c(1, nrow(z)), ylim = c(1, ncol(z)), ...)
## S4 method for signature 'ANY,advector,ANY,missing'
splinefun(x, y, method = c("fmm", "periodic", "natural"))
## S4 method for signature 'advector,missing,ANY,missing'
splinefun(x, method = c("fmm", "periodic", "natural"))
Arguments
z |
Matrix to be interpolated |
xlim |
Domain of x |
... |
Configuration parameters |
ylim |
Domain of y |
x |
spline x coordinates |
y |
spline y coordinates |
method |
Same as for the stats version, however only the three first are available. |
Details
interpol1Dfun
and interpol2Dfun
are kernel smoothers useful in the case where you need a 3rd order smooth representation of a data vector or matrix.
A typical use case is when a high-resolution map needs to be accessed along a random effect trajectory.
Both 1D and 2D cases accept an 'interpolation radius' parameter (default R=2) controlling the degree of smoothness. Note, that only the value R=1 will match the data exactly, while higher radius trades accuracy for smoothness. Note also that these smoothers do not attempt to extrapolate: The returned value will be NaN
outside the valid range (xlim
/ ylim
).
splinefun
imitates the corresponding stats
function. The AD implementation (in contrast to interpol1Dfun
) works for parameter dependent y-coordinates.
Value
function of x.
function of x and y.
Functions
-
interpol1Dfun()
: Construct a kernel smoothed representation of a vector. -
interpol2Dfun()
: Construct a kernel smoothed representation of a matrix. -
splinefun(x = ANY, y = advector, method = ANY, ties = missing)
: Construct a spline function. -
splinefun(x = advector, y = missing, method = ANY, ties = missing)
: Construct a spline function.
Examples
## ======= interpol1D
## R=1 => exact match of observations
f <- interpol1Dfun(sin(1:10), R=1)
layout(t(1:2))
plot(sin(1:10))
plot(f, 1, 10, add=TRUE)
title("R=1")
F <- MakeTape(f, 0)
F3 <- F$jacfun()$jacfun()$jacfun()
plot(Vectorize(F3), 1, 10)
title("3rd derivative")
## ======= interpol2D
f <- interpol2Dfun(volcano, xlim=c(0,1), ylim=c(0,1))
F <- MakeTape(function(x) f(x[1],x[2]), c(.5,.5))
## ======= splinefun
T <- MakeTape(function(x){
S <- splinefun(sin(x))
S(4:6)
}, 1:10)