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」的偉大數字。
說小批量做你只是指使用spDistsN1()?請如果你能澄清你的想法,它可以是有用的。提前致謝。 –
嗨。我不熟悉這種方法。但如果它適合你的話。實際上,我的意思是將距離矩陣分成子矩陣並逐個求解每個子矩陣。每次將結果保存在硬盤上。釋放你的RAM。 –
你知道一些包加速簡單的計算任務,如sum,sqrt等。我聽說有一個允許的包,但我找不到任何包。 –