我想使用引导程序进行大型分析。我发现使用并行计算提高了引导速度,如以下代码所示:
并行计算
# detect number of cpu
library(parallel)
detectCores()
library(boot)
# boot function --> mean
bt.mean <- function(dat, d){
x <- dat[d]
m <- mean(x)
return(m)
}
# obtain confidence intervals
# use parallel computing with 4 cpus
x <- mtcars$mpg
bt <- boot(x, bt.mean, R = 1000, parallel = "snow", ncpus = 4)
quantile(bt$t, probs = c(0.025, 0.975))
然而,由于我的情况下计算总量很大(10,000 个引导样本的 10^6 回归),我读到有一些方法可以使用 GPU 计算来进一步提高速度(link1 http://www.parallelr.com/blog/, link2 https://cran.r-project.org/web/views/HighPerformanceComputing.html)。您可以轻松地将 GPU 计算与某些功能结合使用,例如:
GPU计算
m <- matrix(rnorm(10^6), ncol = 1000)
csm <- gpuR::colSums(m)
但在我看来,这些包只能处理一些特定的 R 函数,例如矩阵运算、线性代数或聚类分析(link3 http://www.r-tutor.com/gpu-computing)。
另一种方法是使用 CUDA/C/C++/Fortran 创建自己的函数(link4 https://devblogs.nvidia.com/parallelforall/accelerate-r-applications-cuda/)。但我宁愿在 R 中寻找解决方案。
因此我的问题是:
是否可以使用 GPU 计算进行引导boot
包和其他 R 包(例如quantreg
)?