用于使用“引导"引导进行引导的GPU计算.包裹 [英] GPU computing for bootstrapping using "boot" package

查看:61
本文介绍了用于使用“引导"引导进行引导的GPU计算.包裹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用引导进行大量分析.我看到使用并行计算提高了自举的速度,如以下代码所示:

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:

并行计算

# 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计算来提高速度(链接2 ).您可以通过以下功能轻松使用GPU计算:

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计算

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

但是在我看来,这些软件包只能处理某些特定的R函数,例如矩阵运算,线性代数或聚类分析( link3 ).另一种方法是使用CUDA/C/C ++/Fortran创建自己的函数(link4 ).但是我宁愿在R中寻找解决方案.

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.

因此,我的问题是:

是否可以使用 boot 软件包和其他R软件包(例如 quantreg )将GPU计算用于引导?

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

推荐答案

我认为,如果不立即进行任何其他编程,就不可能自由获得gpu计算的功能.但是gpuR软件包是一个很好的起点.正如您所指出的那样,gpuR仅能处理某些特定的R函数,例如矩阵运算和线性代数,它是受限制的,但很有用,例如,可以很容易地将线性回归公式化为线性代数问题.对于分位数回归,将其转换为线性代数并不像线性回归那样简单,但是可以做到.例如,您可以使用牛顿-拉夫森算法或其他数值优化算法来处理分位数回归(听起来并不难),牛顿算法是线性代数形式.

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.

gpuR软件包已经隐藏了许多c ++编程细节和硬件细节,以利用gpu计算能力,并且提供了一种非常易于使用的编程样式,只要我能想到,这就是实现此目标的方法您需要花费最少的精力:依靠gpuR程序包,在矩阵运算和线性代数(Newton Raphson等)中提出问题,然后自己进行编程,或者也许可以在R中找到一些Newton Raphson实现以实现分位数回归,并且进行一些必要的修改,例如,使用gpuMatrix代替matrix等,希望对您有所帮助.

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.

这篇关于用于使用“引导"引导进行引导的GPU计算.包裹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆