mpadge / spatialcluster

spatially-constrained clustering in R
https://mpadge.github.io/spatialcluster/
30 stars 6 forks source link

bug in rcpp_slk #20

Closed mpadge closed 6 years ago

mpadge commented 6 years ago

This fails:

devtools::load_all (".", export_all = TRUE)
getdat <- function (ncl = 5, noise = 0.1) {
    sizes <- ceiling (runif (ncl) * 20)
    x <- rep (runif (ncl), times = sizes) + runif (sum (sizes), -1, 1) * noise
    y <- rep (runif (ncl), times = sizes) + runif (sum (sizes), -1, 1) * noise
    cols <- rep (rainbow (ncl), times = sizes)
    data.frame (x = x, y = y, col = cols)
}
set.seed (2)
ncl <- 5
dat_nospace <- getdat (ncl = ncl, noise = 0.1)
dat_space <- getdat (ncl = ncl, noise = 0.2)
nr <- min (c (nrow (dat_nospace), nrow (dat_space)))
dat_nospace <- dat_nospace [1:nr, ]
dat_space <- dat_space [1:nr, ]

dmat <- as.matrix (dist (dat_nospace [, 1:2]))
#scl <- scl_redcap (dat_space [, 1:2], dmat, ncl = ncl, linkage = "single")

xy <- scl_tbl (dat_space [, 1:2])
distances <- TRUE
edges_nn <- scl_edges_nn (xy, dmat, distances)
edges_all <- scl_edges_all (xy, dmat, distances)
#tree_full <- scl_spantree_slk (edges_all, edges_nn)
clusters <- rcpp_slk (edges_all, edges_nn) + 1
mpadge commented 6 years ago

Problem arises because of using comparison of 1st & 2nd distances to determine whether distances are increasing or decreasing. If there are a series of zero or otherwise equal values to begin with, then this fails.