我处理大型全球降水数据集(很细的空间分辨率)来计算使用的R.优化/并行化的R - 处理大型数据集R中计算SPI
SPEI package我的标准化降水指数通常我的问题是指使用非常大的数据优化数据处理。我在其他帖子中发现了一些讨论(here,here和here fo实例),但没有一个与我的情况类似。
我的输入是一个包含超过20年每月观测值(> 20 * 12行)降水时间序列的矩阵,其中> 1,000,000点(列)。 SPI的计算为每个时间序列执行一系列步骤,并将该指数计算为中值的标准偏差。 输出是一个列表,结果矩阵($拟合)具有相同大小的输入矩阵。
下面的代码示例:
require(SPEI)
#generating a random values matrix
data<-replicate(200, rnorm(240))
# erasing negative values
data[data<=0]=0
spi6 <- spi(data, 6, kernel = list(type = 'rectangular', shift = 0), distribution = 'PearsonIII', fit = 'ub-pwm', na.rm = FALSE, ref.start=NULL, ref.end=NULL, x=FALSE, params=NULL)
#testing the results
plot(spi6$fitted[,67])
#taking my results out
results <- t(spi6$fitted)
这个脚本作品完美,但如果我增加点(在这种情况下,列)成倍的处理时间增加而增加。直到达到内存不足的问题:
Warning messages:
1: In std[ff, s] <- qnorm(cdfpe3(acu.pred[ff], p3par)) :
Reached total allocation of 16253Mb: see help(memory.size)
2: In std[ff, s] <- qnorm(cdfpe3(acu.pred[ff], p3par)) :
Reached total allocation of 16253Mb: see help(memory.size)
3: In NextMethod("[<-") :
Reached total allocation of 16253Mb: see help(memory.size)
4: In NextMethod("[<-") :
Reached total allocation of 16253Mb: see help(memory.size)
5: In std[ff, s] <- qnorm(pze + (1 - pze) * pnorm(std[ff, s])) :
Reached total allocation of 16253Mb: see help(memory.size)
6: In std[ff, s] <- qnorm(pze + (1 - pze) * pnorm(std[ff, s])) :
Reached total allocation of 16253Mb: see help(memory.size)
7: In NextMethod("[<-") :
Reached total allocation of 16253Mb: see help(memory.size)
8: In NextMethod("[<-") :
Reached total allocation of 16253Mb: see help(memory.size)
如何可以分割我的输入矩阵(或分割在输入矩阵的步骤),以列向量的并行处理组(它们中的每一个完整的时间序列的一个特定的点),而不会丢失信息(或弄乱我的数据)? 谢谢。
谢谢圣地亚哥。并行解决方案(最后一个)大大加快了进程速度,但仍会产生内存问题。使用apply的人工作得很好。 – Nemesi
你是对的,paralellizing不解决内存问题。我编辑我的答案以反映这一点。 –