# NOT RUN {
look <- matrix( 0, 10, 12)
look[4,7] <- 1
kernel2dsmooth( look, kernel.type="boxcar", n=3)
# The above returns the shape of the kernel applied, which
# is a square of length 3 centered on the grid point in look
# that has a value of 1.
# What happens if the 1 is on the edge? the effect is zero padding:
look <- look*0
look[1,1] <- 1
kernel2dsmooth( look, kernel.type="boxcar", n=3)
# Suppose we want to do the above for several, say l, neighborhood lengths.
# We can save an FFT for l-1 of the convolutions.
look <- look*0
look[4,7] <- 1
lookFFT <- Fourier2d( look, kdim=c(3,3))
dim( lookFFT) # Note the dimension is twice that of look.
kernel2dsmooth( look, kernel.type="boxcar", n=3, X=lookFFT)
# Now, suppose we want to apply the same kernel smooth to different fields.
# We can save an FFT for each subsequent calculation as follows.
wg <- kernel2dsmooth( look, kernel.type="boxcar", n=3, setup=TRUE)
dim( wg) # Note the dimension is twice that of look.
kernel2dsmooth( look, kernel.type="boxcar", n=3, W=wg)
look <- look*0
look[8,5] <- 1
kernel2dsmooth( look, kernel.type="boxcar", n=3, W=wg)
look[5, 10] <- 1
kernel2dsmooth( look, kernel.type="boxcar", n=3, W=wg)
# }
Run the code above in your browser using DataLab