錯誤我試圖與20 CPU運行的是UNIX系統下面的代碼,,使用R foreach
,parallel
,doParallel
,和party
包(我的目標是有黨/ varimp功能並行的多個CPU的工作):錯誤在反序列化(socklist [[N]]):從連接讀取在Unix
parallel_compute_varimp <- function (object, mincriterion = 0, conditional = FALSE, threshold = 0.2,
nperm = 1, OOB = TRUE, pre1.0_0 = conditional)
{
response <- [email protected]
input <- [email protected]@get("input")
xnames <- colnames(input)
inp <- initVariableFrame(input, trafo = NULL)
y <- [email protected]@variables[[1]]
error <- function(x, oob) mean((levels(y)[sapply(x, which.max)] != y)[oob])
w <- [email protected]
perror <- matrix(0, nrow = nperm * length([email protected]), ncol = length(xnames))
colnames(perror) <- xnames
data = foreach(b = 1:length([email protected]), .packages = c("party","stats"), .combine = rbind) %dopar%
{
try({
tree <- [email protected][[b]]
oob <- [email protected][[b]] == 0
p <- .Call("R_predict", tree, inp, mincriterion, -1L, PACKAGE = "party")
eoob <- error(p, oob)
for (j in unique(varIDs(tree))) {
for (per in 1:nperm) {
if (conditional || pre1.0_0) {
tmp <- inp
ccl <- create_cond_list(conditional, threshold, xnames[j], input)
if (is.null(ccl)) {
perm <- sample(which(oob))
}
else {
perm <- conditional_perm(ccl, xnames, input, tree, oob)
}
[email protected][[j]][which(oob)] <- [email protected][[j]][perm]
p <- .Call("R_predict", tree, tmp, mincriterion, -1L, PACKAGE = "party")
}
else {
p <- .Call("R_predict", tree, inp, mincriterion, as.integer(j), PACKAGE = "party")
}
perror[b, j] <- (error(p, oob) - eoob)
}
}
########
# return data to the %dopar% loop data variable
perror[b, ]
########
}) # END OF TRY
} # END OF LOOP WITH PARALLEL COMPUTING
perror = data
perror <- as.data.frame(perror)
return(MeanDecreaseAccuracy = colMeans(perror))
}
environment(parallel_compute_varimp) <- asNamespace('party')
cl <- makeCluster(detectCores())
registerDoParallel(cl, cores = detectCores())
<...>
system.time(data.cforest.varimp <- parallel_compute_varimp(data.cforest, conditional = TRUE))
但我得到一個錯誤:
> system.time(data.cforest.varimp <- parallel_compute_varimp(data.cforest, conditional = TRUE))
Error in unserialize(socklist[[n]]) : error reading from connection
Timing stopped at: 58.302 13.197 709.307
代碼是用較小的數據集上的4個CPU的工作。
我正在用盡想法。有人可以提出一種方法來達到我在並行CPU上運行party package varimp函數的目標嗎?
你知道這個問題嗎? – Zach
我不這麼認爲。無論如何我都忘了它:) – tucson