【问题标题】:R calculating Earth Mover's Distance for large rastersR计算大栅格的地球移动距离
【发布时间】:2016-07-23 09:06:36
【问题描述】:

我正在尝试使用 emd2d(来自 emdist 库,版本 0.3-1)对两个栅格之间的(不)相似性进行定量估计。 以下代码对于小矩阵(~35x35)运行良好,但我的栅格要大得多(~5000x3000),并且出现内存错误:

emdr(A, B, dist = dist, ...) 中的错误:
无法在 emdist 中存储 (-1608.8 MB)

这里有一个示例代码来说明问题:

#test case:
library(emdist)
Rows = 40
Cols = 40
Mat1 = matrix( 
       seq(1,Rows*Cols), 
       nrow = Rows, 
       ncol = Cols) 

m0 <- matrix(0, Rows, Cols)
Mat_Rand = apply(m0, c(1,2), function(x) rnorm(1)) #sample(c(0,1),1))
Mat2 = Mat1 * Mat_Rand

emd2d(Mat1,Mat2,dist="euclidean")

我在 win7 64 位上运行 R R 版本 3.2.5。

谢谢

喜欢

【问题讨论】:

  • 请说明问题?您可能内存不足。

标签: r matrix raster similarity


【解决方案1】:

要绕过内存限制,您可以对矩阵进行采样,例如随机选择每行 40 个中的 30 个和每列 40 个中的 30 个来形成一个新矩阵,从而将配对从超过 100 万个减少到不到 50 万个。

seed.set(1234)
row.rand = sample(1:40, 30)
col.rand = sample(1:40, 30)
Mat1.new = matrix(NA, 30,30)
Mat2.new = matrix(NA, 30,30)
for(i in 1:length(row.rand)){
    for(j in 1:length(col.rand)){
        Mat1.new[i,j] = Mat1[row.rand[i],col.rand[j]]
        Mat2.new[i,j] = Mat2[row.rand[i],col.rand[j]]
    }
} 
emd2d(Mat1.new, Mat2.new)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 2016-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多