如何解决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 举报,一经查实,本站将立刻删除。