GeoDaCenter / rgeoda

R library for spatial data analysis based on libgeoda and GeoDa
70 stars 13 forks source link

Random REDCAP and SKATER crashes #33

Open MattIwicki opened 2 years ago

MattIwicki commented 2 years ago

Hi!

I found that both Redcap and Skater algorithms randomly crash R when given too many polygons. The crash was recreated on different machines, including RStudio Cloud.

library(sf)
library(rgeoda)

# creating test geometry with random values
sfc = st_sfc(st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,0)))))
grid = st_make_grid(sfc, cellsize = 0.02, square = F)
grid = st_sf(geom = grid)
grid$value = runif(nrow(grid))

# assigning weights
w = queen_weights(grid)

# looping the redcap algorithm
# using print to see after how many iterations R crashes
for(i in 100:1){
  print(i)
  redcap(10, w, grid[,"value"])
}
Nowosad commented 2 years ago

Note: This problem does not occur for cpu_threads = 1 (when parallel processing is not used).

library(sf)
library(rgeoda)
sfc = st_sfc(st_polygon(list(rbind(c(0,0), c(1,0), c(1,1), c(0,0)))))
grid = st_make_grid(sfc, cellsize = 0.02, square = F)
grid = st_sf(value = runif(length(grid)), geom = grid)

w = queen_weights(grid)

for(i in 100:1){
  print(i)
  redcap(10, w, grid[,"value"], cpu_threads = 1)
}

Related issue: https://github.com/GeoDaCenter/rgeoda/issues/27