在 R NMF 包中保存 foreach 循环的输出
Save output of foreach loop in R NMF package
我深表歉意,因为我知道之前有人问过这个问题,但我已经尝试了大多数答案的变体,但没有任何帮助。
我正在使用 foreach 包 运行 一组数据上的 NMF 算法循环。我是他们尝试使用 ExtractFeatures 函数提取基础名称集,该函数输出每个 运行 作为您确定的排名数量的列表(在我的示例中,3)。
下面是我的代码(我使用了来自 NMF Vignette 的示例数据集):
library("NMF")
library("doParallel")
library("foreach")
#load vignette dataset and shorten it for time's sake
data(esGolub)
esGolub <- esGolub[1:200,]
#output matrix
Extract_Genes <- matrix()
#set cores
registerDoParallel(cores = 3)
#Loop NMF runs and extract features
foreach(i =1:4, .packages = "NMF") %dopar%{
i <- nmf(esGolub, 3, nrun = 1)
Extract_Genes <- extractFeatures(i, format = "list")
}
这将输出提取的基因列表,如下所示:
[[1]]
[[1]][[1]]
[1] 43 120 128 130
[[1]][[2]]
[1] 94 1 112 42 8 64 96 182 59 41 69 25 26
[[1]][[3]]
[1] 39 74 2 91 190 167 103 129 174
3 次超过 3 运行 秒,但它不保存。有人对我如何保存这些输出有什么建议吗?
提前谢谢你,J
Imo 的评论工作正常:
myList <- foreach(i =1:4, .packages = "NMF") %dopar%{
我深表歉意,因为我知道之前有人问过这个问题,但我已经尝试了大多数答案的变体,但没有任何帮助。
我正在使用 foreach 包 运行 一组数据上的 NMF 算法循环。我是他们尝试使用 ExtractFeatures 函数提取基础名称集,该函数输出每个 运行 作为您确定的排名数量的列表(在我的示例中,3)。
下面是我的代码(我使用了来自 NMF Vignette 的示例数据集):
library("NMF")
library("doParallel")
library("foreach")
#load vignette dataset and shorten it for time's sake
data(esGolub)
esGolub <- esGolub[1:200,]
#output matrix
Extract_Genes <- matrix()
#set cores
registerDoParallel(cores = 3)
#Loop NMF runs and extract features
foreach(i =1:4, .packages = "NMF") %dopar%{
i <- nmf(esGolub, 3, nrun = 1)
Extract_Genes <- extractFeatures(i, format = "list")
}
这将输出提取的基因列表,如下所示:
[[1]]
[[1]][[1]]
[1] 43 120 128 130
[[1]][[2]]
[1] 94 1 112 42 8 64 96 182 59 41 69 25 26
[[1]][[3]]
[1] 39 74 2 91 190 167 103 129 174
3 次超过 3 运行 秒,但它不保存。有人对我如何保存这些输出有什么建议吗?
提前谢谢你,J
Imo 的评论工作正常:
myList <- foreach(i =1:4, .packages = "NMF") %dopar%{