【发布时间】:2018-08-25 10:48:03
【问题描述】:
虽然有几个问题需要parLapply,但我找不到当前任务的答案...
我尝试在 B 引导样本矩阵列表上使用 parLapply。根据选择的转换(内差或一阶差),我使用 nlminb( ) 来最大化对数似然度。
问题如果我运行代码,核心找不到 SFM.within 或 SFM.firstDiff。 SFM.within 和 SFM.firstDiff 是我的 fepsfrontieR 包中的复杂函数。
问题:如何为集群提供我的功能?
请在下面找到代码。请原谅缺少的示例数据,因为我相信有经验的 parLapply 用户可以轻松回答这个问题......
no_of_cores = detectCores()
cl = makeCluster(no_of_cores, type="PSOCK")
clusterExport(cl, c("myPar", "lowerInt", "Time", "N", "bootListMat", "mu", "optim", "K", "R", "method", "cumTime"))
if (method == "within"){
bootEstimates <- parLapply (cl = cl, bootListMat, function(x) nlminb(lower = lowerInt,
start = myPar,
Time = Time,
N = N,
xv = as.matrix (x[, 2:(2+K-1)]),
y = as.matrix (x[, 1]),
z = as.matrix (x[, (2+K):cols]),
mu = mu,
optim = optim,
K = K, R = R,
objective = SFM.within,
cumTime = cumTime
)$par) # we want only the estimates } else {
bootEstimates <- parLapply (cl = cl, bootListMat, function(x) nlminb(lower = lowerInt,
start = myPar, # TBD by Rouven
Time = Time,
N = N,
xv = as.matrix (x[, 2:(2+K-1)]),
y = as.matrix (x[, 1]),
z = as.matrix (x[, (2+K):cols]),
mu = mu,
optim = optim,
K = K, R = R,
objective = SFM.firstDiff,
cumTime = cumTime
)$par) # we want only the estimates
}
stopCluster(cl)
【问题讨论】:
标签: r parallel-processing