├── .gitignore ├── DESCRIPTION ├── GWmodel ├── .gitignore ├── DESCRIPTION ├── NAMESPACE ├── R │ ├── BootstrapGWR.r │ ├── GeneralizedGWR.r │ ├── LocalsummaryStatistics.r │ ├── Model.selection.r │ ├── MontCarlo.r │ ├── RcppExports.R │ ├── bw.ggwr.r │ ├── bw.gtwr.R │ ├── bw.gwda.r │ ├── bw.gwss.average.R │ ├── bw.sel.r │ ├── collinearity.r │ ├── gtwr.R │ ├── gw.average.cv.R │ ├── gw.average.cv.contrib.R │ ├── gw.dist.r │ ├── gw.weight.r │ ├── gwda.r │ ├── gwpca.mc.r │ ├── gwpca.r │ ├── gwpca.visualization.r │ ├── gwr.basic.r │ ├── gwr.collin.diagno.r │ ├── gwr.hetero.r │ ├── gwr.mixed.r │ ├── gwr.multiscale.R │ ├── gwr.predict.r │ ├── gwr.robust.r │ ├── gwr.scalable.r │ ├── gwr.t.adjust.r │ ├── mink.pvals.R │ ├── minkovski.approach.r │ ├── writeGWR.r │ └── zzz.r ├── cleanup ├── configure ├── configure.ac ├── data │ ├── DubVoter.rda │ ├── EWHP.rda │ ├── EWOutline.rda │ ├── GE2015.rda │ ├── Georgia.rda │ ├── GeorgiaCounties.rda │ ├── LondonBorough.rda │ ├── LondonHP.rda │ ├── USelect.rda │ └── datalist ├── inst │ └── CITATION ├── man │ ├── DubVoter.rd │ ├── EWHP.Rd │ ├── EWOutline.rd │ ├── GWmodel-package.Rd │ ├── Georgia.Rd │ ├── GeorgiaCounties.rd │ ├── LondonBorough.rd │ ├── LondonHP.Rd │ ├── USelect.rd │ ├── bw.ggwr.Rd │ ├── bw.gtwr.Rd │ ├── bw.gwda.rd │ ├── bw.gwpca.rd │ ├── bw.gwr.Rd │ ├── bw.gwr.lcr.rd │ ├── bw.gwss.average.Rd │ ├── ggwr.basic.Rd │ ├── ggwr.cv.Rd │ ├── ggwr.cv.contrib.Rd │ ├── gtwr.Rd │ ├── gw.dist.Rd │ ├── gw.pcplot.rd │ ├── gw.weight.Rd │ ├── gwda.rd │ ├── gwpca.check.components.rd │ ├── gwpca.cv.Rd │ ├── gwpca.cv.contrib.Rd │ ├── gwpca.glyph.plot.rd │ ├── gwpca.montecarlo.1.rd │ ├── gwpca.montecarlo.2.rd │ ├── gwpca.rd │ ├── gwr.basic.rd │ ├── gwr.bootstrap.rd │ ├── gwr.collin.diagno.Rd │ ├── gwr.cv.Rd │ ├── gwr.cv.contrib.Rd │ ├── gwr.hetero.rd │ ├── gwr.lcr.cv.Rd │ ├── gwr.lcr.cv.contrib.Rd │ ├── gwr.lcr.rd │ ├── gwr.mink.approach.rd │ ├── gwr.mink.matrixview.rd │ ├── gwr.mink.pval.rd │ ├── gwr.mixed.rd │ ├── gwr.model.selection.Rd │ ├── gwr.model.sort.Rd │ ├── gwr.model.view.rd │ ├── gwr.montecarlo.Rd │ ├── gwr.multiscale.rd │ ├── gwr.predict.Rd │ ├── gwr.robust.Rd │ ├── gwr.scalable.rd │ ├── gwr.t.adjust.rd │ ├── gwr.write.Rd │ ├── gwss.montecarlo.Rd │ └── gwss.rd └── src │ ├── GWmodel.cpp │ ├── GWmodelCUDA │ ├── CGWmodelCUDA.cpp │ ├── CGWmodelCUDA.h │ ├── CMakeLists.txt │ ├── GWmodelKernel.cu │ ├── GWmodelKernel.h │ ├── IGWmodelCUDA.cpp │ ├── IGWmodelCUDA.h │ ├── cmake │ │ └── FindcuBLAS.cmake │ └── helper.h │ ├── Makevars.in │ ├── Makevars.win │ ├── RcppExports.cpp │ ├── download.ps1 │ └── init.c ├── NAMESPACE ├── R ├── BootstrapGWR.r ├── GeneralizedGWR.r ├── LocalsummaryStatistics.r ├── Model.selection.r ├── MontCarlo.r ├── RcppExports.R ├── bw.ggwr.r ├── bw.gtwr.R ├── bw.gwda.r ├── bw.gwss.average.R ├── bw.sel.r ├── collinearity.r ├── gtwr.R ├── gw.average.cv.R ├── gw.average.cv.contrib.R ├── gw.dist.r ├── gw.weight.r ├── gwda.r ├── gwpca.mc.r ├── gwpca.r ├── gwpca.visualization.r ├── gwr.basic.r ├── gwr.collin.diagno.r ├── gwr.hetero.r ├── gwr.mixed.r ├── gwr.multiscale.R ├── gwr.predict.r ├── gwr.robust.r ├── gwr.scalable.r ├── gwr.t.adjust.r ├── mink.pvals.R ├── minkovski.approach.r ├── writeGWR.r └── zzz.r ├── cleanup ├── configure ├── configure.ac ├── data ├── DubVoter.rda ├── EN_CB.rda ├── EWHP.rda ├── EWOutline.rda ├── GE2015.rda ├── Georgia.rda ├── GeorgiaCounties.rda ├── LondonBorough.rda ├── LondonHP.rda ├── USelect.rda └── datalist ├── inst └── CITATION ├── man ├── DubVoter.rd ├── EN_CB.rd ├── EWHP.Rd ├── EWOutline.rd ├── GE2015.rd ├── GWmodel-package.Rd ├── Georgia.Rd ├── GeorgiaCounties.rd ├── LondonBorough.rd ├── LondonHP.Rd ├── USelect.rd ├── bw.ggwr.Rd ├── bw.gtwr.Rd ├── bw.gwda.rd ├── bw.gwpca.rd ├── bw.gwr.Rd ├── bw.gwr.lcr.rd ├── bw.gwss.average.Rd ├── ggwr.basic.Rd ├── ggwr.cv.Rd ├── ggwr.cv.contrib.Rd ├── gtwr.Rd ├── gw.dist.Rd ├── gw.pcplot.rd ├── gw.weight.Rd ├── gwda.rd ├── gwpca.check.components.rd ├── gwpca.cv.Rd ├── gwpca.cv.contrib.Rd ├── gwpca.glyph.plot.rd ├── gwpca.montecarlo.1.rd ├── gwpca.montecarlo.2.rd ├── gwpca.rd ├── gwr.basic.rd ├── gwr.bootstrap.rd ├── gwr.collin.diagno.Rd ├── gwr.cv.Rd ├── gwr.cv.contrib.Rd ├── gwr.hetero.rd ├── gwr.lcr.cv.Rd ├── gwr.lcr.cv.contrib.Rd ├── gwr.lcr.rd ├── gwr.mink.approach.rd ├── gwr.mink.matrixview.rd ├── gwr.mink.pval.rd ├── gwr.mixed.rd ├── gwr.model.selection.Rd ├── gwr.model.sort.Rd ├── gwr.model.view.rd ├── gwr.montecarlo.Rd ├── gwr.multiscale.rd ├── gwr.predict.Rd ├── gwr.robust.Rd ├── gwr.scalable.rd ├── gwr.t.adjust.rd ├── gwr.write.Rd ├── gwss.montecarlo.Rd └── gwss.rd ├── readme.txt └── src ├── GWmodel.cpp ├── GWmodelCUDA ├── CGWmodelCUDA.cpp ├── CGWmodelCUDA.h ├── CMakeLists.txt ├── GWmodelKernel.cu ├── GWmodelKernel.h ├── IGWmodelCUDA.cpp ├── IGWmodelCUDA.h ├── cmake │ └── FindcuBLAS.cmake └── helper.h ├── Makevars.in ├── Makevars.win ├── RcppExports.cpp ├── download.ps1 └── init.c /.gitignore: -------------------------------------------------------------------------------- 1 | GWmodel_*.tar.gz 2 | debug.log -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: GWmodel 2 | Type: Package 3 | Version: 2.2-0 4 | Date: 2020-10-11 5 | Title: Geographically-Weighted Models 6 | Depends: R (>= 3.0.0),maptools (>= 0.5-2), 7 | robustbase,sp (> 1.4-0),Rcpp,spatialreg 8 | Imports: methods, grDevices, stats,graphics,spacetime,spdep,FNN 9 | LinkingTo: Rcpp, RcppArmadillo 10 | Suggests: mvoutlier, RColorBrewer, gstat,spData 11 | Description: Techniques from a particular branch of spatial statistics,termed geographically-weighted (GW) models. GW models suit situations when data are not described well by some global model, but where there are spatial regions where a suitably localised calibration provides a better description. 'GWmodel' includes functions to calibrate: GW summary statistics (Brunsdon et al. 2002), GW principal components analysis (Harris et al. 2011), GW discriminant analysis (Brunsdon et al. 2007) and various forms of GW regression (Brunsdon et al. 1996); some of which are provided in basic and robust (outlier resistant) forms. 12 | Author: Binbin Lu[aut], Paul Harris[aut], Martin Charlton[aut], Chris Brunsdon[aut], Tomoki Nakaya[aut], Daisuke Murakami[aut],Isabella Gollini[ctb], Yigong Hu[ctb], Fiona H Evans[ctb] 13 | Maintainer: Binbin Lu 14 | License: GPL (>= 2) 15 | Repository: CRAN 16 | URL: http://gwr.nuim.ie/ 17 | NeedsCompilation: yes -------------------------------------------------------------------------------- /GWmodel/.gitignore: -------------------------------------------------------------------------------- 1 | /src-* 2 | **/*.o 3 | **/*.so 4 | **/*.lib 5 | **/*.dll 6 | **/*.exe 7 | **/*.log 8 | /src/GWmodelCUDA/build 9 | /src/Makevars 10 | config.* 11 | -------------------------------------------------------------------------------- /GWmodel/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: GWmodel 2 | Type: Package 3 | <<<<<<< HEAD 4 | Version: 2.2-5 5 | Date: 2021-04-11 6 | ======= 7 | Version: 2.2-3 8 | Date: 2021-02-03 9 | >>>>>>> master 10 | Title: Geographically-Weighted Models 11 | Depends: R (>= 3.0.0),maptools (>= 0.5-2), robustbase,sp (> 12 | 1.4-0),Rcpp,spatialreg 13 | Imports: methods, grDevices, stats,graphics,spacetime,spdep,FNN 14 | LinkingTo: Rcpp, RcppArmadillo 15 | Suggests: mvoutlier, RColorBrewer, gstat,spData 16 | Description: Techniques from a particular branch of spatial statistics,termed geographically-weighted (GW) models. GW models suit situations when data are not described well by some global model, but where there are spatial regions where a suitably localised calibration provides a better description. 'GWmodel' includes functions to calibrate: GW summary statistics (Brunsdon et al., 2002), GW principal components analysis (Harris et al., 2011), GW discriminant analysis (Brunsdon et al., 2007) and various forms of GW regression (Brunsdon et al., 1996); some of which are provided in basic and robust (outlier resistant) forms. 17 | Author: Binbin Lu[aut], Paul Harris[aut], Martin Charlton[aut], Chris Brunsdon[aut], Tomoki Nakaya[aut], Daisuke Murakami[aut],Isabella Gollini[ctb], Yigong Hu[ctb], Fiona H Evans[ctb] 18 | Maintainer: Binbin Lu 19 | License: GPL (>= 2) 20 | Repository: CRAN 21 | URL: http://gwr.nuim.ie/ 22 | NeedsCompilation: yes 23 | SystemRequirements: GNU make 24 | -------------------------------------------------------------------------------- /GWmodel/NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(GWmodel) 2 | import(Rcpp) 3 | import(maptools) 4 | import(robustbase) 5 | import(sp) 6 | import(stats) 7 | import(spacetime) 8 | import(spatialreg) 9 | import(parallel) 10 | importFrom(FNN, get.knn) 11 | importFrom("grDevices", "grey", "rainbow", "rgb") 12 | importFrom("methods", "as", "is", "slot") 13 | importFrom("graphics", "abline", "axis", "hist", "identify", "legend", 14 | "lines", "points", "rect", "text") 15 | importFrom("spdep", "knearneigh", "poly2nb", "nb2listw","listw2mat","knn2nb") 16 | export(gwr.scalable,gwr.scalable.loocv,AICc1, gwr_diag1,scgwr_loocv,scgwr_pre,scgwr_reg,bw.gtwr, gtwr.aic, gtwr, ti.distv, ti.distm,ti.dist,get.before.ti, get.ts, sdist.mat,tdist.mat, get.uloat,st.dist, gwr.bootstrap,generate.lm.data,parametric.bs,parametric.bs.local,se.bs,bias.bs,ci.bs,pval.bs,gwrtvar,gwrt.mlr,gwrt.lag,gwrt.err,gwrt.sma,bw.gwr3,gwr.multiscale,gwr.backfit,gwr.q2, confusion.matrix,gwss.montecarlo,gwda,print.gwda,grouping.xy,wqda,wlda,splitx,wmean,wvarcov,wprior,bw.gwda,wqda.cr,wlda.cr,gwr.hetero,gwr.mixed,gwr.mixed.2,gwr.mixed.trace.fast, gwr.mixed.trace, gwr.mixed.trace.fast,print.mgwr,gwr.q,gwr.collin.diagno,plot.mcsims,bw.gwr, gwr.cv,gwr.cv.contrib, gwr.aic, gold, gw.dist, gw.weight, gwr.basic, F1234.test,extract.mat,Generate.formula,gwr.generalised,gwr.poisson,gwr.binomial,gwss,bw.ggwr,ggwr.basic,ggwr.cv,ggwr.cv.contrib,ggwr.aic,gwr.poisson.wt,gwr.binomial.wt,wpca,robustSvd,wt.median,rwpca,gwpca,bw.gwpca,gwpca.cv,gwpca.cv.contrib,gwr.lcr,ridge.lm,bw.gwr.lcr,gwr.lcr.cv,gwr.lcr.cv.contrib,gwr.t.adjust,gwr.predict,gwr.robust,gw.pcplot,bw.gwr1,gwr.aic1,gwr.cv1,plot.pvlas,gw_reg,gw.fitted,ehat,rss,gwr_diag,AICc,AICc_rss,Ci_mat,gwss.montecarlo,gwpca.montecarlo.1,gwpca.montecarlo.2,gwr.model.selection,gwr.model.view,gwr.model.sort,gwr.montecarlo,gwr.write,gwr.write.shp,gwpca.glyph.plot,gwpca.check.components,gwr.mink.approach,gwr.mink.matrixview,gwr.mink.pval,gwr.mink.pval.forward,gwr.mink.pval.backward,gw.mean.cv,gw.median.cv,gw.average.cv,gw.average.cv.contrib,bw.gwss.average,montecarlo.gwss,montecarlo.gwpca.1,montecarlo.gwpca.2,model.selection.gwr,model.view.gwr,model.sort.gwr,montecarlo.gwr,writeGWR,writeGWR.shp,glyph.plot,check.components,mink.approach,mink.matrixview,gwr_q,gwr_mixed_trace, gwr_mixed_2,gw_dist,gw_weight, gw_weight_vec, gw_weight_mat, gw_reg, gw_reg_1, trhat2, fitted, ehat, rss, gwr_diag, gwr_diag1, AICc, AICc1, AICc_rss, AICc_rss1, Ci_mat, gw_local_r2, BIC, gw_reg_2, gwr_q, scgwr_pre, scgwr_reg, scgwr_loocv, gw_reg_all, gw_reg_all_omp, gw_reg_all_cuda, gw_cv_all, gw_cv_all_omp, gw_cv_all_cuda, e_vec, gwr_mixed_trace, gwr_mixed_2) 17 | useDynLib(GWmodel, .registration = TRUE) 18 | 19 | S3method(print, mcsims) 20 | S3method(print, gwrm) 21 | S3method(print, ggwrm) 22 | S3method(print, gwss) 23 | S3method(print, gwrlcr) 24 | S3method(print, gwrm.pred) 25 | S3method(plot, mcsims) 26 | S3method(plot, pvlas) 27 | S3method(print, gwda) 28 | S3method(print, mgwr) 29 | S3method(print, gwrbsm) 30 | S3method(print, multiscalegwr) 31 | S3method(print, gtwrm) 32 | S3method(print, gwpca) 33 | S3method(print, scgwrm) -------------------------------------------------------------------------------- /GWmodel/R/gw.average.cv.contrib.R: -------------------------------------------------------------------------------- 1 | gw.average.cv.contrib<- function(bw, X, kernel, adaptive, dp.locat, p, theta, longlat, dMat) 2 | { 3 | findmedian <- function(x, w) { 4 | lw <- length(w) 5 | xo <- sort(x) 6 | wo <- w[order(x)] 7 | 8 | cond <- max({ cumsum(wo) <= 0.5} * seq(1:lw)) 9 | if (cond == 0) 10 | cond <- 1 11 | xo[cond] 12 | } 13 | 14 | dp.n <- length(dp.locat[, 1]) 15 | if (is.null(dMat)) 16 | DM.given <- F 17 | else { 18 | DM.given <- T 19 | dim.dMat <- dim(dMat) 20 | if (dim.dMat[1] != dp.n || dim.dMat[2] != dp.n) 21 | stop("Dimensions of dMat are not correct") 22 | } 23 | CV.mean <- numeric(dp.n) 24 | CV.median <- numeric(dp.n) 25 | for (i in 1:dp.n) { 26 | if (DM.given) 27 | dist.vi <- dMat[, i] 28 | else { 29 | dist.vi <- gw.dist(dp.locat = dp.locat, focus = i, 30 | p = p, theta = theta, longlat = longlat) 31 | } 32 | W.i <- matrix(gw.weight(dist.vi, bw, kernel, adaptive),nrow=1) 33 | sum.w <- sum(W.i) 34 | Wi <- W.i/sum.w 35 | l.mean<-Wi%*%X 36 | l.median<- findmedian(X, w = c(Wi)) 37 | Wi <- Wi[-i] 38 | Wi<-Wi/sum(Wi) 39 | l.mean.resi <- try(sum(Wi*X[-i])) 40 | l.median.resi<- try(findmedian(X[-i], w = Wi)) 41 | 42 | if (!inherits(l.mean.resi, "try-error")) { 43 | CV.mean[i] <- l.mean - l.mean.resi 44 | } 45 | else { 46 | CV.mean[i] <- Inf 47 | break 48 | } 49 | 50 | if (!inherits(l.median.resi, "try-error")) { 51 | CV.median[i] <- l.median - l.median.resi 52 | } 53 | else { 54 | CV.median[i] <- Inf 55 | break 56 | } 57 | } 58 | CV<-cbind(CV.mean,CV.median) 59 | colnames(CV)<-c('Local Mean','Local Median') 60 | CV 61 | } -------------------------------------------------------------------------------- /GWmodel/R/gw.dist.r: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # gw.dist: caculate a distance vector or distance matrix between (a) regression point and data points 3 | # dp.locat: numeric vector of two colunms, coordinates of data points 4 | # rp.locat: numeric vector of two colunms, coordinates of regression points 5 | # focus: an integer, indexing to the current regression point, if focus=0, all the distances between all the regression points and data points will be calculated and a distance matrix will be returned; 6 | # if 0 length(rp.locat[,1])) 22 | stop("No regression point is fixed") 23 | dists <- gw_dist(dp.locat, rp.locat, focus - 1, ifelse(is.infinite(p), -1, p), theta, longlat, T) 24 | } 25 | else dists <- gw_dist(dp.locat, dp.locat, focus - 1, ifelse(is.infinite(p), -1, p), theta, longlat, F) 26 | dists 27 | } 28 | -------------------------------------------------------------------------------- /GWmodel/R/gw.weight.r: -------------------------------------------------------------------------------- 1 | ################## NAME: gw.weight ################### 2 | ## ARGUMENTS IN: 3 | #### vdist: numeric vector or matrix of distances (from gw.dist.r) 4 | #### bw: scalar, bandwidth or number of nearest neighbours 5 | #### kernel: text vector of function chosen 6 | ########## boxcar: wgt=1 if dist < bw, wgt=0 otherwise 7 | ########## gaussian: wgt = exp(-.5*(vdist/bw)^2) 8 | ########## bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise 9 | ########## tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise 10 | ########## adaptive: if TRUE calulate the adaptive kernel, and bw correspond to the number of nearest neighbour 11 | #### 12 | ## ARGUMENTS OUT: 13 | #### if vdist is a vector the output is a vector of weights of the length of vdist 14 | #### if vdist is a matrix the output is a matrix of weights of the dim of vdist, containing in column i the weights for observation i 15 | ## REFERENCES: Book pg 56-57 16 | ######################## 17 | ####C++ code embeded at 31/01/2021 18 | 19 | # MAIN FUNCTION 20 | 21 | gw.weight <-function(vdist,bw,kernel,adaptive=FALSE){ 22 | if (is.matrix(vdist)) 23 | { 24 | wgt <- gw_weight_mat(vdist,bw,kernel,adaptive) 25 | } 26 | else 27 | { 28 | wgt <- gw_weight_vec(vdist,bw,kernel,adaptive) 29 | } 30 | 31 | wgt 32 | } 33 | -------------------------------------------------------------------------------- /GWmodel/R/gwr.robust.r: -------------------------------------------------------------------------------- 1 | gwr.robust<-function(formula, data, bw,filtered=FALSE, kernel = "bisquare", adaptive = FALSE, p = 2, theta = 0, longlat = F, dMat, F123.test = F, 2 | maxiter=20,cut.filter= 3,cut1=2,cut2=3,delta=1.0e-5) 3 | { 4 | W.vect<-NULL 5 | res1<- gwr.basic(formula=formula, data=data, bw=bw, kernel=kernel, adaptive=adaptive, p=p, theta=theta, longlat=longlat, dMat=dMat, F123.test=F123.test, cv=T,W.vect=W.vect) 6 | if(filtered==TRUE){ 7 | W.vect<-as.numeric(abs(res1$SDF$Stud_residual) cut1 18 | xg3 <- x > cut2 19 | span <- cut2 - cut1 20 | result[xg2] <- (1 - ((x[xg2]-cut1)/span)^2)^2 21 | result[xg3] <- rep(0,sum(xg3)) 22 | result 23 | } 24 | 25 | iter<-0 26 | diffmse<-1 27 | err<-res1$SDF$residual 28 | mse<- sum(err*err)/length(err) 29 | W.vect <- filt(abs(err/sqrt(mse))) 30 | W.vect[is.na(W.vect)]<-0 31 | 32 | while(diffmse>delta & iter>>>>>> master 7 | } -------------------------------------------------------------------------------- /GWmodel/cleanup: -------------------------------------------------------------------------------- 1 | #!/bin/sh +x 2 | 3 | rm -rf src/*.o src/*.so 4 | 5 | rm -rf config.log config.status autom4te.cache 6 | 7 | rm -rf src/tmp src/GWmodelCUDA.zip 8 | 9 | rm -rf src/GWmodelCUDA*.dll src/GWmodelCUDA/*.lib 10 | -------------------------------------------------------------------------------- /GWmodel/configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([GWmodel], 2.2-0) 2 | 3 | AC_LANG(C++) 4 | AC_REQUIRE_CPP 5 | 6 | echo "Checking for C++ Compiler" 7 | AC_PROG_CXX 8 | 9 | ENABLE_CUDA=0 10 | 11 | 12 | AC_ARG_ENABLE([cuda], [AS_HELP_STRING([--enable-cuda],[install cuda (default no)])], 13 | [ case "${enableval}" in 14 | yes) ENABLE_CUDA=1 ;; 15 | no) ENABLE_CUDA=0 ;; 16 | *) AC_MSG_ERROR(bad value ${enableval} for --enable-cuda) ;; 17 | esac]) 18 | 19 | if test ${ENABLE_CUDA} -eq 1; then 20 | AC_MSG_CHECKING("Checking environment variable CUDA_HOME") 21 | if test -z "${CUDA_HOME}"; then 22 | AC_MSG_RESULT("CUDA_HOME not set, stop finding nvcc") 23 | else 24 | AC_MSG_RESULT("using CUDA_HOME=${CUDA_HOME}") 25 | fi 26 | 27 | if test -z "${CUDA_HOME}"; then 28 | if test ${ENABLE_CUDA} -eq 1; then 29 | echo " 30 | It seams that you don't have CUDA environment and the --enable-cuda is yes 31 | 32 | Please make sure your cuda environment is under the /usr/local directory 33 | 34 | If you don't want to install cuda function, please set `--enable-cuda=no` 35 | " 36 | exit 1 37 | fi 38 | fi 39 | 40 | if test ${ENABLE_CUDA} -eq 1; then 41 | AC_MSG_CHECKING("whether this is the 64 bit linux version of CUDA") 42 | AC_CHECK_FILE([${CUDA_HOME}/lib64/libcudart.so], [BIT64="yes"]) 43 | if test -z "${BIT64}"; then 44 | AC_MSG_RESULT("no -- using ${CUDA_HOME}/lib for CUDA libs") 45 | cu_libdir="${CUDA_HOME}/lib" 46 | AC_SUBST(CUDA_LIBDIR,["$cu_libdir"]) 47 | else 48 | AC_MSG_RESULT("yes -- using ${CUDA_HOME}/lib64 for CUDA libs") 49 | cu_libdir="${CUDA_HOME}/lib64" 50 | AC_SUBST(CUDA_LIBDIR,["$cu_libdir"]) 51 | fi 52 | else 53 | AC_SUBST(CUDA_LIBDIR,[""]) 54 | fi 55 | fi 56 | 57 | if test ${ENABLE_CUDA} -eq 1; then 58 | AC_MSG_RESULT(You have CUDA environment and we will compile the cuda function for you) 59 | cu_sources="GWmodelKernel.cu" 60 | cu_sharedlibs="GWmodelKernel.o" 61 | cpp_sources_cuda="CGWmodelCUDA.cpp IGWmodelCUDA.cpp" 62 | cpp_sharedlibs_cuda="CGWmodelCUDA.o IGWmodelCUDA.o" 63 | OBJECTS_CUDA="${cu_sharedlibs} ${cpp_sharedlibs_cuda}" 64 | 65 | CDEFS="-DCUDA_ACCE" 66 | TARGET_CUDA_LIB="libgwmodelcuda.so" 67 | 68 | CUDA_LIBS="-L${CUDA_LIBDIR} -Wl,-rpath=${CUDA_LIBDIR} -lcudart -lcublas " 69 | PKG_LIBS=${PKG_LIBS}"${CUDA_LIBS} -L${HOME}/.cache/GWmodel -Wl,-rpath=${HOME}/.cache/GWmodel -lgwmodelcuda" 70 | AC_SUBST(cu_sources) 71 | AC_SUBST(cu_sharedlibs) 72 | AC_SUBST(cpp_sources_cuda) 73 | AC_SUBST(cpp_sharedlibs_cuda) 74 | AC_SUBST(OBJECTS_CUDA) 75 | AC_SUBST(CDEFS) 76 | AC_SUBST(TARGET_CUDA_LIB) 77 | AC_SUBST(CUDA_LIBS) 78 | fi 79 | 80 | 81 | AC_MSG_RESULT(building the nvcc command line) 82 | NVCC="${CUDA_HOME}/bin/nvcc" 83 | AC_MSG_RESULT(building the cuda include path) 84 | CUDA_INCL="${CUDA_HOME}/include" 85 | 86 | AC_SUBST(GWmodel_CUDA_LIB_PATH,["~/.cache/GWmodel"]) 87 | 88 | AC_MSG_NOTICE([Building Makevars]) 89 | AC_SUBST(CU_INCL) 90 | AC_SUBST(NVCC) 91 | AC_SUBST(PKG_LIBS) 92 | AC_SUBST(CUDA_INCL) 93 | AC_SUBST(ENABLE_CUDA) 94 | AC_OUTPUT(src/Makevars) 95 | -------------------------------------------------------------------------------- /GWmodel/data/DubVoter.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbb220/GWmodel/d26fc76c84d0e5ff6672f5290cd9d44aabdec50c/GWmodel/data/DubVoter.rda -------------------------------------------------------------------------------- /GWmodel/data/EWHP.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbb220/GWmodel/d26fc76c84d0e5ff6672f5290cd9d44aabdec50c/GWmodel/data/EWHP.rda -------------------------------------------------------------------------------- /GWmodel/data/EWOutline.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbb220/GWmodel/d26fc76c84d0e5ff6672f5290cd9d44aabdec50c/GWmodel/data/EWOutline.rda -------------------------------------------------------------------------------- /GWmodel/data/GE2015.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbb220/GWmodel/d26fc76c84d0e5ff6672f5290cd9d44aabdec50c/GWmodel/data/GE2015.rda -------------------------------------------------------------------------------- /GWmodel/data/Georgia.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbb220/GWmodel/d26fc76c84d0e5ff6672f5290cd9d44aabdec50c/GWmodel/data/Georgia.rda -------------------------------------------------------------------------------- /GWmodel/data/GeorgiaCounties.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbb220/GWmodel/d26fc76c84d0e5ff6672f5290cd9d44aabdec50c/GWmodel/data/GeorgiaCounties.rda -------------------------------------------------------------------------------- /GWmodel/data/LondonBorough.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbb220/GWmodel/d26fc76c84d0e5ff6672f5290cd9d44aabdec50c/GWmodel/data/LondonBorough.rda -------------------------------------------------------------------------------- /GWmodel/data/LondonHP.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbb220/GWmodel/d26fc76c84d0e5ff6672f5290cd9d44aabdec50c/GWmodel/data/LondonHP.rda -------------------------------------------------------------------------------- /GWmodel/data/USelect.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lbb220/GWmodel/d26fc76c84d0e5ff6672f5290cd9d44aabdec50c/GWmodel/data/USelect.rda -------------------------------------------------------------------------------- /GWmodel/data/datalist: -------------------------------------------------------------------------------- 1 | DubVoter: Dub.voter 2 | EWHP: ewhp 3 | EWOutline: ewoutline 4 | Georgia: Gedu.df 5 | GeorgiaCounties: Gedu.counties 6 | LondonBorough: londonborough 7 | LondonHP: londonhp 8 | USelect: USelect2004 9 | -------------------------------------------------------------------------------- /GWmodel/inst/CITATION: -------------------------------------------------------------------------------- 1 | citHeader("To cite GWmodel in publications use:") 2 | 3 | citEntry(entry = "Article", 4 | title = "{GWmodel}: An {R} Package for Exploring Spatial Heterogeneity Using Geographically Weighted Models", 5 | author = personList(as.person("Isabella Gollini"), 6 | as.person("Binbin Lu"), 7 | as.person("Martin Charlton"), 8 | as.person("Christopher Brunsdon"), 9 | as.person("Paul Harris")), 10 | journal = "Journal of Statistical Software", 11 | year = "2015", 12 | volume = "63", 13 | number = "17", 14 | pages = "1--50", 15 | url = "https://www.jstatsoft.org/article/view/v063i17", 16 | 17 | textVersion = 18 | paste("Isabella Gollini, Binbin Lu, Martin Charlton, Christopher Brunsdon, Paul Harris (2015).", 19 | "GWmodel: An R Package for Exploring Spatial Heterogeneity Using Geographically Weighted Models.", 20 | "Journal of Statistical Software, 63(17), 1-50.", 21 | "URL http://www.jstatsoft.org/v63/i17/.") 22 | ) 23 | 24 | citEntry(entry = "Article", 25 | title = "The {GWmodel} {R} package: further topics for exploring spatial heterogeneity using geographically weighted models", 26 | author = personList(as.person("Binbin Lu"), 27 | as.person("Paul Harris"), 28 | as.person("Martin Charlton"), 29 | as.person("Christopher Brunsdon")), 30 | journal = "Geo-spatial Information Science", 31 | year = "2014", 32 | volume = "17", 33 | number = "2", 34 | pages = "85--101", 35 | url = "https://www.tandfonline.com/doi/abs/10.1080/10095020.2014.917453", 36 | 37 | textVersion = 38 | paste("Binbin Lu, Paul Harris, Martin Charlton, Christopher Brunsdon (2014).", 39 | "The GWmodel R package: further topics for exploring spatial heterogeneity using geographically weighted models.", 40 | "Geo-spatial Information Science, 17(2), 85-101.", 41 | "URL https://www.tandfonline.com/doi/abs/10.1080/10095020.2014.917453") 42 | ) -------------------------------------------------------------------------------- /GWmodel/man/DubVoter.rd: -------------------------------------------------------------------------------- 1 | \name{DubVoter} 2 | \alias{DubVoter} 3 | \alias{Dub.voter} 4 | \docType{data} 5 | \title{Voter turnout data in Greater Dublin(SpatialPolygonsDataFrame)} 6 | \description{ 7 | Voter turnout and social characters data in Greater Dublin for the 2002 General election and the 2002 census. 8 | Note that this data set was originally thought to relate to 2004, so for continuity we have retained the associated variable names. 9 | } 10 | \usage{data(DubVoter)} 11 | \format{ 12 | A SpatialPolygonsDataFrame with 322 electoral divisions on the following 11 variables. 13 | \describe{ 14 | \item{DED_ID}{a vector of ID} 15 | \item{X}{a numeric vector of x coordinates} 16 | \item{Y}{a numeric vector of y coordinates} 17 | \item{DiffAdd}{percentage of the population in each ED who are one-year migrants (i.e. moved to a different address 1 year ago)} 18 | \item{LARent}{percentage of the population in each ED who are local authority renters} 19 | \item{SC1}{percentage of the population in each ED who are social class one (high social class)} 20 | \item{Unempl}{percentage of the population in each ED who are unemployed} 21 | \item{LowEduc}{percentage of the population in each ED who are with little formal education} 22 | \item{Age18_24}{percentage of the population in each ED who are age group 18-24} 23 | \item{Age25_44}{percentage of the population in each ED who are age group 25-44} 24 | \item{Age45_64}{percentage of the population in each ED who are age group 45-64} 25 | \item{GenEl2004}{percentage of population in each ED who voted in 2004 election} 26 | } 27 | } 28 | \details{ 29 | Variables are from DubVoter.shp. 30 | } 31 | \references{ 32 | Kavanagh A (2006) Turnout or turned off? Electoral participation in Dublin in the early 21st Century. Journal of Irish Urban Studies 3(2):1-24 33 | 34 | Harris P, Brunsdon C, Charlton M (2011) Geographically weighted principal components analysis. International Journal of Geographical Information Science 25 (10):1717-1736 35 | } 36 | \examples{ 37 | 38 | data(DubVoter) 39 | ls() 40 | \dontrun{ 41 | spplot(Dub.voter,names(Dub.voter)[4:12]) 42 | } 43 | } 44 | \keyword{data} 45 | \concept{Dublin Voter turnout} 46 | -------------------------------------------------------------------------------- /GWmodel/man/EWHP.Rd: -------------------------------------------------------------------------------- 1 | \name{EWHP} 2 | \alias{EWHP} 3 | \alias{ewhp} 4 | \docType{data} 5 | \title{House price data set (DataFrame) in England and Wales} 6 | \description{ 7 | A house price data set for England and Wales from 2001 with 9 hedonic (explanatory) variables. 8 | } 9 | \usage{data(EWHP)} 10 | \format{ 11 | A data frame with 519 observations on the following 12 variables. 12 | \describe{ 13 | \item{Easting}{a numeric vector, X coordinate} 14 | \item{Northing}{a numeric vector, Y coordinate} 15 | \item{PurPrice}{a numeric vector, the purchase price of the property} 16 | \item{BldIntWr}{a numeric vector, 1 if the property was built during the world war, 0 otherwise} 17 | \item{BldPostW}{a numeric vector, 1 if the property was built after the world war, 0 otherwise} 18 | \item{Bld60s}{a numeric vector, 1 if the property was built between 1960 and 1969, 0 otherwise} 19 | \item{Bld70s}{a numeric vector, 1 if the property was built between 1970 and 1979, 0 otherwise} 20 | \item{Bld80s}{a numeric vector, 1 if the property was built between 1980 and 1989, 0 otherwise} 21 | \item{TypDetch}{a numeric vector, 1 if the property is detached (i.e. it is a stand-alone house), 0 otherwise} 22 | \item{TypSemiD}{a numeric vector, 1 if the property is semi detached, 0 otherwise} 23 | \item{TypFlat}{a numeric vector, if the property is a flat (or 'apartment' in the USA), 0 otherwise} 24 | \item{FlrArea}{a numeric vector, floor area of the property in square metres} 25 | } 26 | } 27 | \references{ 28 | Fotheringham, A.S., Brunsdon, C., and Charlton, M.E. (2002), Geographically Weighted Regression: 29 | The Analysis of Spatially Varying Relationships, Chichester: Wiley. 30 | } 31 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 32 | \examples{ 33 | ### 34 | data(EWHP) 35 | head(ewhp) 36 | houses.spdf <- SpatialPointsDataFrame(ewhp[, 1:2], ewhp) 37 | ####Get the border of England and Wales 38 | data(EWOutline) 39 | plot(ewoutline) 40 | plot(houses.spdf, add = TRUE, pch = 16) 41 | } 42 | \keyword{data} 43 | \concept{house price} 44 | -------------------------------------------------------------------------------- /GWmodel/man/EWOutline.rd: -------------------------------------------------------------------------------- 1 | \name{EWOutline} 2 | \alias{ewoutline} 3 | \docType{data} 4 | \title{Outline of England and Wales for data \link{EWHP}} 5 | \description{ 6 | Outline (SpatialPolygonsDataFrame) of the England and Wales house price data \link{EWHP}. 7 | } 8 | \usage{data(EWOutline)} 9 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 10 | \keyword{data} 11 | \concept{England-Wales outline} 12 | -------------------------------------------------------------------------------- /GWmodel/man/GWmodel-package.Rd: -------------------------------------------------------------------------------- 1 | \name{GWmodel-package} 2 | \alias{GWmodel-package} 3 | \alias{GWmodel} 4 | \docType{package} 5 | \title{ 6 | Geographically-Weighted Models 7 | } 8 | \description{ 9 | In GWmodel, we introduce techniques from a particular branch of spatial statistics, 10 | termed geographically-weighted (GW) models. GW models suit situations when data are 11 | not described well by some global model, but where there are spatial regions where 12 | a suitably localised calibration provides a better description. GWmodel includes functions 13 | to calibrate: GW summary statistics, GW principal components analysis, GW discriminant analysis 14 | and various forms of GW regression; some of which are provided in basic and robust (outlier resistant) forms. 15 | In particular, the high-performence computing technologies, including multi-thread and CUDA techniques are started 16 | to be adopted for efficient calibrations. 17 | } 18 | \details{ 19 | \tabular{ll}{ 20 | Package: \tab GWmodel\cr 21 | Type: \tab Package\cr 22 | <<<<<<< HEAD 23 | Version: \tab 2.2-4\cr 24 | Date: \tab 2021-02-13\cr 25 | ======= 26 | Version: \tab 2.2-3\cr 27 | Date: \tab 2021-02-06\cr 28 | >>>>>>> master 29 | License: \tab GPL (>=2)\cr 30 | LazyLoad: \tab yes\cr 31 | } 32 | 33 | } 34 | \author{ 35 | Binbin Lu, Paul Harris, Martin Charlton, Chris Brunsdon, Tomoki Nakaya, Daisuke Murakami,Isabella Gollini[ctb], Yigong Hu[ctb], Fiona H Evans[ctb] 36 | 37 | Maintainer: Binbin Lu 38 | } 39 | \note{ 40 | Acknowledgements: We gratefully acknowledge support from National Natural Science Foundation of China (42071368); Science Foundation Ireland 41 | under the National Development Plan through the award of a Strategic Research Centre 42 | grant 07-SRC-I1168. 43 | 44 | Beta versions can always be found at \url{https://github.com/lbb220/GWmodel}, 45 | which includes all the newly developed functions for GW models. 46 | 47 | For latest tutorials on using GWmodel please go to: \url{https://rpubs.com/gwmodel} 48 | } 49 | 50 | \references{ 51 | Gollini I, Lu B, Charlton M, Brunsdon C, Harris P (2015) GWmodel: an R Package 52 | for exploring Spatial Heterogeneity using Geographically Weighted Models. Journal 53 | of Statistical Software, 63(17):1-50, \url{https://www.jstatsoft.org/article/view/v063i17} 54 | 55 | Lu B, Harris P, Charlton M, Brunsdon C (2014) The GWmodel R Package: further 56 | topics for exploring Spatial Heterogeneity using Geographically Weighted Models. 57 | Geo-spatial Information Science 17(2): 85-101, 58 | \url{https://www.tandfonline.com/doi/abs/10.1080/10095020.2014.917453} 59 | } 60 | \keyword{package} 61 | -------------------------------------------------------------------------------- /GWmodel/man/Georgia.Rd: -------------------------------------------------------------------------------- 1 | \name{Georgia} 2 | \alias{Georgia} 3 | \alias{Gedu.df} 4 | \docType{data} 5 | \title{Georgia census data set (csv file)} 6 | \description{ 7 | Census data from the county of Georgia, USA 8 | } 9 | \usage{data(Georgia)} 10 | \format{ 11 | A data frame with 159 observations on the following 13 variables. 12 | \describe{ 13 | \item{AreaKey}{An identification number for each county} 14 | \item{Latitude}{The latitude of the county centroid} 15 | \item{Longitud}{The longitude of the county centroid} 16 | \item{TotPop90}{Population of the county in 1990} 17 | \item{PctRural}{Percentage of the county population defined as rural} 18 | \item{PctBach}{Percentage of the county population with a bachelors degree} 19 | \item{PctEld}{Percentage of the county population aged 65 or over} 20 | \item{PctFB}{Percentage of the county population born outside the US} 21 | \item{PctPov}{Percentage of the county population living below the poverty line} 22 | \item{PctBlack}{Percentage of the county population who are black} 23 | \item{ID}{a numeric vector of IDs} 24 | \item{X}{a numeric vector of x coordinates} 25 | \item{Y}{a numeric vector of y coordinates} 26 | } 27 | } 28 | \details{ 29 | This data set can also be found in GWR 3 and in spgwr. 30 | } 31 | \references{ 32 | Fotheringham S, Brunsdon, C, and Charlton, M (2002), 33 | Geographically Weighted Regression: The Analysis of Spatially Varying Relationships, Chichester: Wiley. 34 | } 35 | \examples{ 36 | data(Georgia) 37 | ls() 38 | coords <- cbind(Gedu.df$X, Gedu.df$Y) 39 | educ.spdf <- SpatialPointsDataFrame(coords, Gedu.df) 40 | spplot(educ.spdf, names(educ.spdf)[4:10]) 41 | } 42 | \keyword{data} 43 | \concept{Georgia census} 44 | -------------------------------------------------------------------------------- /GWmodel/man/GeorgiaCounties.rd: -------------------------------------------------------------------------------- 1 | \name{GeorgiaCounties} 2 | \alias{Gedu.counties} 3 | \docType{data} 4 | \title{Georgia counties data (SpatialPolygonsDataFrame)} 5 | \description{ 6 | The Georgia census data with boundaries for mapping 7 | } 8 | \usage{data(GeorgiaCounties)} 9 | \details{ 10 | This data set can also be found in GWR 3 and in spgwr. 11 | } 12 | \examples{ 13 | data(GeorgiaCounties) 14 | plot(Gedu.counties) 15 | data(Georgia) 16 | coords <- cbind(Gedu.df$X, Gedu.df$Y) 17 | educ.spdf <- SpatialPointsDataFrame(coords, Gedu.df) 18 | plot(educ.spdf, add=TRUE) 19 | 20 | } 21 | \keyword{data} 22 | \concept{Georgia counties} 23 | -------------------------------------------------------------------------------- /GWmodel/man/LondonBorough.rd: -------------------------------------------------------------------------------- 1 | \name{LondonBorough} 2 | \alias{LondonBorough} 3 | \alias{londonborough} 4 | \docType{data} 5 | \title{London boroughs data} 6 | \description{ 7 | Outline (SpatialPolygonsDataFrame) of London boroughs for the \link{LondonHP} data. 8 | } 9 | \usage{data(LondonBorough)} 10 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 11 | \keyword{data} 12 | \concept{London Boroughs} 13 | -------------------------------------------------------------------------------- /GWmodel/man/LondonHP.Rd: -------------------------------------------------------------------------------- 1 | \name{LondonHP} 2 | \alias{LondonHP} 3 | \alias{londonhp} 4 | \docType{data} 5 | \title{London house price data set (SpatialPointsDataFrame)} 6 | \description{ 7 | A house price data set with 18 hedonic variables for London in 2001. 8 | } 9 | \usage{data(LondonHP)} 10 | \format{ 11 | A SpatialPointsDataFrame object (proj4string set to "+init=epsg:27700 +datum=OSGB36"). 12 | 13 | The "data" slot is a data frame with 372 observations on the following 21 variables. 14 | \describe{ 15 | \item{X}{a numeric vector, X coordinate} 16 | \item{Y}{a numeric vector, Y coordinate} 17 | \item{PURCHASE}{a numeric vector, the purchase price of the property} 18 | \item{FLOORSZ}{a numeric vector, floor area of the property in square metres} 19 | \item{TYPEDETCH}{a numeric vector, 1 if the property is detached (i.e. it is a stand-alone house), 0 otherwise} 20 | \item{TPSEMIDTCH}{a numeric vector, 1 if the property is semi detached, 0 otherwise} 21 | \item{TYPETRRD}{a numeric vector, 1 if the property is in a terrace of similar houses (commonly referred to as a 'row house' in the USA), 0 otherwise} 22 | \item{TYPEBNGLW}{a numeric vector, if the property is a bungalow (i.e. it has only one floor), 0 otherwise} 23 | \item{TYPEFLAT}{a numeric vector, if the property is a flat (or 'apartment' in the USA), 0 otherwise} 24 | \item{BLDPWW1}{a numeric vector, 1 if the property was built prior to 1914, 0 otherwise} 25 | \item{BLDPOSTW}{a numeric vector, 1 if the property was built between 1940 and 1959, 0 otherwise} 26 | \item{BLD60S}{a numeric vector, 1 if the property was built between 1960 and 1969, 0 otherwise} 27 | \item{BLD70S}{a numeric vector, 1 if the property was built between 1970 and 1979, 0 otherwise} 28 | \item{BLD80S}{a numeric vector, 1 if the property was built between 1980 and 1989, 0 otherwise} 29 | \item{BLD90S}{a numeric vector, 1 if the property was built between 1990 and 2000, 0 otherwise} 30 | \item{BATH2}{a numeric vector, 1 if the property has more than 2 bathrooms, 0 otherwise} 31 | \item{GARAGE}{a numeric vector,1 if the house has a garage, 0 otherwise} 32 | \item{CENTHEAT}{a numeric vector, 1 if the house has central heating, 0 otherwise} 33 | \item{BEDS2}{a numeric vector, 1 if the property has more than 2 bedrooms, 0 otherwise} 34 | \item{UNEMPLOY}{a numeric vector, the rate of unemployment in the census ward in which the house is located} 35 | \item{PROF}{a numeric vector, the proportion of the workforce in professional or managerial occupations in the census ward in which the house is located} 36 | } 37 | } 38 | \references{ 39 | Fotheringham, A.S., Brunsdon, C., and Charlton, M.E. (2002), Geographically Weighted Regression: 40 | The Analysis of Spatially Varying Relationships, Chichester: Wiley. 41 | 42 | Lu, B, Charlton, M, Harris, P, Fotheringham, AS (2014) Geographically weighted regression 43 | with a non-Euclidean distance metric: a case study using hedonic house price data. 44 | International Journal of Geographical Information Science 28(4): 660-681 45 | } 46 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 47 | \examples{ 48 | data(LondonHP) 49 | data(LondonBorough) 50 | ls() 51 | plot(londonborough) 52 | plot(londonhp, add=TRUE) 53 | } 54 | \keyword{data} 55 | \concept{house price} 56 | -------------------------------------------------------------------------------- /GWmodel/man/USelect.rd: -------------------------------------------------------------------------------- 1 | \name{USelect} 2 | \alias{USelect2004} 3 | \docType{data} 4 | \title{Results of the 2004 US presidential election at the county level (SpatialPolygonsDataFrame)} 5 | \description{ 6 | Results of the 2004 US presidential election at the county level, together with five socio-economic (census) variables. 7 | This data can be used with GW Discriminant Analysis. 8 | } 9 | \usage{data(USelect)} 10 | \format{ 11 | A SpatialPolygonsDataFrame with 3111 electoral divisions on the following 6 variables. 12 | \describe{ 13 | \item{winner}{Categorical variable with three classes: i) Bush, ii) Kerry and iii) Borderline (supporting ratio for a candidate ranges from 0.45 to 0.55)} 14 | \item{unemploy}{percentage unemployed} 15 | \item{pctcoled}{percentage of adults over 25 with 4 or more years of college education} 16 | \item{PEROVER65}{percentage of persons over the age of 65} 17 | \item{pcturban}{percentage urban} 18 | \item{WHITE}{percentage white} 19 | } 20 | } 21 | \references{ 22 | Robinson, A. C. (2013). Geovisualization of the 2004 Presidential Election. 23 | In: NATIONAL INSTITUTES OF HEALTH, P. S. U. (ed.). Penn State: 24 | \url{http://www.personal.psu.edu/users/a/c/acr181/election.html}. 25 | 26 | Foley, P. & Demsar, U. (2012). Using geovisual analytics to compare the 27 | performance of geographically weighted discriminant analysis versus its global 28 | counterpart, linear discriminant analysis. International Journal of Geographical 29 | Information Science, 27, 633-661. 30 | } 31 | \examples{ 32 | 33 | data(USelect) 34 | ls() 35 | } 36 | \keyword{data} 37 | \concept{US presidential election} 38 | -------------------------------------------------------------------------------- /GWmodel/man/bw.ggwr.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.ggwr} 2 | \alias{bw.ggwr} 3 | \alias{ggwr.aic} 4 | \title{Bandwidth selection for generalised geographically weighted regression (GWR)} 5 | \description{ 6 | A function for automatic bandwidth selection to calibrate a generalised GWR model 7 | } 8 | \usage{ 9 | bw.ggwr(formula, data, family ="poisson", approach="CV", 10 | kernel="bisquare",adaptive=FALSE, p=2, theta=0, longlat=F,dMat) 11 | } 12 | \arguments{ 13 | \item{formula}{Regression model formula of a \link{formula} object } 14 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 15 | \item{family}{a description of the error distribution and link function to 16 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 17 | \item{approach}{specified by CV for cross-validation approach or by AIC corrected (AICc) approach} 18 | \item{kernel}{function chosen as follows: 19 | 20 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 21 | 22 | exponential: wgt = exp(-vdist/bw); 23 | 24 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 25 | 26 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 27 | 28 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 29 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 30 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 31 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 32 | \item{longlat}{if TRUE, great circle distances will be calculated} 33 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 34 | } 35 | \note{ 36 | For a discontinuous kernel function, a bandwidth can be specified either as a fixed (constant) distance or 37 | as a fixed (constant) number of local data (i.e. an adaptive distance). For a continuous kernel function, 38 | a bandwidth can be specified either as a fixed distance or as a 'fixed quantity that reflects local sample size' 39 | (i.e. still an 'adaptive' distance but the actual local sample size will be the sample size as functions are continuous). 40 | In practise a fixed bandwidth suits fairly regular sample configurations whilst an adaptive bandwidth suits highly irregular 41 | sample configurations. Adaptive bandwidths ensure sufficient (and constant) local information for each local calibration. 42 | This note is applicable to all GW models 43 | } 44 | \value{ 45 | Returns the adaptive or fixed distance bandwidth 46 | } 47 | 48 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 49 | 50 | \keyword{generalised GWR} 51 | \concept{bandwidth selection} 52 | 53 | -------------------------------------------------------------------------------- /GWmodel/man/bw.gtwr.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.gtwr} 2 | \alias{bw.gtwr} 3 | \alias{gtwr.cv} 4 | \alias{gtwr.aic} 5 | \title{Bandwidth selection for GTWR} 6 | \description{ 7 | A function for automatic bandwidth selection to calibrate a GTWR model 8 | } 9 | \usage{ 10 | bw.gtwr(formula, data, obs.tv, approach="CV",kernel="bisquare",adaptive=FALSE, 11 | p=2, theta=0, longlat=F,lamda=0.05,t.units = "auto",ksi=0, st.dMat, 12 | verbose=T) 13 | } 14 | \arguments{ 15 | \item{formula}{Regression model formula of a \link{formula} object } 16 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 17 | \item{obs.tv}{a vector of time tags for each observation, which could be numeric or of \link{POSIXlt} class} 18 | \item{approach}{specified by CV for cross-validation approach or by AIC corrected (AICc) approach} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) 31 | corresponds to the number of nearest neighbours (i.e. adaptive distance); default 32 | is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 33 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 34 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 35 | \item{longlat}{if TRUE, great circle distances will be calculated} 36 | \item{lamda}{an parameter between 0 and 1 for calculating spatio-temporal distance} 37 | \item{t.units}{ character string to define time unit} 38 | \item{ksi}{an parameter between 0 and PI for calculating spatio-temporal distance, 39 | see details in Wu et al. (2014)} 40 | \item{st.dMat}{a pre-specified spatio-temporal distance matrix} 41 | \item{verbose}{logical variable to define whether show the selection procedure} 42 | } 43 | \note{ 44 | The function is developed according to the articles by Huang et al. (2010) and 45 | Wu et al. (2014). 46 | } 47 | 48 | \value{ 49 | Returns the adaptive or fixed distance bandwidth 50 | } 51 | \references{ 52 | Huang, B., Wu, B., & Barry, M. (2010). Geographically and temporally weighted 53 | regression for modeling spatio-temporal variation in house prices. International 54 | Journal of Geographical Information Science, 24, 383-401. 55 | 56 | Wu, B., Li, R., & Huang, B. (2014). A geographically and temporally weighted 57 | autoregressive model with application to housing prices. International Journal 58 | of Geographical Information Science, 28, 1186-1204. 59 | 60 | Fotheringham, A. S., Crespo, R., & Yao, J. (2015). Geographical and Temporal 61 | Weighted Regression (GTWR). Geographical Analysis, 47, 431-452. 62 | 63 | } 64 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 65 | 66 | \keyword{GTWR} 67 | \concept{bandwidth selection} 68 | -------------------------------------------------------------------------------- /GWmodel/man/bw.gwpca.rd: -------------------------------------------------------------------------------- 1 | \name{bw.gwpca} 2 | \alias{bw.gwpca} 3 | \title{Bandwidth selection for Geographically Weighted Principal Components Analysis (GWPCA)} 4 | \description{ 5 | A function for automatic bandwidth selection to calibrate a basic or robust GWPCA via a cross-validation approach only 6 | } 7 | \usage{ 8 | bw.gwpca(data,vars,k=2, robust=FALSE,kernel="bisquare",adaptive=FALSE,p=2, 9 | theta=0, longlat=F,dMat) 10 | } 11 | 12 | \arguments{ 13 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 14 | \item{vars}{a vector of variable names to be evaluated} 15 | \item{k}{the number of retained components, and it must be less than the number of variables} 16 | \item{robust}{if TRUE, robust GWPCA will be applied; otherwise basic GWPCA will be applied} 17 | \item{kernel}{function chosen as follows: 18 | 19 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 20 | 21 | exponential: wgt = exp(-vdist/bw); 22 | 23 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 24 | 25 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 26 | 27 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 28 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 29 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 30 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 31 | \item{longlat}{if TRUE, great circle distances will be calculated} 32 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 33 | } 34 | \value{ 35 | Returns the adaptive or fixed distance bandwidth 36 | } 37 | \note{ 38 | For a discontinuous kernel function, a bandwidth can be specified either as a fixed (constant) distance or 39 | as a fixed (constant) number of local data (i.e. an adaptive distance). For a continuous kernel function, 40 | a bandwidth can be specified either as a fixed distance or as a 'fixed quantity that reflects local sample size' 41 | (i.e. still an 'adaptive' distance but the actual local sample size will be the sample size as functions are continuous). 42 | In practise a fixed bandwidth suits fairly regular sample configurations whilst an adaptive bandwidth suits highly irregular 43 | sample configurations. Adaptive bandwidths ensure sufficient (and constant) local information for each local calibration. 44 | This note is applicable to all GW models 45 | } 46 | \references{ 47 | Harris P, Clarke A, Juggins S, Brunsdon C, Charlton M (2015) 48 | Enhancements to a geographically weighted principal components analysis in the context of an application to an environmental data set. 49 | Geographical Analysis 47: 146-172 50 | } 51 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 52 | \keyword{GWPCA} 53 | \concept{bandwidth selection} 54 | 55 | -------------------------------------------------------------------------------- /GWmodel/man/bw.gwss.average.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.gwss.average} 2 | \alias{bw.gwss.average} 3 | \alias{gw.mean.cv} 4 | \alias{gw.median.cv} 5 | \alias{gw.average.cv} 6 | \alias{gw.average.cv.contrib} 7 | \title{Bandwidth selection for GW summary averages} 8 | \description{ 9 | A function for automatic bandwidth selections to calculate GW summary averages, including means and medians, via a cross-validation approach. 10 | } 11 | \usage{ 12 | bw.gwss.average(data, summary.locat, vars, kernel = "bisquare", adaptive = FALSE, 13 | p = 2, theta = 0, longlat = F, dMat) 14 | } 15 | \arguments{ 16 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 17 | \item{summary.locat}{a Spatial*DataFrame object for providing summary locations, 18 | i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame 19 | as defined in package \pkg{sp}} 20 | \item{vars}{a vector of variable names to be summarized} 21 | \item{kernel}{function chosen as follows: 22 | 23 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 24 | 25 | exponential: wgt = exp(-vdist/bw); 26 | 27 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 28 | 29 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 30 | 31 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 32 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 33 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 34 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 35 | \item{longlat}{if TRUE, great circle distances will be calculated} 36 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 37 | } 38 | \value{ 39 | Returns the adaptive or fixed distance bandwidths (in a two-column matrix) for calculating the averages of each variable. 40 | } 41 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 42 | 43 | \keyword{GWSS} 44 | \concept{bandwidth selection} 45 | 46 | -------------------------------------------------------------------------------- /GWmodel/man/ggwr.cv.Rd: -------------------------------------------------------------------------------- 1 | \name{ggwr.cv} 2 | \alias{ggwr.cv} 3 | \title{Cross-validation score for a specified bandwidth for generalised GWR} 4 | \description{ 5 | This function finds the cross-validation score for a specified bandwidth for generalised GWR. 6 | It can be used to construct the bandwidth function across all possible bandwidths and compared to that found automatically. 7 | } 8 | \usage{ 9 | ggwr.cv(bw, X, Y,family="poisson", kernel="bisquare",adaptive=F, dp.locat, 10 | p=2, theta=0, longlat=F,dMat) 11 | } 12 | 13 | \arguments{ 14 | \item{bw}{bandwidth used in the weighting function;fixed (distance) or adaptive bandwidth(number of nearest neighbours)} 15 | \item{X}{a numeric matrix of the independent data with an extra column of \dQuote{ones} for the 1st column} 16 | \item{Y}{a column vector of the dependent data} 17 | \item{family}{a description of the error distribution and link function to 18 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 31 | \item{dp.locat}{a two-column numeric array of observation coordinates} 32 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 33 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 34 | \item{longlat}{if TRUE, great circle distances will be calculated} 35 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 36 | } 37 | \value{ 38 | \item{CV.score}{cross-validation score} 39 | } 40 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 41 | \keyword{generalised GWR} 42 | \concept{Cross-validation score} 43 | 44 | -------------------------------------------------------------------------------- /GWmodel/man/ggwr.cv.contrib.Rd: -------------------------------------------------------------------------------- 1 | \name{ggwr.cv.contrib} 2 | \alias{ggwr.cv.contrib} 3 | \title{Cross-validation data at each observation location for a generalised GWR model} 4 | \description{ 5 | This function finds the individual cross-validation score at each observation location, for a generalised GWR model, for a specified bandwidth. 6 | These data can be mapped to detect unusually high or low cross-validations scores. 7 | } 8 | \usage{ 9 | ggwr.cv.contrib(bw, X, Y,family="poisson", kernel="bisquare",adaptive=F, 10 | dp.locat, p=2, theta=0, longlat=F,dMat) 11 | } 12 | 13 | \arguments{ 14 | \item{bw}{bandwidth used in the weighting function;fixed (distance) or adaptive bandwidth(number of nearest neighbours)} 15 | \item{X}{a numeric matrix of the independent data with an extra column of \dQuote{ones} for the 1st column} 16 | \item{Y}{a column vector of the dependent data} 17 | \item{family}{a description of the error distribution and link function to 18 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 31 | \item{dp.locat}{a two-column numeric array of observation coordinates} 32 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 33 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 34 | \item{longlat}{if TRUE, great circle distances will be calculated} 35 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 36 | } 37 | \value{ 38 | \item{CV}{a data vector consisting of squared residuals, whose sum is the cross-validation score for the specified bandwidth} 39 | } 40 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 41 | \keyword{generalised GWR} 42 | \concept{point-wise cross-validation score} -------------------------------------------------------------------------------- /GWmodel/man/gw.dist.Rd: -------------------------------------------------------------------------------- 1 | \name{gw.dist} 2 | \alias{gw.dist} 3 | \alias{gw_dist} 4 | \title{Distance matrix calculation} 5 | \description{ 6 | Calculate a distance vector(matrix) between any GW model calibration point(s) and the data points. 7 | } 8 | \usage{ 9 | gw.dist(dp.locat, rp.locat, focus=0, p=2, theta=0, longlat=F) 10 | } 11 | %- maybe also 'usage' for other objects documented here. 12 | \arguments{ 13 | \item{dp.locat}{a numeric matrix of two columns giving the coordinates of the data points} 14 | \item{rp.locat}{a numeric matrix of two columns giving the coordinates of the GW model calibration points} 15 | \item{focus}{an integer, indexing to the current GW model point, if focus=0, all the distances between all the GW model calibration points and data points will be calculated and a distance matrix will be returned; if 0 3 | 4 | #include "IGWmodelCUDA.h" 5 | 6 | using namespace arma; 7 | 8 | class CGWmodelCUDA : public IGWmodelCUDA 9 | { 10 | private: 11 | mat x; 12 | vec y; 13 | mat dp; 14 | mat rp; 15 | mat dMat; 16 | bool rp_given; 17 | bool dm_given; 18 | mat betas; 19 | mat betasSE; 20 | vec s_hat; 21 | vec qdiag; 22 | public: 23 | CGWmodelCUDA(); 24 | CGWmodelCUDA(int N, int K, bool rp_given, int n, bool dm_given); 25 | ~CGWmodelCUDA(); 26 | 27 | virtual void SetX(int i, int k, double value); 28 | virtual void SetY(int i, double value); 29 | virtual void SetDp(int i, double u, double v); 30 | virtual void SetRp(int i, double u, double v); 31 | virtual void SetDmat(int i, int j, double value); 32 | 33 | virtual double GetBetas(int i, int k); 34 | virtual double GetBetasSE(int i, int k); 35 | virtual double GetShat1(); 36 | virtual double GetShat2(); 37 | virtual double GetQdiag(int i); 38 | 39 | 40 | virtual bool Regression( 41 | bool hatmatrix, 42 | double p, double theta, bool longlat, 43 | double bw, int kernel, bool adaptive, 44 | int groupl, int gpuID 45 | ); 46 | 47 | virtual double CV( 48 | double p, double theta, bool longlat, 49 | double bw, int kernel, bool adaptive, 50 | int groupl, int gpuID 51 | ); 52 | 53 | }; 54 | -------------------------------------------------------------------------------- /GWmodel/src/GWmodelCUDA/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | project(GWmodelCUDA LANGUAGES CXX CUDA) 3 | 4 | if(WIN32 AND NOT MSVC) 5 | message(FATAL_ERROR "CUDA only support MSVC complier on Windows!") 6 | endif(WIN32 AND NOT MSVC) 7 | 8 | find_package(Armadillo REQUIRED) 9 | include_directories(${ARMADILLO_INCLUDE_DIRS}) 10 | 11 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 12 | find_package(cuBLAS REQUIRED) 13 | include_directories(${CUBLAS_INCLUDE_DIRS}) 14 | 15 | add_definitions(-DCREATDLL_EXPORTS) 16 | 17 | set(SOURCES_CXX 18 | CGWmodelCUDA.cpp 19 | IGWmodelCUDA.cpp 20 | ) 21 | 22 | set(SOURCES_CUDA 23 | GWmodelKernel.cu 24 | ) 25 | 26 | set(HEADERS 27 | CGWmodelCUDA.h 28 | GWmodelKernel.h 29 | helper.h 30 | IGWmodelCUDA.h 31 | ) 32 | 33 | 34 | add_library(GWmodelCUDA64 SHARED ${SOURCES_CUDA} ${SOURCES_CXX} ${HEADERS}) 35 | set_property(TARGET GWmodelCUDA64 PROPERTY CUDA_ARCHITECTURES 35 37 52 60 61 70 75) 36 | target_link_libraries(GWmodelCUDA64 PRIVATE 37 | ${CUDA_LIBRARIES} 38 | ${CUBLAS_LIBRARIES} 39 | ${ARMADILLO_LIBRARIES} 40 | ) 41 | target_compile_features(GWmodelCUDA64 PUBLIC cxx_std_11) 42 | add_custom_command(TARGET GWmodelCUDA64 POST_BUILD 43 | COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/.." 44 | ) 45 | add_custom_command(TARGET GWmodelCUDA64 POST_BUILD 46 | COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/.." 47 | ) 48 | add_custom_command(TARGET GWmodelCUDA64 POST_BUILD 49 | COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}" 50 | ) -------------------------------------------------------------------------------- /GWmodel/src/GWmodelCUDA/GWmodelKernel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | cudaError_t gw_coordinate_rotate_cuda(double* d_coords, int n, double theta, int threads); 5 | cudaError_t gw_dist_cuda(double *d_dp, double *d_rp, int ndp, int nrp, int focus, double p, double theta, bool longlat, bool rp_given, double *d_dists, int threads); 6 | cudaError_t gw_weight_cuda(double bw, int kernel, bool adaptive, double *d_dists, double *d_weight, int ndp, int nrp, int threads); 7 | cudaError_t gw_xtw_cuda(const double* d_x, const double* d_weight, int n, int k, double* d_xtw, int threads); 8 | cudaError_t gw_xdy_cuda(const double* d_x, const double* d_y, int n, double * d_xdoty, int threads); 9 | cudaError_t gw_xdx_cuda(const double* d_x, int n, double * d_xdotx, int threads); 10 | cudaError_t gw_qdiag_cuda(const double* d_si, int n, int p, double* d_q, int threads); 11 | -------------------------------------------------------------------------------- /GWmodel/src/GWmodelCUDA/IGWmodelCUDA.cpp: -------------------------------------------------------------------------------- 1 | #include "IGWmodelCUDA.h" 2 | #include "CGWmodelCUDA.h" 3 | 4 | 5 | IGWmodelCUDA * GWCUDA_Create(int N, int K, bool rp_given, int n, bool dm_given) 6 | { 7 | return new CGWmodelCUDA(N, K, rp_given, n, dm_given); 8 | } 9 | 10 | void GWCUDA_Del(IGWmodelCUDA * pInstance) 11 | { 12 | delete pInstance; 13 | } 14 | 15 | bool gwr_reg_cuda(IGWmodelCUDA * pInstance, bool hatmatrix, double p, double theta, bool longlat, double bw, int kernel, bool adaptive, int groupl, int gpuID) 16 | { 17 | return pInstance->Regression(hatmatrix, p, theta, longlat, bw, kernel, adaptive, groupl, gpuID); 18 | } 19 | -------------------------------------------------------------------------------- /GWmodel/src/GWmodelCUDA/IGWmodelCUDA.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef WIN32 4 | #ifdef CREATDLL_EXPORTS 5 | #define GWMODELCUDA_API __declspec(dllexport) 6 | #else 7 | #define GWMODELCUDA_API __declspec(dllimport) 8 | #endif // CREATDLL_EXPORTS 9 | #else 10 | #define GWMODELCUDA_API 11 | #endif 12 | 13 | class GWMODELCUDA_API IGWmodelCUDA 14 | { 15 | public: 16 | virtual void SetX(int i, int k, double value) = 0; 17 | virtual void SetY(int i, double value) = 0; 18 | virtual void SetDp(int i, double u, double v) = 0; 19 | virtual void SetRp(int i, double u, double v) = 0; 20 | virtual void SetDmat(int i, int j, double value) = 0; 21 | 22 | virtual double GetBetas(int i, int k) = 0; 23 | virtual double GetBetasSE(int i, int k) = 0; 24 | virtual double GetShat1() = 0; 25 | virtual double GetShat2() = 0; 26 | virtual double GetQdiag(int i) = 0; 27 | 28 | 29 | virtual bool Regression( 30 | bool hatmatrix, 31 | double p, double theta, bool longlat, 32 | double bw, int kernel, bool adaptive, 33 | int groupl, int gpuID 34 | ) = 0; 35 | 36 | virtual double CV( 37 | double p, double theta, bool longlat, 38 | double bw, int kernel, bool adaptive, 39 | int groupl, int gpuID 40 | ) = 0; 41 | }; 42 | 43 | extern "C" GWMODELCUDA_API IGWmodelCUDA* GWCUDA_Create(int N, int K, bool rp_given, int n, bool dm_given); 44 | extern "C" GWMODELCUDA_API void GWCUDA_Del(IGWmodelCUDA* pInstance); 45 | -------------------------------------------------------------------------------- /GWmodel/src/GWmodelCUDA/cmake/FindcuBLAS.cmake: -------------------------------------------------------------------------------- 1 | # ================================================================================================== 2 | # This file is part of the cuBLASt project. The project is licensed under Apache Version 2.0. This 3 | # project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- 4 | # width of 100 characters per line. 5 | # 6 | # Author(s): 7 | # Cedric Nugteren 8 | # 9 | # ================================================================================================== 10 | # 11 | # Defines the following variables: 12 | # CUBLAS_FOUND Boolean holding whether or not the cuBLAS library was found 13 | # CUBLAS_INCLUDE_DIRS The CUDA and cuBLAS include directory 14 | # CUDA_LIBRARIES The CUDA library 15 | # CUBLAS_LIBRARIES The cuBLAS library 16 | # 17 | # In case CUDA is not installed in the default directory, set the CUDA_ROOT variable to point to 18 | # the root of cuBLAS, such that 'cublas_v2.h' can be found in $CUDA_ROOT/include. This can either be 19 | # done using an environmental variable (e.g. export CUDA_ROOT=/path/to/cuBLAS) or using a CMake 20 | # variable (e.g. cmake -DCUDA_ROOT=/path/to/cuBLAS ..). 21 | # 22 | # ================================================================================================== 23 | 24 | # Sets the possible install locations 25 | set(CUBLAS_HINTS 26 | ${CUDA_PATH} 27 | $ENV{CUDA_PATH} 28 | $ENV{CUDA_TOOLKIT_ROOT_DIR} 29 | ) 30 | set(CUBLAS_PATHS 31 | /usr 32 | /usr/local 33 | /usr/local/cuda 34 | ) 35 | 36 | # Finds the include directories 37 | find_path(CUBLAS_INCLUDE_DIRS 38 | NAMES cublas_v2.h cuda.h 39 | HINTS ${CUBLAS_HINTS} 40 | PATH_SUFFIXES include inc include/x86_64 include/x64 41 | PATHS ${CUBLAS_PATHS} 42 | DOC "cuBLAS include header cublas_v2.h" 43 | ) 44 | mark_as_advanced(CUBLAS_INCLUDE_DIRS) 45 | 46 | # Finds the libraries 47 | find_library(CUDA_LIBRARIES 48 | NAMES cudart 49 | HINTS ${CUBLAS_HINTS} 50 | PATH_SUFFIXES lib lib64 lib/x86_64 lib/x64 lib/x86 lib/Win32 lib/import lib64/import 51 | PATHS ${CUBLAS_PATHS} 52 | DOC "CUDA library" 53 | ) 54 | mark_as_advanced(CUDA_LIBRARIES) 55 | find_library(CUBLAS_LIBRARIES 56 | NAMES cublas 57 | HINTS ${CUBLAS_HINTS} 58 | PATH_SUFFIXES lib lib64 lib/x86_64 lib/x64 lib/x86 lib/Win32 lib/import lib64/import 59 | PATHS ${CUBLAS_PATHS} 60 | DOC "cuBLAS library" 61 | ) 62 | mark_as_advanced(CUBLAS_LIBRARIES) 63 | 64 | # ================================================================================================== 65 | 66 | # Notification messages 67 | if(NOT CUBLAS_INCLUDE_DIRS) 68 | message(STATUS "Could NOT find 'cuBLAS.h', install CUDA/cuBLAS or set CUDA_ROOT") 69 | endif() 70 | if(NOT CUDA_LIBRARIES) 71 | message(STATUS "Could NOT find CUDA library, install it or set CUDA_ROOT") 72 | endif() 73 | if(NOT CUBLAS_LIBRARIES) 74 | message(STATUS "Could NOT find cuBLAS library, install it or set CUDA_ROOT") 75 | endif() 76 | 77 | # Determines whether or not cuBLAS was found 78 | include(FindPackageHandleStandardArgs) 79 | find_package_handle_standard_args(cuBLAS DEFAULT_MSG CUBLAS_INCLUDE_DIRS CUDA_LIBRARIES CUBLAS_LIBRARIES) 80 | 81 | # ================================================================================================== -------------------------------------------------------------------------------- /GWmodel/src/GWmodelCUDA/helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | static const char *_cudaGetErrorEnum(cudaError_t error) { 7 | return cudaGetErrorName(error); 8 | } 9 | 10 | static const char *_cudaGetErrorEnum(cublasStatus_t error) { 11 | switch (error) { 12 | case CUBLAS_STATUS_SUCCESS: 13 | return "CUBLAS_STATUS_SUCCESS"; 14 | 15 | case CUBLAS_STATUS_NOT_INITIALIZED: 16 | return "CUBLAS_STATUS_NOT_INITIALIZED"; 17 | 18 | case CUBLAS_STATUS_ALLOC_FAILED: 19 | return "CUBLAS_STATUS_ALLOC_FAILED"; 20 | 21 | case CUBLAS_STATUS_INVALID_VALUE: 22 | return "CUBLAS_STATUS_INVALID_VALUE"; 23 | 24 | case CUBLAS_STATUS_ARCH_MISMATCH: 25 | return "CUBLAS_STATUS_ARCH_MISMATCH"; 26 | 27 | case CUBLAS_STATUS_MAPPING_ERROR: 28 | return "CUBLAS_STATUS_MAPPING_ERROR"; 29 | 30 | case CUBLAS_STATUS_EXECUTION_FAILED: 31 | return "CUBLAS_STATUS_EXECUTION_FAILED"; 32 | 33 | case CUBLAS_STATUS_INTERNAL_ERROR: 34 | return "CUBLAS_STATUS_INTERNAL_ERROR"; 35 | 36 | case CUBLAS_STATUS_NOT_SUPPORTED: 37 | return "CUBLAS_STATUS_NOT_SUPPORTED"; 38 | 39 | case CUBLAS_STATUS_LICENSE_ERROR: 40 | return "CUBLAS_STATUS_LICENSE_ERROR"; 41 | } 42 | 43 | return ""; 44 | } 45 | 46 | #define DEVICE_RESET cudaDeviceReset(); 47 | 48 | template 49 | bool check(T result, char const *const func, const char *const file, 50 | int const line) { 51 | if (result) { 52 | fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line, 53 | static_cast(result), _cudaGetErrorEnum(result), func); 54 | DEVICE_RESET 55 | // Make sure we call CUDA Device Reset before exiting 56 | return true; 57 | } 58 | else return false; 59 | } 60 | 61 | #ifndef WIN32 62 | #ifdef _DEBUG 63 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 64 | #else 65 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 66 | #endif // _DEBUG 67 | 68 | #ifdef _DEBUG 69 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 70 | #else 71 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 72 | #endif // _DEBUG 73 | #else 74 | #ifdef _DEBUG 75 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 76 | #else 77 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 78 | #endif // _DEBUG 79 | 80 | #ifdef _DEBUG 81 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 82 | #else 83 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 84 | #endif // _DEBUG 85 | #endif 86 | -------------------------------------------------------------------------------- /GWmodel/src/Makevars.in: -------------------------------------------------------------------------------- 1 | CDEFS = @CDEFS@ 2 | R_INC = -I./GWmodelCUDA 3 | PKG_CXXFLAGS = -DARMA_64BIT_WORD=1 $(SHLIB_OPENMP_CXXFLAGS) $(CDEFS) $(R_INC) 4 | CUDA_LIBS = @CUDA_LIBS@ 5 | PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) @PKG_LIBS@ 6 | ENABLE_CUDA = @ENABLE_CUDA@ 7 | GWmodel_CUDA_LIB_PATH=@GWmodel_CUDA_LIB_PATH@ 8 | 9 | cu_sources = @cu_sources@ 10 | cu_sharedlibs =@cu_sharedlibs@ 11 | cpp_sources_cuda = @cpp_sources_cuda@ 12 | cpp_sharedlibs_cuda = @cpp_sharedlibs_cuda@ 13 | OBJECTS_CUDA = @OBJECTS_CUDA@ 14 | 15 | #CDEFS = @CDEFS@ 16 | TARGET_CUDA_LIB =@TARGET_CUDA_LIB@ 17 | 18 | cpp_sources = RcppExports.cpp GWmodel.cpp 19 | cpp_sharedlibs= RcppExports.o GWmodel.o 20 | 21 | c_sources = init.c 22 | c_sharedlibs = init.o 23 | 24 | OBJECTS = ${cpp_sharedlibs} ${c_sharedlibs} 25 | 26 | #R_INC = -I./GWmodelCUDA 27 | CXX_ARGS = @R_CPIC@ $(SHLIB_OPENMP_CXXFLAGS) -DNDEBUG ${CXX11FLAGS} 28 | 29 | CU_ARGS = -std=c++14 -Xcompiler -fPIC -Xcudafe --diag_suppress=boolean_controlling_expr_is_constant -DNDEBUG 30 | CU_INCL = ${R_INCL} 31 | CU_ARCH = \ 32 | -gencode arch=compute_35,code=sm_35 \ 33 | -gencode arch=compute_37,code=sm_37 \ 34 | -gencode arch=compute_52,code=sm_52 \ 35 | -gencode arch=compute_60,code=sm_60 \ 36 | -gencode arch=compute_61,code=sm_61 \ 37 | -gencode arch=compute_70,code=sm_70 \ 38 | -gencode arch=compute_75,code=sm_75 39 | 40 | NVCC=@NVCC@ 41 | CUDA_INCL = @CUDA_INCL@ 42 | 43 | vpath %.cu ./GWmodelCUDA 44 | vpath %.cpp ./GWmodelCUDA 45 | 46 | .PHONY: all clean 47 | 48 | all : ${TARGET_CUDA_LIB} GWmodel.so 49 | 50 | ${TARGET_CUDA_LIB}: ${OBJECTS_CUDA} 51 | ${SHLIB_LINK} -o $@ $^ ${CUDA_LIBS} 52 | mkdir -p ${GWmodel_CUDA_LIB_PATH} 53 | cp $@ ${GWmodel_CUDA_LIB_PATH} 54 | chown -R ${USER}:${USER} ${HOME}/.cache/GWmodel 55 | 56 | 57 | GWmodel.so : ${TARGET_CUDA_LIB} ${OBJECTS_CUDA} ${OBJECTS} 58 | 59 | ${cpp_sharedlibs_cuda}: %.o: %.cpp 60 | $(CXX) $(SHLIB_OPENMP_CXXFLAGS) -DNDEBUG ${CXX11FLAGS} -DCUDA_ARCH=52 $(R_INC) -I${CUDA_INCL} -fPIC $< -c 61 | 62 | ${cu_sharedlibs}: %.o: %.cu 63 | $(NVCC) $(CU_ARCH) $(CU_ARGS) $(CU_INCL) -I${CUDA_INCL} $< -c 64 | 65 | ${cpp_sharedlibs}: %.o :%.cpp 66 | 67 | clean: 68 | rm -rf *.o Makevars 69 | 70 | -------------------------------------------------------------------------------- /GWmodel/src/Makevars.win: -------------------------------------------------------------------------------- 1 | PKG_CXXFLAGS = -DARMA_64BIT_WORD=1 $(SHLIB_OPENMP_CXXFLAGS) 2 | PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) 3 | 4 | ifdef CUDA_PATH 5 | ifeq "$(WIN)" "64" 6 | PKG_CXXFLAGS += -DCUDA_ACCE -I"./GWmodelCUDA" 7 | PKG_LIBS += -L"./GWmodelCUDA" -lGWmodelCUDA64 8 | CUDA_LIB = GWmodelCUDA64.dll GWmodelCUDA64.lib 9 | endif 10 | endif 11 | 12 | 13 | 14 | vpath %.lib ./GWmodelCUDA 15 | 16 | .PHONY: all 17 | 18 | all: GWmodel.dll 19 | 20 | GWmodel.dll: ${CUDA_LIB} 21 | 22 | ${CUDA_LIB}: 23 | sh -c 'powershell.exe -Command -' < download.ps1 24 | unzip -d tmp -o GWmodelCUDA.zip 25 | mv tmp/*.dll . 26 | mv tmp/*.lib GWmodelCUDA 27 | -------------------------------------------------------------------------------- /GWmodel/src/download.ps1: -------------------------------------------------------------------------------- 1 | $client = new-object System.Net.WebClient 2 | $client.DownloadFile('https://haokunt-download-data.oss-cn-hangzhou.aliyuncs.com/GWmodelCUDA.zip', 'GWmodelCUDA.zip') 3 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(GWmodel) 2 | import(Rcpp) 3 | import(maptools) 4 | import(robustbase) 5 | import(sp) 6 | import(stats) 7 | import(spacetime) 8 | import(spatialreg) 9 | import(parallel) 10 | importFrom(FNN, get.knn) 11 | importFrom("grDevices", "grey", "rainbow", "rgb") 12 | importFrom("methods", "as", "is", "slot") 13 | importFrom("graphics", "abline", "axis", "hist", "identify", "legend", 14 | "lines", "points", "rect", "text") 15 | importFrom("spdep", "knearneigh", "poly2nb", "nb2listw","listw2mat","knn2nb") 16 | export(gwr.scalable,gwr.scalable.loocv,AICc1, gwr_diag1,scgwr_loocv,scgwr_pre,scgwr_reg,bw.gtwr, gtwr.aic, gtwr, ti.distv, ti.distm,ti.dist,get.before.ti, get.ts, sdist.mat,tdist.mat, get.uloat,st.dist, gwr.bootstrap,generate.lm.data,parametric.bs,parametric.bs.local,se.bs,bias.bs,ci.bs,pval.bs,gwrtvar,gwrt.mlr,gwrt.lag,gwrt.err,gwrt.sma,bw.gwr3,gwr.multiscale,gwr.backfit,gwr.q2, confusion.matrix,gwss.montecarlo,gwda,print.gwda,grouping.xy,wqda,wlda,splitx,wmean,wvarcov,wprior,bw.gwda,wqda.cr,wlda.cr,gwr.hetero,gwr.mixed,gwr.mixed.2,gwr.mixed.trace.fast, gwr.mixed.trace, gwr.mixed.trace.fast,print.mgwr,gwr.q,gwr.collin.diagno,plot.mcsims,bw.gwr, gwr.cv,gwr.cv.contrib, gwr.aic, gold, gw.dist, gw.weight.box, gw.weight.gau, gw.weight.bis, gw.weight.tri, gw.weight.gau.ad, gw.weight.bis.ad, gw.weight.tri.ad, gw.weight.box.ad, gw.weight, gwr.basic, F1234.test,extract.mat,Generate.formula,gwr.generalised,gwr.poisson,gwr.binomial,gwss,bw.ggwr,ggwr.basic,ggwr.cv,ggwr.cv.contrib,ggwr.aic,gwr.poisson.wt,gwr.binomial.wt,wpca,robustSvd,wt.median,rwpca,gwpca,bw.gwpca,gwpca.cv,gwpca.cv.contrib,gwr.lcr,ridge.lm,bw.gwr.lcr,gwr.lcr.cv,gwr.lcr.cv.contrib,gwr.t.adjust,gwr.predict,gw.reg1,gwr.robust,gw.pcplot,bw.gwr1,gwr.aic1,gwr.cv1,plot.pvlas,coordinate_rotate,eu_dist_mat,eu_dist_smat,eu_dist_vec,mk_dist_mat,mk_dist_smat,mk_dist_vec,cd_dist_mat,cd_dist_smat,cd_dist_vec,md_dist_mat,md_dist_smat,md_dist_vec,bisq_wt_vec,bisq_wt_mat,gauss_wt_vec,gauss_wt_mat,tri_wt_vec,tri_wt_mat,exp_wt_vec,exp_wt_mat,gw_reg,gw.fitted,ehat,rss,gwr_diag,AICc,AICc_rss,Ci_mat,gwss.montecarlo,gwpca.montecarlo.1,gwpca.montecarlo.2,gwr.model.selection,gwr.model.view,gwr.model.sort,gwr.montecarlo,gwr.write,gwr.write.shp,gwpca.glyph.plot,gwpca.check.components,gwr.mink.approach,gwr.mink.matrixview,gwr.mink.pval,gwr.mink.pval.forward,gwr.mink.pval.backward,gw.mean.cv,gw.median.cv,gw.average.cv,gw.average.cv.contrib,bw.gwss.average,montecarlo.gwss,montecarlo.gwpca.1,montecarlo.gwpca.2,model.selection.gwr,model.view.gwr,model.sort.gwr,montecarlo.gwr,writeGWR,writeGWR.shp,glyph.plot,check.components,mink.approach,mink.matrixview,gwr_q,gwr_mixed_trace, gwr_mixed_2) 17 | useDynLib(GWmodel, .registration = TRUE) 18 | 19 | S3method(print, mcsims) 20 | S3method(print, gwrm) 21 | S3method(print, ggwrm) 22 | S3method(print, gwss) 23 | S3method(print, gwrlcr) 24 | S3method(print, gwrm.pred) 25 | S3method(plot, mcsims) 26 | S3method(plot, pvlas) 27 | S3method(print, gwda) 28 | S3method(print, mgwr) 29 | S3method(print, gwrbsm) 30 | S3method(print, multiscalegwr) 31 | S3method(print, gtwrm) 32 | S3method(print, gwpca) 33 | S3method(print, scgwrm) -------------------------------------------------------------------------------- /R/gw.average.cv.contrib.R: -------------------------------------------------------------------------------- 1 | gw.average.cv.contrib<- function(bw, X, kernel, adaptive, dp.locat, p, theta, longlat, dMat) 2 | { 3 | findmedian <- function(x, w) { 4 | lw <- length(w) 5 | xo <- sort(x) 6 | wo <- w[order(x)] 7 | 8 | cond <- max({ cumsum(wo) <= 0.5} * seq(1:lw)) 9 | if (cond == 0) 10 | cond <- 1 11 | xo[cond] 12 | } 13 | 14 | dp.n <- length(dp.locat[, 1]) 15 | if (is.null(dMat)) 16 | DM.given <- F 17 | else { 18 | DM.given <- T 19 | dim.dMat <- dim(dMat) 20 | if (dim.dMat[1] != dp.n || dim.dMat[2] != dp.n) 21 | stop("Dimensions of dMat are not correct") 22 | } 23 | CV.mean <- numeric(dp.n) 24 | CV.median <- numeric(dp.n) 25 | for (i in 1:dp.n) { 26 | if (DM.given) 27 | dist.vi <- dMat[, i] 28 | else { 29 | dist.vi <- gw.dist(dp.locat = dp.locat, focus = i, 30 | p = p, theta = theta, longlat = longlat) 31 | } 32 | W.i <- matrix(gw.weight(dist.vi, bw, kernel, adaptive),nrow=1) 33 | sum.w <- sum(W.i) 34 | Wi <- W.i/sum.w 35 | l.mean<-Wi%*%X 36 | l.median<- findmedian(X, w = c(Wi)) 37 | Wi <- Wi[-i] 38 | Wi<-Wi/sum(Wi) 39 | l.mean.resi <- try(sum(Wi*X[-i])) 40 | l.median.resi<- try(findmedian(X[-i], w = Wi)) 41 | 42 | if (!inherits(l.mean.resi, "try-error")) { 43 | CV.mean[i] <- l.mean - l.mean.resi 44 | } 45 | else { 46 | CV.mean[i] <- Inf 47 | break 48 | } 49 | 50 | if (!inherits(l.median.resi, "try-error")) { 51 | CV.median[i] <- l.median - l.median.resi 52 | } 53 | else { 54 | CV.median[i] <- Inf 55 | break 56 | } 57 | } 58 | CV<-cbind(CV.mean,CV.median) 59 | colnames(CV)<-c('Local Mean','Local Median') 60 | CV 61 | } -------------------------------------------------------------------------------- /R/gwr.robust.r: -------------------------------------------------------------------------------- 1 | gwr.robust<-function(formula, data, bw,filtered=FALSE, kernel = "bisquare", adaptive = FALSE, p = 2, theta = 0, longlat = F, dMat, F123.test = F,maxiter=20,cut.filter= 3,cut1=2,cut2=3,delta=1.0e-5) 2 | { 3 | W.vect<-NULL 4 | res1<- gwr.basic(formula=formula, data=data, bw=bw, kernel=kernel, adaptive=adaptive, p=p, theta=theta, longlat=longlat, dMat=dMat, F123.test=F123.test, cv=T,W.vect=W.vect) 5 | if(filtered==TRUE){ 6 | W.vect<-as.numeric(abs(res1$SDF$Stud_residual) cut1 17 | xg3 <- x > cut2 18 | span <- cut2 - cut1 19 | result[xg2] <- (1 - ((x[xg2]-cut1)/span)^2)^2 20 | result[xg3] <- rep(0,sum(xg3)) 21 | result 22 | } 23 | 24 | iter<-0 25 | diffmse<-1 26 | err<-res1$SDF$residual 27 | mse<- sum(err*err)/length(err) 28 | W.vect <- filt(abs(err/sqrt(mse))) 29 | W.vect[is.na(W.vect)]<-0 30 | 31 | while(diffmse>delta & iter=2)\cr 25 | LazyLoad: \tab yes\cr 26 | } 27 | 28 | } 29 | \author{ 30 | Binbin Lu, Paul Harris, Martin Charlton, Chris Brunsdon, Tomoki Nakaya, Daisuke Murakami,Isabella Gollini 31 | 32 | Maintainer: Binbin Lu 33 | } 34 | \note{ 35 | Acknowledgements: We gratefully acknowledge support from National Natural Science Foundation of China (42071368); Science Foundation Ireland 36 | under the National Development Plan through the award of a Strategic Research Centre 37 | grant 07-SRC-I1168. 38 | 39 | Beta versions can always be found at \url{https://github.com/lbb220/GWmodel}, 40 | which includes all the newly developed functions for GW models. 41 | 42 | For latest tutorials on using GWmodel please go to: \url{https://rpubs.com/gwmodel} 43 | } 44 | 45 | \references{ 46 | Gollini I, Lu B, Charlton M, Brunsdon C, Harris P (2015) GWmodel: an R Package 47 | for exploring Spatial Heterogeneity using Geographically Weighted Models. Journal 48 | of Statistical Software, 63(17):1-50, \url{http://www.jstatsoft.org/v63/i17/} 49 | 50 | Lu B, Harris P, Charlton M, Brunsdon C (2014) The GWmodel R Package: further 51 | topics for exploring Spatial Heterogeneity using Geographically Weighted Models. 52 | Geo-spatial Information Science 17(2): 85-101, 53 | \url{http://www.tandfonline.com/doi/abs/10.1080/10095020.2014.917453} 54 | } 55 | \keyword{package} 56 | -------------------------------------------------------------------------------- /man/Georgia.Rd: -------------------------------------------------------------------------------- 1 | \name{Georgia} 2 | \alias{Georgia} 3 | \alias{Gedu.df} 4 | \docType{data} 5 | \title{Georgia census data set (csv file)} 6 | \description{ 7 | Census data from the county of Georgia, USA 8 | } 9 | \usage{data(Georgia)} 10 | \format{ 11 | A data frame with 159 observations on the following 13 variables. 12 | \describe{ 13 | \item{AreaKey}{An identification number for each county} 14 | \item{Latitude}{The latitude of the county centroid} 15 | \item{Longitud}{The longitude of the county centroid} 16 | \item{TotPop90}{Population of the county in 1990} 17 | \item{PctRural}{Percentage of the county population defined as rural} 18 | \item{PctBach}{Percentage of the county population with a bachelors degree} 19 | \item{PctEld}{Percentage of the county population aged 65 or over} 20 | \item{PctFB}{Percentage of the county population born outside the US} 21 | \item{PctPov}{Percentage of the county population living below the poverty line} 22 | \item{PctBlack}{Percentage of the county population who are black} 23 | \item{ID}{a numeric vector of IDs} 24 | \item{X}{a numeric vector of x coordinates} 25 | \item{Y}{a numeric vector of y coordinates} 26 | } 27 | } 28 | \details{ 29 | This data set can also be found in GWR 3 and in spgwr. 30 | } 31 | \references{ 32 | Fotheringham S, Brunsdon, C, and Charlton, M (2002), 33 | Geographically Weighted Regression: The Analysis of Spatially Varying Relationships, Chichester: Wiley. 34 | } 35 | \examples{ 36 | data(Georgia) 37 | ls() 38 | coords <- cbind(Gedu.df$X, Gedu.df$Y) 39 | educ.spdf <- SpatialPointsDataFrame(coords, Gedu.df) 40 | spplot(educ.spdf, names(educ.spdf)[4:10]) 41 | } 42 | \keyword{data} 43 | \concept{Georgia census} 44 | -------------------------------------------------------------------------------- /man/GeorgiaCounties.rd: -------------------------------------------------------------------------------- 1 | \name{GeorgiaCounties} 2 | \alias{Gedu.counties} 3 | \docType{data} 4 | \title{Georgia counties data (SpatialPolygonsDataFrame)} 5 | \description{ 6 | The Georgia census data with boundaries for mapping 7 | } 8 | \usage{data(GeorgiaCounties)} 9 | \details{ 10 | This data set can also be found in GWR 3 and in spgwr. 11 | } 12 | \examples{ 13 | data(GeorgiaCounties) 14 | plot(Gedu.counties) 15 | data(Georgia) 16 | coords <- cbind(Gedu.df$X, Gedu.df$Y) 17 | educ.spdf <- SpatialPointsDataFrame(coords, Gedu.df) 18 | plot(educ.spdf, add=TRUE) 19 | 20 | } 21 | \keyword{data} 22 | \concept{Georgia counties} 23 | -------------------------------------------------------------------------------- /man/LondonBorough.rd: -------------------------------------------------------------------------------- 1 | \name{LondonBorough} 2 | \alias{LondonBorough} 3 | \alias{londonborough} 4 | \docType{data} 5 | \title{London boroughs data} 6 | \description{ 7 | Outline (SpatialPolygonsDataFrame) of London boroughs for the \link{LondonHP} data. 8 | } 9 | \usage{data(LondonBorough)} 10 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 11 | \keyword{data} 12 | \concept{London Boroughs} 13 | -------------------------------------------------------------------------------- /man/LondonHP.Rd: -------------------------------------------------------------------------------- 1 | \name{LondonHP} 2 | \alias{LondonHP} 3 | \alias{londonhp} 4 | \docType{data} 5 | \title{London house price data set (SpatialPointsDataFrame)} 6 | \description{ 7 | A house price data set with 18 hedonic variables for London in 2001. 8 | } 9 | \usage{data(LondonHP)} 10 | \format{ 11 | A SpatialPointsDataFrame object (proj4string set to "+init=epsg:27700 +datum=OSGB36"). 12 | 13 | The "data" slot is a data frame with 372 observations on the following 21 variables. 14 | \describe{ 15 | \item{X}{a numeric vector, X coordinate} 16 | \item{Y}{a numeric vector, Y coordinate} 17 | \item{PURCHASE}{a numeric vector, the purchase price of the property} 18 | \item{FLOORSZ}{a numeric vector, floor area of the property in square metres} 19 | \item{TYPEDETCH}{a numeric vector, 1 if the property is detached (i.e. it is a stand-alone house), 0 otherwise} 20 | \item{TPSEMIDTCH}{a numeric vector, 1 if the property is semi detached, 0 otherwise} 21 | \item{TYPETRRD}{a numeric vector, 1 if the property is in a terrace of similar houses (commonly referred to as a 'row house' in the USA), 0 otherwise} 22 | \item{TYPEBNGLW}{a numeric vector, if the property is a bungalow (i.e. it has only one floor), 0 otherwise} 23 | \item{TYPEFLAT}{a numeric vector, if the property is a flat (or 'apartment' in the USA), 0 otherwise} 24 | \item{BLDPWW1}{a numeric vector, 1 if the property was built prior to 1914, 0 otherwise} 25 | \item{BLDPOSTW}{a numeric vector, 1 if the property was built between 1940 and 1959, 0 otherwise} 26 | \item{BLD60S}{a numeric vector, 1 if the property was built between 1960 and 1969, 0 otherwise} 27 | \item{BLD70S}{a numeric vector, 1 if the property was built between 1970 and 1979, 0 otherwise} 28 | \item{BLD80S}{a numeric vector, 1 if the property was built between 1980 and 1989, 0 otherwise} 29 | \item{BLD90S}{a numeric vector, 1 if the property was built between 1990 and 2000, 0 otherwise} 30 | \item{BATH2}{a numeric vector, 1 if the property has more than 2 bathrooms, 0 otherwise} 31 | \item{GARAGE}{a numeric vector,1 if the house has a garage, 0 otherwise} 32 | \item{CENTHEAT}{a numeric vector, 1 if the house has central heating, 0 otherwise} 33 | \item{BEDS2}{a numeric vector, 1 if the property has more than 2 bedrooms, 0 otherwise} 34 | \item{UNEMPLOY}{a numeric vector, the rate of unemployment in the census ward in which the house is located} 35 | \item{PROF}{a numeric vector, the proportion of the workforce in professional or managerial occupations in the census ward in which the house is located} 36 | } 37 | } 38 | \references{ 39 | Fotheringham, A.S., Brunsdon, C., and Charlton, M.E. (2002), Geographically Weighted Regression: 40 | The Analysis of Spatially Varying Relationships, Chichester: Wiley. 41 | 42 | Lu, B, Charlton, M, Harris, P, Fotheringham, AS (2014) Geographically weighted regression 43 | with a non-Euclidean distance metric: a case study using hedonic house price data. 44 | International Journal of Geographical Information Science 28(4): 660-681 45 | } 46 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 47 | \examples{ 48 | data(LondonHP) 49 | data(LondonBorough) 50 | ls() 51 | plot(londonborough) 52 | plot(londonhp, add=TRUE) 53 | } 54 | \keyword{data} 55 | \concept{house price} 56 | -------------------------------------------------------------------------------- /man/USelect.rd: -------------------------------------------------------------------------------- 1 | \name{USelect} 2 | \alias{USelect2004} 3 | \docType{data} 4 | \title{Results of the 2004 US presidential election at the county level (SpatialPolygonsDataFrame)} 5 | \description{ 6 | Results of the 2004 US presidential election at the county level, together with five socio-economic (census) variables. 7 | This data can be used with GW Discriminant Analysis. 8 | } 9 | \usage{data(USelect)} 10 | \format{ 11 | A SpatialPolygonsDataFrame with 3111 electoral divisions on the following 6 variables. 12 | \describe{ 13 | \item{winner}{Categorical variable with three classes: i) Bush, ii) Kerry and iii) Borderline (supporting ratio for a candidate ranges from 0.45 to 0.55)} 14 | \item{unemploy}{percentage unemployed} 15 | \item{pctcoled}{percentage of adults over 25 with 4 or more years of college education} 16 | \item{PEROVER65}{percentage of persons over the age of 65} 17 | \item{pcturban}{percentage urban} 18 | \item{WHITE}{percentage white} 19 | } 20 | } 21 | \references{ 22 | Robinson, A. C. (2013). Geovisualization of the 2004 Presidential Election. 23 | In: NATIONAL INSTITUTES OF HEALTH, P. S. U. (ed.). Penn State: 24 | \url{http://www.personal.psu.edu/users/a/c/acr181/election.html}. 25 | 26 | Foley, P. & Demsar, U. (2012). Using geovisual analytics to compare the 27 | performance of geographically weighted discriminant analysis versus its global 28 | counterpart, linear discriminant analysis. International Journal of Geographical 29 | Information Science, 27, 633-661. 30 | } 31 | \examples{ 32 | 33 | data(USelect) 34 | ls() 35 | } 36 | \keyword{data} 37 | \concept{US presidential election} 38 | -------------------------------------------------------------------------------- /man/bw.ggwr.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.ggwr} 2 | \alias{bw.ggwr} 3 | \alias{ggwr.aic} 4 | \title{Bandwidth selection for generalised geographically weighted regression (GWR)} 5 | \description{ 6 | A function for automatic bandwidth selection to calibrate a generalised GWR model 7 | } 8 | \usage{ 9 | bw.ggwr(formula, data, family ="poisson", approach="CV", 10 | kernel="bisquare",adaptive=FALSE, p=2, theta=0, longlat=F,dMat) 11 | } 12 | \arguments{ 13 | \item{formula}{Regression model formula of a \link{formula} object } 14 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 15 | \item{family}{a description of the error distribution and link function to 16 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 17 | \item{approach}{specified by CV for cross-validation approach or by AIC corrected (AICc) approach} 18 | \item{kernel}{function chosen as follows: 19 | 20 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 21 | 22 | exponential: wgt = exp(-vdist/bw); 23 | 24 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 25 | 26 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 27 | 28 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 29 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 30 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 31 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 32 | \item{longlat}{if TRUE, great circle distances will be calculated} 33 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 34 | } 35 | \note{ 36 | For a discontinuous kernel function, a bandwidth can be specified either as a fixed (constant) distance or 37 | as a fixed (constant) number of local data (i.e. an adaptive distance). For a continuous kernel function, 38 | a bandwidth can be specified either as a fixed distance or as a 'fixed quantity that reflects local sample size' 39 | (i.e. still an 'adaptive' distance but the actual local sample size will be the sample size as functions are continuous). 40 | In practise a fixed bandwidth suits fairly regular sample configurations whilst an adaptive bandwidth suits highly irregular 41 | sample configurations. Adaptive bandwidths ensure sufficient (and constant) local information for each local calibration. 42 | This note is applicable to all GW models 43 | } 44 | \value{ 45 | Returns the adaptive or fixed distance bandwidth 46 | } 47 | 48 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 49 | 50 | \keyword{generalised GWR} 51 | \concept{bandwidth selection} 52 | 53 | -------------------------------------------------------------------------------- /man/bw.gtwr.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.gtwr} 2 | \alias{bw.gtwr} 3 | \alias{gtwr.cv} 4 | \alias{gtwr.aic} 5 | \title{Bandwidth selection for GTWR} 6 | \description{ 7 | A function for automatic bandwidth selection to calibrate a GTWR model 8 | } 9 | \usage{ 10 | bw.gtwr(formula, data, obs.tv, approach="CV",kernel="bisquare",adaptive=FALSE, 11 | p=2, theta=0, longlat=F,lamda=0.05,t.units = "auto",ksi=0, st.dMat, 12 | verbose=T) 13 | } 14 | \arguments{ 15 | \item{formula}{Regression model formula of a \link{formula} object } 16 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 17 | \item{obs.tv}{a vector of time tags for each observation, which could be numeric or of \link{POSIXlt} class} 18 | \item{approach}{specified by CV for cross-validation approach or by AIC corrected (AICc) approach} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) 31 | corresponds to the number of nearest neighbours (i.e. adaptive distance); default 32 | is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 33 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 34 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 35 | \item{longlat}{if TRUE, great circle distances will be calculated} 36 | \item{lamda}{an parameter between 0 and 1 for calculating spatio-temporal distance} 37 | \item{t.units}{ character string to define time unit} 38 | \item{ksi}{an parameter between 0 and PI for calculating spatio-temporal distance, 39 | see details in Wu et al. (2014)} 40 | \item{st.dMat}{a pre-specified spatio-temporal distance matrix} 41 | \item{verbose}{logical variable to define whether show the selection procedure} 42 | } 43 | \note{ 44 | The function is developed according to the articles by Huang et al. (2010) and 45 | Wu et al. (2014). 46 | } 47 | 48 | \value{ 49 | Returns the adaptive or fixed distance bandwidth 50 | } 51 | \references{ 52 | Huang, B., Wu, B., & Barry, M. (2010). Geographically and temporally weighted 53 | regression for modeling spatio-temporal variation in house prices. International 54 | Journal of Geographical Information Science, 24, 383-401. 55 | 56 | Wu, B., Li, R., & Huang, B. (2014). A geographically and temporally weighted 57 | autoregressive model with application to housing prices. International Journal 58 | of Geographical Information Science, 28, 1186-1204. 59 | 60 | Fotheringham, A. S., Crespo, R., & Yao, J. (2015). Geographical and Temporal 61 | Weighted Regression (GTWR). Geographical Analysis, 47, 431-452. 62 | 63 | } 64 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 65 | 66 | \keyword{GTWR} 67 | \concept{bandwidth selection} 68 | -------------------------------------------------------------------------------- /man/bw.gwpca.rd: -------------------------------------------------------------------------------- 1 | \name{bw.gwpca} 2 | \alias{bw.gwpca} 3 | \title{Bandwidth selection for Geographically Weighted Principal Components Analysis (GWPCA)} 4 | \description{ 5 | A function for automatic bandwidth selection to calibrate a basic or robust GWPCA via a cross-validation approach only 6 | } 7 | \usage{ 8 | bw.gwpca(data,vars,k=2, robust=FALSE,kernel="bisquare",adaptive=FALSE,p=2, 9 | theta=0, longlat=F,dMat) 10 | } 11 | 12 | \arguments{ 13 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 14 | \item{vars}{a vector of variable names to be evaluated} 15 | \item{k}{the number of retained components, and it must be less than the number of variables} 16 | \item{robust}{if TRUE, robust GWPCA will be applied; otherwise basic GWPCA will be applied} 17 | \item{kernel}{function chosen as follows: 18 | 19 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 20 | 21 | exponential: wgt = exp(-vdist/bw); 22 | 23 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 24 | 25 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 26 | 27 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 28 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 29 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 30 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 31 | \item{longlat}{if TRUE, great circle distances will be calculated} 32 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 33 | } 34 | \value{ 35 | Returns the adaptive or fixed distance bandwidth 36 | } 37 | \note{ 38 | For a discontinuous kernel function, a bandwidth can be specified either as a fixed (constant) distance or 39 | as a fixed (constant) number of local data (i.e. an adaptive distance). For a continuous kernel function, 40 | a bandwidth can be specified either as a fixed distance or as a 'fixed quantity that reflects local sample size' 41 | (i.e. still an 'adaptive' distance but the actual local sample size will be the sample size as functions are continuous). 42 | In practise a fixed bandwidth suits fairly regular sample configurations whilst an adaptive bandwidth suits highly irregular 43 | sample configurations. Adaptive bandwidths ensure sufficient (and constant) local information for each local calibration. 44 | This note is applicable to all GW models 45 | } 46 | \references{ 47 | Harris P, Clarke A, Juggins S, Brunsdon C, Charlton M (2015) 48 | Enhancements to a geographically weighted principal components analysis in the context of an application to an environmental data set. 49 | Geographical Analysis 47: 146-172 50 | } 51 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 52 | \keyword{GWPCA} 53 | \concept{bandwidth selection} 54 | 55 | -------------------------------------------------------------------------------- /man/bw.gwss.average.Rd: -------------------------------------------------------------------------------- 1 | \name{bw.gwss.average} 2 | \alias{bw.gwss.average} 3 | \alias{gw.mean.cv} 4 | \alias{gw.median.cv} 5 | \alias{gw.average.cv} 6 | \alias{gw.average.cv.contrib} 7 | \title{Bandwidth selection for GW summary averages} 8 | \description{ 9 | A function for automatic bandwidth selections to calculate GW summary averages, including means and medians, via a cross-validation approach. 10 | } 11 | \usage{ 12 | bw.gwss.average(data, summary.locat, vars, kernel = "bisquare", adaptive = FALSE, 13 | p = 2, theta = 0, longlat = F, dMat) 14 | } 15 | \arguments{ 16 | \item{data}{a Spatial*DataFrame, i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame as defined in package \pkg{sp}} 17 | \item{summary.locat}{a Spatial*DataFrame object for providing summary locations, 18 | i.e. SpatialPointsDataFrame or SpatialPolygonsDataFrame 19 | as defined in package \pkg{sp}} 20 | \item{vars}{a vector of variable names to be summarized} 21 | \item{kernel}{function chosen as follows: 22 | 23 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 24 | 25 | exponential: wgt = exp(-vdist/bw); 26 | 27 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 28 | 29 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 30 | 31 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 32 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 33 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 34 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 35 | \item{longlat}{if TRUE, great circle distances will be calculated} 36 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 37 | } 38 | \value{ 39 | Returns the adaptive or fixed distance bandwidths (in a two-column matrix) for calculating the averages of each variable. 40 | } 41 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 42 | 43 | \keyword{GWSS} 44 | \concept{bandwidth selection} 45 | 46 | -------------------------------------------------------------------------------- /man/ggwr.cv.Rd: -------------------------------------------------------------------------------- 1 | \name{ggwr.cv} 2 | \alias{ggwr.cv} 3 | \title{Cross-validation score for a specified bandwidth for generalised GWR} 4 | \description{ 5 | This function finds the cross-validation score for a specified bandwidth for generalised GWR. 6 | It can be used to construct the bandwidth function across all possible bandwidths and compared to that found automatically. 7 | } 8 | \usage{ 9 | ggwr.cv(bw, X, Y,family="poisson", kernel="bisquare",adaptive=F, dp.locat, 10 | p=2, theta=0, longlat=F,dMat) 11 | } 12 | 13 | \arguments{ 14 | \item{bw}{bandwidth used in the weighting function;fixed (distance) or adaptive bandwidth(number of nearest neighbours)} 15 | \item{X}{a numeric matrix of the independent data with an extra column of \dQuote{ones} for the 1st column} 16 | \item{Y}{a column vector of the dependent data} 17 | \item{family}{a description of the error distribution and link function to 18 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 31 | \item{dp.locat}{a two-column numeric array of observation coordinates} 32 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 33 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 34 | \item{longlat}{if TRUE, great circle distances will be calculated} 35 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 36 | } 37 | \value{ 38 | \item{CV.score}{cross-validation score} 39 | } 40 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 41 | \keyword{generalised GWR} 42 | \concept{Cross-validation score} 43 | 44 | -------------------------------------------------------------------------------- /man/ggwr.cv.contrib.Rd: -------------------------------------------------------------------------------- 1 | \name{ggwr.cv.contrib} 2 | \alias{ggwr.cv.contrib} 3 | \title{Cross-validation data at each observation location for a generalised GWR model} 4 | \description{ 5 | This function finds the individual cross-validation score at each observation location, for a generalised GWR model, for a specified bandwidth. 6 | These data can be mapped to detect unusually high or low cross-validations scores. 7 | } 8 | \usage{ 9 | ggwr.cv.contrib(bw, X, Y,family="poisson", kernel="bisquare",adaptive=F, 10 | dp.locat, p=2, theta=0, longlat=F,dMat) 11 | } 12 | 13 | \arguments{ 14 | \item{bw}{bandwidth used in the weighting function;fixed (distance) or adaptive bandwidth(number of nearest neighbours)} 15 | \item{X}{a numeric matrix of the independent data with an extra column of \dQuote{ones} for the 1st column} 16 | \item{Y}{a column vector of the dependent data} 17 | \item{family}{a description of the error distribution and link function to 18 | be used in the model, which can be specified by \dQuote{poisson} or \dQuote{binomial}} 19 | \item{kernel}{function chosen as follows: 20 | 21 | gaussian: wgt = exp(-.5*(vdist/bw)^2); 22 | 23 | exponential: wgt = exp(-vdist/bw); 24 | 25 | bisquare: wgt = (1-(vdist/bw)^2)^2 if vdist < bw, wgt=0 otherwise; 26 | 27 | tricube: wgt = (1-(vdist/bw)^3)^3 if vdist < bw, wgt=0 otherwise; 28 | 29 | boxcar: wgt=1 if dist < bw, wgt=0 otherwise} 30 | \item{adaptive}{if TRUE calculate an adaptive kernel where the bandwidth (bw) corresponds to the number of nearest neighbours (i.e. adaptive distance); default is FALSE, where a fixed kernel is found (bandwidth is a fixed distance)} 31 | \item{dp.locat}{a two-column numeric array of observation coordinates} 32 | \item{p}{the power of the Minkowski distance, default is 2, i.e. the Euclidean distance} 33 | \item{theta}{an angle in radians to rotate the coordinate system, default is 0} 34 | \item{longlat}{if TRUE, great circle distances will be calculated} 35 | \item{dMat}{a pre-specified distance matrix, it can be calculated by the function \code{\link{gw.dist}}} 36 | } 37 | \value{ 38 | \item{CV}{a data vector consisting of squared residuals, whose sum is the cross-validation score for the specified bandwidth} 39 | } 40 | \author{Binbin Lu \email{binbinlu@whu.edu.cn}} 41 | \keyword{generalised GWR} 42 | \concept{point-wise cross-validation score} -------------------------------------------------------------------------------- /man/gw.dist.Rd: -------------------------------------------------------------------------------- 1 | \name{gw.dist} 2 | \alias{gw.dist} 3 | \alias{coordinate_rotate} 4 | \alias{eu_dist_mat} 5 | \alias{eu_dist_smat} 6 | \alias{eu_dist_vec} 7 | \alias{mk_dist_mat} 8 | \alias{mk_dist_smat} 9 | \alias{mk_dist_vec} 10 | \alias{cd_dist_mat} 11 | \alias{cd_dist_smat} 12 | \alias{cd_dist_vec} 13 | \alias{md_dist_mat} 14 | \alias{md_dist_smat} 15 | \alias{md_dist_vec} 16 | \title{Distance matrix calculation} 17 | \description{ 18 | Calculate a distance vector(matrix) between any GW model calibration point(s) and the data points. 19 | } 20 | \usage{ 21 | gw.dist(dp.locat, rp.locat, focus=0, p=2, theta=0, longlat=F) 22 | } 23 | %- maybe also 'usage' for other objects documented here. 24 | \arguments{ 25 | \item{dp.locat}{a numeric matrix of two columns giving the coordinates of the data points} 26 | \item{rp.locat}{a numeric matrix of two columns giving the coordinates of the GW model calibration points} 27 | \item{focus}{an integer, indexing to the current GW model point, if focus=0, all the distances between all the GW model calibration points and data points will be calculated and a distance matrix will be returned; if 0 3 | 4 | #include "IGWmodelCUDA.h" 5 | 6 | using namespace arma; 7 | 8 | class CGWmodelCUDA : public IGWmodelCUDA 9 | { 10 | private: 11 | mat x; 12 | vec y; 13 | mat dp; 14 | mat rp; 15 | mat dMat; 16 | bool rp_given; 17 | bool dm_given; 18 | mat betas; 19 | mat betasSE; 20 | vec s_hat; 21 | vec qdiag; 22 | public: 23 | CGWmodelCUDA(); 24 | CGWmodelCUDA(int N, int K, bool rp_given, int n, bool dm_given); 25 | ~CGWmodelCUDA(); 26 | 27 | virtual void SetX(int i, int k, double value); 28 | virtual void SetY(int i, double value); 29 | virtual void SetDp(int i, double u, double v); 30 | virtual void SetRp(int i, double u, double v); 31 | virtual void SetDmat(int i, int j, double value); 32 | 33 | virtual double GetBetas(int i, int k); 34 | virtual double GetBetasSE(int i, int k); 35 | virtual double GetShat1(); 36 | virtual double GetShat2(); 37 | virtual double GetQdiag(int i); 38 | 39 | 40 | virtual bool Regression( 41 | bool hatmatrix, 42 | double p, double theta, bool longlat, 43 | double bw, int kernel, bool adaptive, 44 | int groupl, int gpuID 45 | ); 46 | 47 | virtual double CV( 48 | double p, double theta, bool longlat, 49 | double bw, int kernel, bool adaptive, 50 | int groupl, int gpuID 51 | ); 52 | 53 | }; -------------------------------------------------------------------------------- /src/GWmodelCUDA/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.9) 2 | project(GWmodelCUDA LANGUAGES CXX CUDA) 3 | 4 | if(WIN32 AND NOT MSVC) 5 | message(FATAL_ERROR "CUDA only support MSVC complier on Windows!") 6 | endif(WIN32 AND NOT MSVC) 7 | 8 | find_package(Armadillo REQUIRED) 9 | include_directories(${ARMADILLO_INCLUDE_DIRS}) 10 | 11 | set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) 12 | find_package(cuBLAS REQUIRED) 13 | include_directories(${CUBLAS_INCLUDE_DIRS}) 14 | 15 | add_definitions(-DCREATDLL_EXPORTS) 16 | 17 | set(SOURCES_CXX 18 | CGWmodelCUDA.cpp 19 | IGWmodelCUDA.cpp 20 | ) 21 | 22 | set(SOURCES_CUDA 23 | GWmodelKernel.cu 24 | ) 25 | 26 | set(HEADERS 27 | CGWmodelCUDA.h 28 | GWmodelKernel.h 29 | helper.h 30 | IGWmodelCUDA.h 31 | ) 32 | 33 | 34 | add_library(GWmodelCUDA64 SHARED ${SOURCES_CUDA} ${SOURCES_CXX} ${HEADERS}) 35 | set_property(TARGET GWmodelCUDA64 PROPERTY CUDA_ARCHITECTURES 35 37 52 60 61 70 75) 36 | target_link_libraries(GWmodelCUDA64 PRIVATE 37 | ${CUDA_LIBRARIES} 38 | ${CUBLAS_LIBRARIES} 39 | ${ARMADILLO_LIBRARIES} 40 | ) 41 | target_compile_features(GWmodelCUDA64 PUBLIC cxx_std_11) 42 | add_custom_command(TARGET GWmodelCUDA64 POST_BUILD 43 | COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/.." 44 | ) 45 | add_custom_command(TARGET GWmodelCUDA64 POST_BUILD 46 | COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}/.." 47 | ) 48 | add_custom_command(TARGET GWmodelCUDA64 POST_BUILD 49 | COMMAND ${CMAKE_COMMAND} -E copy $ "${CMAKE_CURRENT_SOURCE_DIR}" 50 | ) -------------------------------------------------------------------------------- /src/GWmodelCUDA/GWmodelKernel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | cudaError_t gw_coordinate_rotate_cuda(double* d_coords, int n, double theta, int threads); 5 | cudaError_t gw_dist_cuda(double *d_dp, double *d_rp, int ndp, int nrp, int focus, double p, double theta, bool longlat, bool rp_given, double *d_dists, int threads); 6 | cudaError_t gw_weight_cuda(double bw, int kernel, bool adaptive, double *d_dists, double *d_weight, int ndp, int nrp, int threads); 7 | cudaError_t gw_xtw_cuda(const double* d_x, const double* d_weight, int n, int k, double* d_xtw, int threads); 8 | cudaError_t gw_xdy_cuda(const double* d_x, const double* d_y, int n, double * d_xdoty, int threads); 9 | cudaError_t gw_xdx_cuda(const double* d_x, int n, double * d_xdotx, int threads); 10 | cudaError_t gw_qdiag_cuda(const double* d_si, int n, int p, double* d_q, int threads); 11 | -------------------------------------------------------------------------------- /src/GWmodelCUDA/IGWmodelCUDA.cpp: -------------------------------------------------------------------------------- 1 | #include "IGWmodelCUDA.h" 2 | #include "CGWmodelCUDA.h" 3 | 4 | 5 | IGWmodelCUDA * GWCUDA_Create(int N, int K, bool rp_given, int n, bool dm_given) 6 | { 7 | return new CGWmodelCUDA(N, K, rp_given, n, dm_given); 8 | } 9 | 10 | void GWCUDA_Del(IGWmodelCUDA * pInstance) 11 | { 12 | delete pInstance; 13 | } 14 | 15 | bool gwr_reg_cuda(IGWmodelCUDA * pInstance, bool hatmatrix, double p, double theta, bool longlat, double bw, int kernel, bool adaptive, int groupl, int gpuID) 16 | { 17 | return pInstance->Regression(hatmatrix, p, theta, longlat, bw, kernel, adaptive, groupl, gpuID); 18 | } 19 | -------------------------------------------------------------------------------- /src/GWmodelCUDA/IGWmodelCUDA.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef WIN32 4 | #ifdef CREATDLL_EXPORTS 5 | #define GWMODELCUDA_API __declspec(dllexport) 6 | #else 7 | #define GWMODELCUDA_API __declspec(dllimport) 8 | #endif // CREATDLL_EXPORTS 9 | #else 10 | #define GWMODELCUDA_API 11 | #endif 12 | 13 | class GWMODELCUDA_API IGWmodelCUDA 14 | { 15 | public: 16 | virtual void SetX(int i, int k, double value) = 0; 17 | virtual void SetY(int i, double value) = 0; 18 | virtual void SetDp(int i, double u, double v) = 0; 19 | virtual void SetRp(int i, double u, double v) = 0; 20 | virtual void SetDmat(int i, int j, double value) = 0; 21 | 22 | virtual double GetBetas(int i, int k) = 0; 23 | virtual double GetBetasSE(int i, int k) = 0; 24 | virtual double GetShat1() = 0; 25 | virtual double GetShat2() = 0; 26 | virtual double GetQdiag(int i) = 0; 27 | 28 | 29 | virtual bool Regression( 30 | bool hatmatrix, 31 | double p, double theta, bool longlat, 32 | double bw, int kernel, bool adaptive, 33 | int groupl, int gpuID 34 | ) = 0; 35 | 36 | virtual double CV( 37 | double p, double theta, bool longlat, 38 | double bw, int kernel, bool adaptive, 39 | int groupl, int gpuID 40 | ) = 0; 41 | }; 42 | 43 | extern "C" GWMODELCUDA_API IGWmodelCUDA* GWCUDA_Create(int N, int K, bool rp_given, int n, bool dm_given); 44 | extern "C" GWMODELCUDA_API void GWCUDA_Del(IGWmodelCUDA* pInstance); -------------------------------------------------------------------------------- /src/GWmodelCUDA/cmake/FindcuBLAS.cmake: -------------------------------------------------------------------------------- 1 | # ================================================================================================== 2 | # This file is part of the cuBLASt project. The project is licensed under Apache Version 2.0. This 3 | # project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- 4 | # width of 100 characters per line. 5 | # 6 | # Author(s): 7 | # Cedric Nugteren 8 | # 9 | # ================================================================================================== 10 | # 11 | # Defines the following variables: 12 | # CUBLAS_FOUND Boolean holding whether or not the cuBLAS library was found 13 | # CUBLAS_INCLUDE_DIRS The CUDA and cuBLAS include directory 14 | # CUDA_LIBRARIES The CUDA library 15 | # CUBLAS_LIBRARIES The cuBLAS library 16 | # 17 | # In case CUDA is not installed in the default directory, set the CUDA_ROOT variable to point to 18 | # the root of cuBLAS, such that 'cublas_v2.h' can be found in $CUDA_ROOT/include. This can either be 19 | # done using an environmental variable (e.g. export CUDA_ROOT=/path/to/cuBLAS) or using a CMake 20 | # variable (e.g. cmake -DCUDA_ROOT=/path/to/cuBLAS ..). 21 | # 22 | # ================================================================================================== 23 | 24 | # Sets the possible install locations 25 | set(CUBLAS_HINTS 26 | ${CUDA_PATH} 27 | $ENV{CUDA_PATH} 28 | $ENV{CUDA_TOOLKIT_ROOT_DIR} 29 | ) 30 | set(CUBLAS_PATHS 31 | /usr 32 | /usr/local 33 | /usr/local/cuda 34 | ) 35 | 36 | # Finds the include directories 37 | find_path(CUBLAS_INCLUDE_DIRS 38 | NAMES cublas_v2.h cuda.h 39 | HINTS ${CUBLAS_HINTS} 40 | PATH_SUFFIXES include inc include/x86_64 include/x64 41 | PATHS ${CUBLAS_PATHS} 42 | DOC "cuBLAS include header cublas_v2.h" 43 | ) 44 | mark_as_advanced(CUBLAS_INCLUDE_DIRS) 45 | 46 | # Finds the libraries 47 | find_library(CUDA_LIBRARIES 48 | NAMES cudart 49 | HINTS ${CUBLAS_HINTS} 50 | PATH_SUFFIXES lib lib64 lib/x86_64 lib/x64 lib/x86 lib/Win32 lib/import lib64/import 51 | PATHS ${CUBLAS_PATHS} 52 | DOC "CUDA library" 53 | ) 54 | mark_as_advanced(CUDA_LIBRARIES) 55 | find_library(CUBLAS_LIBRARIES 56 | NAMES cublas 57 | HINTS ${CUBLAS_HINTS} 58 | PATH_SUFFIXES lib lib64 lib/x86_64 lib/x64 lib/x86 lib/Win32 lib/import lib64/import 59 | PATHS ${CUBLAS_PATHS} 60 | DOC "cuBLAS library" 61 | ) 62 | mark_as_advanced(CUBLAS_LIBRARIES) 63 | 64 | # ================================================================================================== 65 | 66 | # Notification messages 67 | if(NOT CUBLAS_INCLUDE_DIRS) 68 | message(STATUS "Could NOT find 'cuBLAS.h', install CUDA/cuBLAS or set CUDA_ROOT") 69 | endif() 70 | if(NOT CUDA_LIBRARIES) 71 | message(STATUS "Could NOT find CUDA library, install it or set CUDA_ROOT") 72 | endif() 73 | if(NOT CUBLAS_LIBRARIES) 74 | message(STATUS "Could NOT find cuBLAS library, install it or set CUDA_ROOT") 75 | endif() 76 | 77 | # Determines whether or not cuBLAS was found 78 | include(FindPackageHandleStandardArgs) 79 | find_package_handle_standard_args(cuBLAS DEFAULT_MSG CUBLAS_INCLUDE_DIRS CUDA_LIBRARIES CUBLAS_LIBRARIES) 80 | 81 | # ================================================================================================== -------------------------------------------------------------------------------- /src/GWmodelCUDA/helper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | static const char *_cudaGetErrorEnum(cudaError_t error) { 7 | return cudaGetErrorName(error); 8 | } 9 | 10 | static const char *_cudaGetErrorEnum(cublasStatus_t error) { 11 | switch (error) { 12 | case CUBLAS_STATUS_SUCCESS: 13 | return "CUBLAS_STATUS_SUCCESS"; 14 | 15 | case CUBLAS_STATUS_NOT_INITIALIZED: 16 | return "CUBLAS_STATUS_NOT_INITIALIZED"; 17 | 18 | case CUBLAS_STATUS_ALLOC_FAILED: 19 | return "CUBLAS_STATUS_ALLOC_FAILED"; 20 | 21 | case CUBLAS_STATUS_INVALID_VALUE: 22 | return "CUBLAS_STATUS_INVALID_VALUE"; 23 | 24 | case CUBLAS_STATUS_ARCH_MISMATCH: 25 | return "CUBLAS_STATUS_ARCH_MISMATCH"; 26 | 27 | case CUBLAS_STATUS_MAPPING_ERROR: 28 | return "CUBLAS_STATUS_MAPPING_ERROR"; 29 | 30 | case CUBLAS_STATUS_EXECUTION_FAILED: 31 | return "CUBLAS_STATUS_EXECUTION_FAILED"; 32 | 33 | case CUBLAS_STATUS_INTERNAL_ERROR: 34 | return "CUBLAS_STATUS_INTERNAL_ERROR"; 35 | 36 | case CUBLAS_STATUS_NOT_SUPPORTED: 37 | return "CUBLAS_STATUS_NOT_SUPPORTED"; 38 | 39 | case CUBLAS_STATUS_LICENSE_ERROR: 40 | return "CUBLAS_STATUS_LICENSE_ERROR"; 41 | } 42 | 43 | return ""; 44 | } 45 | 46 | #define DEVICE_RESET cudaDeviceReset(); 47 | 48 | template 49 | bool check(T result, char const *const func, const char *const file, 50 | int const line) { 51 | if (result) { 52 | fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", file, line, 53 | static_cast(result), _cudaGetErrorEnum(result), func); 54 | DEVICE_RESET 55 | // Make sure we call CUDA Device Reset before exiting 56 | return true; 57 | } 58 | else return false; 59 | } 60 | 61 | #ifndef WIN32 62 | #ifdef _DEBUG 63 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 64 | #else 65 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 66 | #endif // _DEBUG 67 | 68 | #ifdef _DEBUG 69 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 70 | #else 71 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(std::runtime_error(_cudaGetErrorEnum(val))) 72 | #endif // _DEBUG 73 | #else 74 | #ifdef _DEBUG 75 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 76 | #else 77 | #define checkRegCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 78 | #endif // _DEBUG 79 | 80 | #ifdef _DEBUG 81 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 82 | #else 83 | #define checkCvCudaErrors(val) if (check((val), #val, __FILE__, __LINE__)) throw std::exception(_cudaGetErrorEnum(val)) 84 | #endif // _DEBUG 85 | #endif -------------------------------------------------------------------------------- /src/Makevars.in: -------------------------------------------------------------------------------- 1 | PKG_CXXFLAGS = -ARMA_64BIT_WORD=1 $(SHLIB_OPENMP_CXXFLAGS) 2 | CUDA_LIBS = @CUDA_LIBS@ 3 | PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) @PKG_LIBS@ 4 | R_LIBS = @R_LIBS@ 5 | ENABLE_CUDA = @ENABLE_CUDA@ 6 | GWmodel_CUDA_LIB_PATH=@GWmodel_CUDA_LIB_PATH@ 7 | 8 | # R_PACKAGE_DIR=@R_PACKAGE_DIR@ 9 | # R_PACKAGE_DIR_REAL=@R_PACKAGE_DIR_REAL@ 10 | 11 | cu_sources = @cu_sources@ 12 | cu_sharedlibs =@cu_sharedlibs@ 13 | cpp_sources_cuda = @cpp_sources_cuda@ 14 | cpp_sharedlibs_cuda = @cpp_sharedlibs_cuda@ 15 | OBJECTS_CUDA = @OBJECTS_CUDA@ 16 | 17 | CDEFS = @CDEFS@ 18 | TARGET_CUDA_LIB =@TARGET_CUDA_LIB@ 19 | 20 | cpp_sources = RcppExports.cpp GWmodel.cpp 21 | cpp_sharedlibs= RcppExports.o GWmodel.o 22 | 23 | c_sources = init.c 24 | c_sharedlibs = init.o 25 | 26 | OBJECTS = ${cpp_sharedlibs} ${c_sharedlibs} 27 | 28 | R_INC = -I./GWmodelCUDA @R_INCL@ @RCPP_INCL@ @RCPP_ARMA_INCL@ @CU_INCL@ 29 | CXX_ARGS = @R_CPIC@ $(SHLIB_OPENMP_CXXFLAGS) -DNDEBUG ${CXX11FLAGS} 30 | 31 | CU_ARGS = -std=c++14 -Xcompiler -fPIC -Xcudafe --diag_suppress=boolean_controlling_expr_is_constant -DNDEBUG 32 | CU_INCL = @R_INCL@ @RCPP_INCL@ 33 | CU_ARCH = \ 34 | -gencode arch=compute_35,code=sm_35 \ 35 | -gencode arch=compute_37,code=sm_37 \ 36 | -gencode arch=compute_52,code=sm_52 \ 37 | -gencode arch=compute_60,code=sm_60 \ 38 | -gencode arch=compute_61,code=sm_61 \ 39 | -gencode arch=compute_70,code=sm_70 \ 40 | -gencode arch=compute_75,code=sm_75 41 | 42 | 43 | 44 | CXX=@CXX@ 45 | NVCC=@NVCC@ 46 | CUDA_INCL = @CUDA_INCL@ 47 | 48 | 49 | 50 | vpath %.cu ./GWmodelCUDA 51 | vpath %.cpp ./GWmodelCUDA 52 | 53 | .PHONY: all clean 54 | 55 | all : ${TARGET_CUDA_LIB} GWmodel.so 56 | 57 | ${TARGET_CUDA_LIB}: ${OBJECTS_CUDA} 58 | ${SHLIB_LINK} -o $@ $^ ${CUDA_LIBS} 59 | # cp $@ $(R_HOME)/lib$(R_ARCH) 60 | # cp -r $@ ${R_PACKAGE_DIR_REAL}/libs 61 | # cp -r $@ ${R_PACKAGE_DIR}/libs 62 | mkdir -p ${GWmodel_CUDA_LIB_PATH} 63 | cp $@ ${GWmodel_CUDA_LIB_PATH} 64 | chown -R ${USER}:${USER} ${HOME}/.cache/GWmodel 65 | 66 | 67 | GWmodel.so : ${TARGET_CUDA_LIB} ${OBJECTS_CUDA} ${OBJECTS} 68 | 69 | ${cpp_sharedlibs_cuda}: %.o: %.cpp 70 | $(CXX) $(CXX_ARGS) -DCUDA_ARCH=52 $(R_INC) -I${CUDA_INCL} $< -c 71 | 72 | ${cu_sharedlibs}: %.o: %.cu 73 | $(NVCC) $(CU_ARCH) $(CU_ARGS) $(CU_INCL) $< -c 74 | 75 | ${cpp_sharedlibs}: %.o :%.cpp 76 | ${CXX} $(CXX_ARGS) $(CDEFS) $(R_INC) $< -c 77 | 78 | clean: 79 | rm -rf *.o Makevars 80 | 81 | -------------------------------------------------------------------------------- /src/Makevars.win: -------------------------------------------------------------------------------- 1 | PKG_CXXFLAGS = -ARMA_64BIT_WORD=1 $(SHLIB_OPENMP_CXXFLAGS) 2 | PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) $(SHLIB_OPENMP_CXXFLAGS) 3 | 4 | ifdef CUDA_PATH 5 | ifeq "$(WIN)" "64" 6 | PKG_CXXFLAGS += -DCUDA_ACCE -I"./GWmodelCUDA" 7 | PKG_LIBS += -L"./GWmodelCUDA" -lGWmodelCUDA64 8 | CUDA_LIB = GWmodelCUDA64.dll GWmodelCUDA64.lib 9 | endif 10 | endif 11 | 12 | 13 | 14 | vpath %.lib ./GWmodelCUDA 15 | 16 | .PHONY: all 17 | 18 | all: GWmodel.dll 19 | 20 | GWmodel.dll: ${CUDA_LIB} 21 | 22 | ${CUDA_LIB}: 23 | sh -c 'powershell.exe -Command -' < download.ps1 24 | unzip -d tmp -o GWmodelCUDA.zip 25 | mv tmp/*.dll . 26 | mv tmp/*.lib GWmodelCUDA -------------------------------------------------------------------------------- /src/download.ps1: -------------------------------------------------------------------------------- 1 | $client = new-object System.Net.WebClient 2 | $client.DownloadFile('https://haokunt-download-data.oss-cn-hangzhou.aliyuncs.com/GWmodelCUDA.zip', 'GWmodelCUDA.zip') 3 | --------------------------------------------------------------------------------