2015-02-09 17 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")