[R-sig-Geo] skater - spdep runtime - geographic territories

Elias T. Krainski e||@@kr@|n@k| @end|ng |rom gm@||@com
Wed Jun 12 01:12:47 CEST 2019


Hi Salo,

In the file I sent attached to my previous email the ssdfun() has to be 
replaced by the following in order to give the same results as the 
default option in skater():

ssdfun <- function(d,i)
     sum(sqrt(colSums((t(d[i,,drop=FALSE])-
                       colMeans(d[i,,drop=FALSE]))^2)))

So, the recommendation is to use skater(..., method=ssdfun)

Best regards,

Elias

On 6/11/19 5:21 PM, Salo V wrote:
> Hi Everyone,
>
> I am trying to run the skater function for graph partitions, part of the
> spdep package. My goal is to create contiguous territories for the entire
> USA at the ZIP Code level.
>
> The function takes a very long time to run even for ~15% of my total areas.
> I am looking to run this for the 30,000 ZIP Codes in the USA.
>
> The skater function documentation gives an example of parallel processing,
> but it doesn’t seem to be speeding things up. I have a windows laptop with
> 2 physical cores and 4 logical cores. In the below code, I have already
> tried to set nc = 1, nc=2 and nc=4 all with very similar results in time.
>
> Has anyone been able to run the skater function for a large amount of areas
> in a reasonable amount of time? Would really appreciate any guidance on
> this, perhaps I am missing steps.
>
>
>
> Here is the example from the documentation and which I am also running.
>
> *library*(parallel)
>
> nc <- detectCores(logical=FALSE)
>
> # set nc to 1L here
>
> *if* (nc > 1L) nc <- 1L
>
> coresOpt <- get.coresOption()
>
> invisible(set.coresOption(nc))
>
> *if*(!get.mcOption()) {
>
> # no-op, "snow" parallel calculation not available
>
>    cl <- makeCluster(get.coresOption())
>
>    set.ClusterOption(cl)
>
> }
>
> ### calculating costs
>
> system.time(plcosts <- nbcosts(bh.nb, dpad))
>
> all.equal(lcosts, plcosts, check.attributes=FALSE)
>
> ### making listw
>
> pnb.w <- nb2listw(bh.nb, plcosts, style="B")
>
> ### find a minimum spanning tree
>
> pmst.bh <- mstree(pnb.w,5)
>
> ### three groups with no restriction
>
> system.time(pres1 <- skater(pmst.bh[,1:2], dpad, 2))
>
> *if*(!get.mcOption()) {
>
>    set.ClusterOption(NULL)
>
>    stopCluster(cl)
>
> }
>
>
> much appreciated!
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list