wpeterman / ResistanceGA

Optimize resistance surfaces using Genetic Algorithms
36 stars 15 forks source link

Potential bug in SS_optim #6

Closed jeffreyhanson closed 6 years ago

jeffreyhanson commented 6 years ago

Hi,

I'm receiving the following error when I try and use SS_optim or MS_optim with the latest version of ResistanceGA (4.0-12):

Error in ga(type = "real-valued", fitness = Resistance.Opt_single, Resistance = r,  : 
  A min and max range of values (for 'real-valued' or 'permutation' GA) or nBits (for 'binary' GA) must be provided!

I've included a reproducible example and my session information below. If you have any suggestions or ideas on what I'm doing wrong that would be great.

Cheers,

Jeff


Reproducible example

# load package
library(ResistanceGA)

# Import data
data(resistance_surfaces)
continuous <- resistance_surfaces[[2]]
data(samples)
sample.locales <- SpatialPoints(samples[,c(2,3)])

# Set the random number seed to reproduce the results presented
# Run in parallel on 4 cores
GA.inputs <- GA.prep(ASCII.dir=continuous,
                     Results.dir=paste0(tempdir(), "/"),
                     select.trans = "M",
                     max.cat=500,
                     max.cont=500,
                     seed = 555,
                     parallel = 4) 

# Create gdist input using geographic distance
gdist.inputs <- gdist.prep(length(sample.locales),
                           samples = sample.locales,
                           response = ResistanceGA::lower(as.matrix(dist(sample.locales@coords))),
                           method = 'commuteDistance') ## Optimize using commute distance

# Run optimization
SS_RESULTS.gdist <- SS_optim(gdist.inputs = gdist.inputs,
                             GA.inputs = GA.inputs)

Session information

sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.4 LTS

Matrix products: default
BLAS: /opt/R/R-3.4.4/lib/R/lib/libRblas.so
LAPACK: /opt/R/R-3.4.4/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ResistanceGA_4.0-12 raster_2.5-8        sp_1.2-4           
[4] lpsymphony_1.6.0    gurobi_8.0-1        slam_0.1-40        

loaded via a namespace (and not attached):
 [1] akima_0.6-2          gdistance_1.2-1      GA_3.0.2            
 [4] splines_3.4.4        lattice_0.20-35      spatstat.utils_1.9-0
 [7] colorspace_1.3-2     miniUI_0.1.1.1       htmltools_0.3.5     
[10] stats4_3.4.4         mgcv_1.8-23          rlang_0.2.0         
[13] spatstat.data_1.3-1  pillar_1.2.2         nloptr_1.0.4        
[16] spatstat_1.56-1      withr_2.1.0.9000     DBI_0.6             
[19] foreach_1.4.3        plyr_1.8.4           munsell_0.4.3       
[22] gtable_0.2.0         devtools_1.12.0      codetools_0.2-15    
[25] memoise_1.0.0        knitr_1.15.1         httpuv_1.3.3        
[28] curl_2.3             Rcpp_0.12.10         tensor_1.5          
[31] xtable_1.8-2         scales_0.5.0.9000    abind_1.4-5         
[34] deldir_0.1-12        mime_0.5             lme4_1.1-12         
[37] ggExtra_0.8          ggplot2_2.2.1.9000   packrat_0.4.8-1     
[40] digest_0.6.12        dplyr_0.5.0          shiny_1.0.0         
[43] polyclip_1.9-1       grid_3.4.4           tools_3.4.4         
[46] goftest_1.1-1        magrittr_1.5         lazyeval_0.2.0      
[49] tibble_1.4.2         MASS_7.3-49          Matrix_1.2-12       
[52] MuMIn_1.15.6         assertthat_0.2.0     minqa_1.2.4         
[55] httr_1.2.1           iterators_1.0.8      rpart_4.1-13        
[58] R6_2.2.0             igraph_1.0.1         nlme_3.1-131.1      
[61] git2r_0.18.0         compiler_3.4.4  
jeffreyhanson commented 6 years ago

I managed to get the latest version of ResistanceGA working by updating my installed version of the GA package (from 3.0.2 to 3.1.1), so I'll close this now.

wpeterman commented 6 years ago

Great, thanks.

jeffreyhanson commented 6 years ago

If it helps, I can submit a PR that adds this version dependency to the DESCRIPTION?

wpeterman commented 6 years ago

Feel free to do so, thanks.