wpeterman / ResistanceGA

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

Issues with GA::ga() function in SS_optim() and MS_optim() #33

Closed JGPunier closed 1 year ago

JGPunier commented 1 year ago

Hello I recently updated ResistanceGA (v.4.2.9) and I keep getting errors when running the SS_optim() and the MS_optim() functions, whatever the handled dataset (everything was fine with a previous version of the package I used in March 2021) I tried with my own datasets, as well as with those provided with the package, that is:

My commands are the following for SS_optim : GA.inputs <- GA.prep(ASCII.dir=resistance_surfaces[[1]], Results.dir=paste0(main,"/test/"), parallel = 10) gdist.inputs <- gdist.prep(length(sample.locales), samples = sample.locales, response = lower(Dc_list[[1]][1:25,1:25]), method = 'commuteDistance') SS_RESULTS.gdist <- SS_optim(gdist.inputs = gdist.inputs, GA.inputs = GA.inputs)

and the following for MS_optim : GA.inputs <- GA.prep(ASCII.dir=resistance_surfaces, Results.dir=paste0(main,"/test/"), parallel = 10) gdist.inputs <- gdist.prep(length(sample.locales), samples = sample.locales, response = lower(Dc_list[[1]][1:25,1:25]), method = 'commuteDistance') SS_RESULTS.gdist <- MS_optim(gdist.inputs = gdist.inputs, GA.inputs = GA.inputs)

Note that I get the same errors whatever the method used ("costDistance" or "commuteDistance")

The error with SS-optim is the following : "Error in { : task N failed - "0 (non-NA) cases" with N ranging from 1 to 4 depending on the run, which suggests an issue with an iterative process.

The error with MS-optim is the following : "Error in { : task 1 failed - replacement has 1 rows, data has Y" with Y being the length of the response vector (i.e., Y = 300 for the 25 samples from the sample.locales object)

In both cases, traceback() points to the GA::ga() function, as indicated below for SS_optim

_7: stop(simpleError(msg, call = expr)) 6: e$fun(obj, substitute(ex), parent.frame(), e$data) 5: (function (obj, ex) { e <- getDoPar() e$fun(obj, substitute(ex), parent.frame(), e$data) })(structure(list(args = seq_len(popSize)(.doRNG.stream = list( c(10407L, 428094913L, 1532680334L, -1655922761L, 2049912972L, 1842150429L, 1376803898L), c(10407L, -543019799L, 785898928L, 1747243086L, -148731881L, -422405155L, -1002265700L), c(10407L, -223435128L, 643606822L, 417527330L, -582193243L, -1496025378L, -862618860L), c(10407L, 1014030182L, -1845268902L, 761681033L, -653776266L, 1761582385L, 1526003606L), c(10407L, -1797595570L, 563515179L, -2066534802L, 284108639L, 1112757431L, 370668131L ), c(10407L, 399045750L, -973570918L, 411412967L, 338555026L, 2087534884L, 165144246L), c(10407L, 1794639416L, 466264297L, 2006857113L, 378033522L, 1699708191L, -1245133161L), c(10407L, -1865398319L, 486451659L, -997926930L, -364494469L, 1427050736L, 1670866193L), c(10407L, 1353202114L, -1224107971L, 1083044696L, -1323452596L, -523646557L, 933409947L), c(10407L, -548320847L, -414565749L, 1337068228L, 1973677165L, -2122917714L, -4814366L ), c(10407L, 1373466268L, -581354932L, 1401018777L, -1303882456L, ... 4: do.call(%dopar%, list(obj, ex), envir = parent.frame()) 3: foreach(i. = seq_len(popSize), .combine = "c") %DO% { if (is.na(Fitness[i.])) do.call(fitness, c(list(Pop[i., ]), callArgs)) else Fitness[i.] } 2: ga(type = "real-valued", fitness = Resistance.Opt_single, Resistance = r, population = GA.inputs$population, selection = GA.inputs$selection, pcrossover = GA.inputs$pcrossover, pmutation = GA.inputs$pmutation, crossover = GA.inputs$crossover, Min.Max = GA.inputs$Min.Max, GA.inputs = GA.inputs, gdist.inputs = gdist.inputs, lower = GA.inputs$min.list[[i]], upper = GA.inputs$max.list[[i]], parallel = GA.inputs$parallel, optim = GA.inputs$optim, optimArgs = GA.inputs$optimArgs, popSize = GA.inputs$pop.size, maxiter = GA.inputs$maxiter, run = GA.inputs$run, keepBest = GA.inputs$keepBest, elitism = GA.inputs$percent.elite, mutation = GA.inputs$mutation, seed = GA.inputs$seed, monitor = GA.inputs$monitor, iter = i, quiet = GA.inputs$quiet) 1: SSoptim(gdist.inputs = gdist.inputs, GA.inputs = GA.inputs)

The traceback is exactly the same for MS_optim, except for "L-values" in part 5 that differ.

Any idea of what is going wrong? Any help would be much appreciated.

My system : RStudio 2023.03.0 Build 386 R version 4.2.3 (2023-03-15) -- "Shortstop Beagle" Ubuntu 18.04.6 LTS (Bionic Beaver)

JGPunier commented 1 year ago

Found the answer in closed issues... switching to Julia Thanks for the great package !