R:与Intel MKL一起使用“ foreach”:“ Lapack例程'dgesdd'中的错误代码9”

问题描述

我正在尝试加快为数千个线性模型运行置换所花费的时间。我相信Intel MKL BLAS已被证明可以提高回归计算的性能

更新:使用常规的for循环再次尝试下面的代码,一次迭代后出现错误

library(ggplot2)
library(dplyr)
library(tidyr)
set.seed(123)
#Data
n <- 500
#Random vars
z1 <- rnorm(n)
z2 <- rnorm(n)
z3 <- rnorm(n)
#Design Y1 and Y2
y1 <- 1+z1
y2 = 5 + 2*(z1) + z2
#For missing
y2_missing <- y2
#Set missing
index <- which(((2*(y1-1))+z3)<0)
y2_missing[index]<-NA
#Complete dataset
df <- data.frame(y1,y2,y2_missing)
#Plot distributions
df %>% select(-y1) %>%
  pivot_longer(everything()) %>%
  ggplot(aes(x=value,fill=name))+
  geom_density(alpha=0.5)+
  ggtitle('distribution for y2 and y2_missing')+
  labs(fill='Variable')+
  theme_bw()

据估计,有关Intel MKL如何计算SVD(相对于认R BLAS)的问题正在引起问题。

使用svd R包中的propack.svd()函数似乎可以解决问题。

解决方案的贷方到GitHub上的nerdcommander: https://github.com/thibautjombart/adegenet/issues/214


我遇到错误代码块:

Error in La.svd(x,nu,nv) : error code 9 from Lapack routine 'dgesdd'

我试图通过更改N的值(通常为1000)来隔离问题。

在N = 1到N = 4之间的某个时刻,出现以下错误之一:

j=1
datTemp=foreach(1:N,.combine=cbind) %dopar% { 

top10Expr=datExpr[rownames(datExpr) %in% top10pool[top10inds[,j],grep(datinfoSpec1$DatName[i],colnames(top10pool))],]

top10ME=svd(top10Expr,nu=1,nv=1)$v[,1]
if(cor(top10ME,as.numeric(top10Expr[1,]))<0){
 top10ME=-1*top10ME
}
fit=lapply(rownames(datExprTemp),function(x){lm(as.numeric(datExprTemp[rownames(datExprTemp) %in% x,])~top10ME)})
j=j+1
sapply(fit,function(y){sum(y$residuals^2)/ncol(datExpr)})
      } # // end N permutations 

或者:

Error in { : task 1 Failed - "missing value where TRUE/FALSE needed"

traceback()
3: stop(simpleError(msg,call = expr))
2: e$fun(obj,substitute(ex),parent.frame(),e$data)
1: foreach(1:N,.combine = cbind) %dopar% {
       top10Expr = datExpr[rownames(datExpr) %in% top10pool[top10inds[,]
       top10ME = svd(top10Expr,nu = 1,nv = 1)$v[,1]
       if (cor(top10ME,])) < 0) {
           top10ME = -1 * top10ME
       }
       fit = lapply(rownames(datExprTemp),function(x) {
           lm(as.numeric(datExprTemp[rownames(datExprTemp) %in% 
               x,]) ~ top10ME)
       })
       j = j + 1
       sapply(fit,function(y) {
           sum(y$residuals^2)/ncol(datExpr)
       })
   }

会话信息:

Error in { : task 2 Failed - "error code 9 from Lapack routine 'dgesdd'"

 traceback()
3: stop(simpleError(msg,function(y) {
           sum(y$residuals^2)/ncol(datExpr)
       })
   }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)