2014-01-22 36 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等。我聽說有一個允許的包,但我找不到任何包。 –