2015-02-09 67 views
4

我使用R程序包bnlearn来估计贝叶斯网络结构。它具有使用parallel包的内置并行化。但是,这是行不通的。使用bnlearn的并行化(使用并行程序包)

的例子的手册页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) 

在这里,我得到的错误"Error in check.cluster(cluster) : cluster is not a valid cluster object."

有谁知道如何得到这个工作?

回答

6

这是一个错误。请将其报告给软件包维护人员。

这里是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.") 
} 

现在,如果你看一下类的cl

class(cl) 
#[1] "SOCKcluster" "cluster" 

让我们重现检查:

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 

cluster是不在supported.clusters。我相信,该函数只应检查群集是否具有受支持的类,而不是具有不受支持的类。

作为变通,你可以改变supported.clusters

assignInNamespace("supported.clusters", 
        c("cluster", "MPIcluster", 
        "PVMcluster", "SOCKcluster"), 
        "bnlearn")