2014-01-22 31 views
1

如何以适当的方式分配一个巨大的距离矩阵,以避免“分配是 无法”错误。想象一下,你在一些 空间中有100000个随机点。如何巧妙地创建一个矩阵或“dist” - 对象,它代表DistMatrix的一半。也许它应该是另一个对象,它将能够有效地分配大量的距离。如何创建一个大距离矩阵?

你可以从以下链接polygonial对象: https://www.dropbox.com/sh/65c3rke0gi4d8pb/LAKJWhwm-l

# Load required packages 
library(sp) 
library(maptools) 
library(maps) 

# Load the polygonal object 
x <- readShapePoly("vg250_gem.shp") 

# Sample or Pick up a large Number of Points 
# this command needs some minutes to be done. 
# "coord" is SpatialPoints Object 
n <- 1e5 
coord <- spsample(x, n, "random") 
# Try to measure the distances by dist() 

DistMatrix <- dist([email protected]) 
Error: negative length vectors are not allowed 

# Try to measure the distances by spDists() 
DistMatrix <- spDists(coord) 
Error: cannot allocate vector of size (some number) MB 

# It seems that the problem lies on large matrix to be created. 

如何为这个问题中的R可解为“N”的伟大数字。

回答

0

此时R无法分配RAM的随机数兆字节。此时,您的计算机正在将其所有内存都用于其他地方,并且您的进程没有(某些数量)的MBytes可用于继续。此时您有几种解决方案。其中,获得更多内存,关闭程序的机器,或者以较小的批次进行距离计算。尝试一个更小的n;当它工作时只需重复这个过程几次,直到你有了你的整个距离矩阵。

+0

说小批量做你只是指使用spDistsN1()?请如果你能澄清你的想法,它可以是有用的。提前致谢。 –

+0

嗨。我不熟悉这种方法。但如果它适合你的话。实际上,我的意思是将距离矩阵分成子矩阵并逐个求解每个子矩阵。每次将结果保存在硬盘上。释放你的RAM。 –

+0

你知道一些包加速简单的计算任务,如sum,sqrt等。我听说有一个允许的包,但我找不到任何包。 –