【发布时间】:2017-04-27 06:15:55
【问题描述】:
我正在处理一个大型全球降水数据集(具有非常精细的空间分辨率),以使用 R 中的SPEI package 计算标准化降水指数。
我的问题一般是指使用非常大的数据优化数据处理。我在其他帖子中发现了一些讨论(here、here 和 here fo 实例),但似乎没有什么与我的情况相似。
我的输入是一个矩阵,其中包含超过 20 年的每月观测(>20*12 行)降水时间序列 > 1,000,000 个点(列)。 SPI 的计算为每个时间序列执行一系列步骤,并将指数计算为与中位数的标准差。 输出是一个列表,其结果矩阵 ($fitted) 与输入矩阵的大小相同。
这里是代码示例:
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)
如何拆分我的输入矩阵(或在输入矩阵上拆分过程)以并行处理列向量组(每个列向量都是特定点的完整时间序列),而不会丢失信息(或弄乱我的数据)? 谢谢。
【问题讨论】:
标签: r matrix parallel-processing