0

我尝试使用不同的参数并行运行我自己的函数“EMGMM(y, startmy = 0)”:

require(snow)
library(parallel)

tasks = list(
    job1 = function(y) EMGMM(y=y, startmy = 0),
    job2 = function(y) EMGMM(y=y, startmy = 1),
    job3 = function(y) EMGMM(y=y, startmy = 2)
)

cl = makeCluster( length(tasks) )
clusterExport(cl, list("EMGMM"))

out = clusterApply(cl, tasks, ????)
stopCluster(cl)

但我现在不知道如何称呼“clusterApply”。每个工作中的 y 参数都是相同的,而 startmy 是我的算法的起始参数。

4

1 回答 1

0

谢谢:) y 是多维随机变量的矩阵

这对我来说很好(它可能不是最好的解决方案):

require(snow)
library(parallel)

tasks = list(
    job1 = function(y) EMGMM(y=y, startmy = 0),
    job2 = function(y) EMGMM(y=y, startmy = 1),
    job3 = function(y) EMGMM(y=y, startmy = 2)
)

cl = makeCluster( length(tasks) )
clusterExport(cl, ls())
clusterExport(cl, "dmvnorm") #needed in EMGMM()

out = clusterApply(cl, tasks, function(f) f(y))

stopCluster(cl)
于 2014-07-19T11:13:18.133 回答