GPU computing for bootstrapping using “boot” package

寵の児 提交于 2021-02-18 17:11:32

问题


I would like to do a large analysis using bootstrapping. I saw that the speed of bootstrapping is increased using parallel computing as in the following code:

Parallel computing

# 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))

However, as the whole number of calculations is large in my case (10^6 regressions with 10,000 bootstrap samples), I read that there are ways to use GPU computing to increase the speed even more (link1, link2). You can easily use GPU computing with some functions like in:

GPU computing

m   <- matrix(rnorm(10^6), ncol = 1000)
csm <- gpuR::colSums(m)

But it seems to me that the packages can only handle some specific R functions such as matrix operations, linear algebra or cluster analysis (link3). Another approach is to use CUDA/C/C++/Fortran to create own functions (link4). But I am rather searching for a solution in R.

My question is therefore:

Is it possible to use GPU computing for bootstrapping using the boot package and other R packages (e.g. quantreg)?


回答1:


I think it is not possible to gain the power of gpu computing freely without doing any additional programming now. But the gpuR package is a good starting point. As you point out, the gpuR can only handle some specific R functions such as matrix operations and linear algebra, it is restricted but useful, for example, linear regression can be easily formulated to a linear algebra problem. As to quantile regression, it is not that straightforward to translate it to a linear algebra as linear regression, but it can be done. For example, you can use Newton-Raphson algorithm or something other numerical optimization algorithm to deal with quantile regression (it is not that hard as it sounds like), and the Newton algorithm is in linear algebra form.

The gpuR package is already hiding a lot of c++ programming details and hardware details to utilize gpu computing power and provides a quite easy-to-use programming style, as long as I can think of, this is the way to achieve what you want with the least effort: to rely on the gpuR package, formulate your problem in matrix operations and linear algebra (Newton Raphson etc) and do the programming yourself, or maybe you can find some Newton Raphson implementation in R for quantile regression, and make some little modifications necessary, for example, use gpuMatrix instead of matrix, etc. Hope it helps.



来源:https://stackoverflow.com/questions/43887664/gpu-computing-for-bootstrapping-using-boot-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!