Jon*_*nas 4 parallel-processing r
我正在使用该R
软件包bnlearn
来估计贝叶斯网络结构.它使用parallel
包内置并行化.但是,这不起作用.
使用联机帮助页中的示例bnlearn::parallel integration
:
library(parallel)
library(bnlearn)
cl = makeCluster(2)
# check it works.
clusterEvalQ(cl, runif(10)) # -> this works
data(learning.test)
res = gs(learning.test, cluster = cl)
Run Code Online (Sandbox Code Playgroud)
我在这里得到错误 "Error in check.cluster(cluster) : cluster is not a valid cluster object."
有人知道怎么做这个吗?
这是一个错误.请将其报告给软件包维护者.
这是代码check.cluster
:
function (cluster)
{
if (is.null(cluster))
return(TRUE)
if (any(class(cluster) %!in% supported.clusters))
stop("cluster is not a valid cluster object.")
if (!requireNamespace("parallel"))
stop("this function requires the parallel package.")
if (!isClusterRunning(cluster))
stop("the cluster is stopped.")
}
Run Code Online (Sandbox Code Playgroud)
现在,如果你看一下这个类cl
:
class(cl)
#[1] "SOCKcluster" "cluster"
Run Code Online (Sandbox Code Playgroud)
让我们重现一下检查:
bnlearn:::supported.clusters
#[1] "MPIcluster" "PVMcluster" "SOCKcluster"
`%!in%` <- function (x, table) {
match(x, table, nomatch = 0L) == 0L
}
any(class(cl) %!in% bnlearn:::supported.clusters)
#[1] TRUE
Run Code Online (Sandbox Code Playgroud)
cluster
不在supported.clusters
.我相信,该函数应该只检查集群是否有受支持的类,而不是它是否具有不受支持的类.
作为一种解决方案,您可以改变supported.clusters
:
assignInNamespace("supported.clusters",
c("cluster", "MPIcluster",
"PVMcluster", "SOCKcluster"),
"bnlearn")
Run Code Online (Sandbox Code Playgroud)