虽然有几个问题需要解决,但我找不到我当前任务的答案......
我尝试在 B 引导样本矩阵列表上使用 parLapp。根据所选的变换(在差异内或第一差异内(,我使用 nlminb( ( 来最大化对数似然。
如果我运行代码,问题在于内核找不到SFM.in或SFM.firstDiff。 SFM.inside和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 会话(中的"worker"评估的代码取决于包 fepsfrontieR,则需要在每个工作线程中附加该包(就像在主 R 会话中一样(。因此,请尝试:
clusterEvalQ(cl, library(fepsfrontieR))
我认为您还必须将函数导出到集群