bash_scripts/pipeline_ML.R

DAISIE_ML_run = function(parsindex, project, args, all_args)
{
  # args is a vector with simulation arguments
  # all_args is a string with same simulation arguments used in file names
  .libPaths('/home/p282067/R/3.5/')
  setwd('/home/p282067/DAISIE/results')
  require(DAISIE)
  count <- 0
  print(list.files(file.path("/home", "p282067", project, "data")))
  while (!file.exists(file.path("/home", "p282067", project, "data", paste0("sim-", project, all_args, ".RData")))) {
    Sys.sleep(1)
    count <- count + 1
    stopifnot(count < 50)
  }
  load(file.path("/home", "p282067", project, "data", paste0("sim-", project, all_args, ".RData")))
  set.seed(args[1])

#1: seed
#2: time
#3: M
#4: lac
#5: mu
#6: K
#7: gam
#8: laa
#9: replicates
#10: mu_min
#11: mu_max
#12: Amax
#13: Apeak
#14: Asharpness
#15: Atotalage

time <- args[2]
M <- args[3]
pars <- c(0.1, 0.1, 18, args[7], args[8]) # Using standard starting params
replicates <- args[9]
Epars <- c(args[10], args[11])
divdepmodel <- "CS"
plot_sims <- FALSE
island_ontogeny <- "beta"
Apars <- c(
  max_area = args[12],
  proportional_peak_t = args[13],
  peak_sharpness = args[14],
  total_island_age = args[15]
)

keep_final_state <- FALSE
stored_data <- NULL
verbose <- TRUE
rng_value <- args[1]

  cat("Initial parameters to optimize: ", pars, "\n")
  flush.console()

  initpars <- pars
  seq_range <- seq(1, M + 1, by = M / 10)
  seq_range[11] <- M
  out_results <- list()

  for (k in 0:((M / 10) - 1)) {
  cat("index is: ", seq_range[parsindex] + k, "\n")
  cat("Executing estimate", k + 1, "of, ", (M / 10),"...\n")
  flush.console()
    out_results[[k + 1]] <- try(DAISIE::DAISIE_ML(out[[seq_range[parsindex] + k]],
                                                               initparsopt = pars, idparsopt = 1:5,
                                                               parsfix = NULL, idparsfix = NULL, ddmodel = 11, CS_version = 1))
    if (class(out_results[[k + 1]]) == 'try-error') {
	out_results[[k + 1]] <- "No converge"
    }
    if (k == ((M / 10) - 1)) {
		save(out_results, Apars, Epars, time, pars, file = paste0("res-", project, "-", all_args, "_", parsindex, ".RData"))
		gc()
		}
	}
}
Neves-P/utilSIE documentation built on Nov. 20, 2019, 7 a.m.