如何创建大距离矩阵? [英] How to create a Large Distance Matrix?

查看:185
本文介绍了如何创建大距离矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以适当的方式分配巨大的距离矩阵,以避免出现 分配失败
错误。想象一下,您有100.000点随机分布在某些
空间中。如何巧妙地创建一个矩阵或 dist对象,该对象代表
DistMatrix的一半。也许它应该是另一个对象,它将能够有效地分配大量距离。

How to allocate a huge distance matrix in an appropriate way to avoid "allocation is unable" error. Imagine you have a 100.000 points randomly spreaded over some space. How can one cleverly create a matrix or "dist"-object, which represents the the half of DistMatrix. Maybe it should be another object, which will be able efficiently allocate the large number of distances.

您可以从以下链接中获取多边形对象:
< a href = https://www.dropbox.com/sh/65c3rke0gi4d8pb/LAKJWhwm-l rel = nofollow> https://www.dropbox.com/sh/65c3rke0gi4d8pb/LAKJWhwm-l

You can get the polygonial object from the following link: 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(coord@coords)
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,该问题如何解决。

How is this problem solvable in R for great numbers of "n".

推荐答案

这时R不能分配随机数的RAM。此时,您的计算机正在其他地方使用其所有内存,并且没有(一定数量)兆字节可用于您的进程继续。此时,您有几种解决方案。其中,购买一台具有更多RAM的机器,关闭程序,或者小批量进行距离计算。尝试较小的n;当它起作用时,只需重复几次该过程,直到您有了整个距离矩阵即可。

At this point R cannot allocate the random number of megabytes of RAM. At this point, your computer is using all of its memory somewhere else and there just isn't (some number) of MBytes available for your process to continue. You have several solutions at this point. Among them, get a machine with more RAM, close programs, or do your distance calculations in smaller batches. Try a smaller n; and when it works just repeat the process several times until you have your whole matrix of distances.

这篇关于如何创建大距离矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆