data(LondonHP)
DM<-gw.dist(dp.locat=coordinates(londonhp))
##Compare the time consumed with and without a specified distance matrix
if (FALSE) {
system.time(gwr.res<-gwr.basic(PURCHASE~FLOORSZ, data=londonhp, bw=1000,
kernel = "gaussian"))
system.time(DM<-gw.dist(dp.locat=coordinates(londonhp)))
system.time(gwr.res<-gwr.basic(PURCHASE~FLOORSZ, data=londonhp, bw=1000,
kernel = "gaussian", dMat=DM))
## specify an optimum bandwidth by cross-validation appraoch
bw1<-bw.gwr(PURCHASE~FLOORSZ, data=londonhp, kernel = "gaussian",dMat=DM)
gwr.res1<-gwr.basic(PURCHASE~FLOORSZ, data=londonhp, bw=bw1,kernel = "gaussian",
dMat=DM)
gwr.res1 }
data(LondonBorough)
nsa = list("SpatialPolygonsRescale", layout.north.arrow(), offset = c(561900,200900),
scale = 500, col=1)
if (FALSE) {
if(require("RColorBrewer"))
{
mypalette<-brewer.pal(6,"Spectral")
x11()
spplot(gwr.res1$SDF, "FLOORSZ", key.space = "right", cex=1.5, cuts=10,
ylim=c(155840.8,200933.9), xlim=c(503568.2,561957.5),
main="GWR estimated coefficients for FLOORSZ with a fixed bandwidth",
col.regions=mypalette, sp.layout=list(nsa, londonborough))}
}
if (FALSE) {
bw2<-bw.gwr(PURCHASE~FLOORSZ,approach="aic",adaptive=TRUE, data=londonhp,
kernel = "gaussian", dMat=DM)
gwr.res2<-gwr.basic(PURCHASE~FLOORSZ, data=londonhp, bw=bw2,adaptive=TRUE,
kernel = "gaussian", dMat=DM)
gwr.res2
if(require("RColorBrewer"))
{
x11()
spplot(gwr.res2$SDF, "FLOORSZ", key.space = "right", cex=1.5, cuts=10,
ylim=c(155840.8,200933.9), xlim=c(503568.2,561957.5),
main="GWR estimated coefficients for FLOORSZ with an adaptive bandwidth",
col.regions=mypalette, sp.layout=list(nsa,londonborough))}
}
if (FALSE) {
############HP-GWR test code
simulate.data.generator <- function(data.length) {
x1 <- rnorm(data.length)
x2 <- rnorm(data.length)
x3 <- rnorm(data.length)
lon <- rnorm(data.length, mean = 533200, sd = 10000)
lat <- rnorm(data.length, mean = 159400, sd = 10000)
y <- x1 + 5 * x2 + 2.5 * x3 + rnorm(data.length)
simulate.data <- data.frame(y = y, x1 = x1, x2 = x2, x3 = x3, lon = lon, lat = lat)
coordinates(simulate.data) <- ~ lon + lat
names(simulate.data)
return(simulate.data)
}
simulate.data <- simulate.data.generator(10000)
adaptive = TRUE
## GWR (not parallelized)
bw.CV.s <- bw.gwr(data = simulate.data, formula = y ~ x1 + x2 + x3, approach="CV",
kernel = "gaussian", adaptive = adaptive, parallel.method = FALSE)
model.s <- gwr.model.selection(DeVar = "y", InDeVars = c("x1", "x2", "x3"), data = simulate.data,
bw = bw.CV.s, approach="AIC", kernel = "gaussian", adaptive = T,
parallel.method = FALSE)
system.time(
betas.s <- gwr.basic(data = simulate.data, formula = y ~ x1 + x2 + x3, bw = bw.CV.s,
kernel = "gaussian", adaptive = TRUE)
)
## GWR-Omp
bw.CV.omp <- bw.gwr(data = simulate.data, formula = y ~ x1 + x2 + x3, approach="CV",
kernel = "gaussian", adaptive = adaptive, parallel.method = "omp")
model.omp <- gwr.model.selection(DeVar = "y", InDeVars = c("x1", "x2", "x3"), data = simulate.data,
bw = bw.CV.omp, approach="AIC", kernel = "gaussian", adaptive = T,
parallel.method = "omp")
system.time(
betas.omp <- gwr.basic(data = simulate.data, formula = y ~ x1 + x2 + x3, bw = bw.CV.omp,
kernel = "gaussian", adaptive = T, parallel.method = "omp"))
## GWR-CUDA
bw.CV.cuda <- bw.gwr(data = simulate.data, formula = y ~ x1 + x2 + x3, approach="CV",
kernel = "gaussian", adaptive = adaptive, parallel.method = "cuda",
parallel.arg = 6*16)
model.cuda <- gwr.model.selection(DeVar = "y", InDeVars = c("x1", "x2", "x3"),
data = simulate.data, bw = bw.CV.cuda, approach="AIC",
kernel = "gaussian", adaptive = T,
parallel.method = "cuda", parallel.arg = 6*16)
system.time(
betas.cuda <- gwr.basic(data = simulate.data, formula = y ~ x1 + x2 + x3, bw = bw.CV.cuda,
kernel = "gaussian", adaptive = T, parallel.method = "cuda",
parallel.arg = 6*8))
}
Run the code above in your browser using DataLab