biomodhub / biomod2

BIOMOD is a computer platform for ensemble forecasting of species distributions, enabling the treatment of a range of methodological uncertainties in models and the examination of species-environment relationships.
89 stars 22 forks source link

Help with BIOMOD_4.2-5-2 - Error in summary.connection(connection) : invalid connection #543

Open tongruiju opened 2 days ago

tongruiju commented 2 days ago

Hi,

We have tuned the parameters as detailed below, but subsequently encountered the error: 'Error in summary.connection(connection) : invalid connection'. This error appears to be associated with the transfer of tuned parameters, as no such error is reported when we do not perform tuning. Thank you in advance for your assistance.

Best, Ruiju

**> bm.options <- bm_ModelingOptions(data.type = 'binary', models = c('GBM', 'MAXENT'), strategy = 'default', bm.format = myBiomodData)

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Build Modeling Options -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

>  GBM options (datatype: binary , package: gbm , function: gbm )...
>  MAXENT options (datatype: binary , package: MAXENT , function: MAXENT )...

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

gbm.params <- list(

  • GBM.n.trees = c(500, 1000, 2500),
  • GBM.interaction.depth = 5,
  • GBM.shrinkage = 0.01,
  • GBM.n.minobsinnode = 10
  • )

maxent.params <- list(MAXENT.algorithm = "maxnet", MAXENT.parallel = TRUE) start.time.gbm <- Sys.time()

tuning.result.gbm <- bm_Tuning(model = "GBM",

  • tuning.fun = "gbm",
  • do.formula = FALSE,
  • do.stepAIC = FALSE,
  • bm.options = bm.options@options$GBM.binary.gbm.gbm,
  • bm.format = myBiomodData,
  • calib.lines = NULL,
  • metric.eval = "TSS",
  • metric.AIC = "AIC",
  • weights = NULL,
  • ctrl.train = NULL,
  • params.train = gbm.params)

Dataset _allData_allRun Tuning parameters...>

end.time.gbm <- Sys.time() time.elapsed.gbm <- end.time.gbm - start.time.gbm print(paste("GBM tuning took", time.elapsed.gbm)) [1] "GBM tuning took 5.46707306702932" start.time.maxent <- Sys.time() tuning.result.maxent <- bm_Tuning(

  • model = "MAXENT",
  • tuning.fun = "maxnet",
  • do.formula = FALSE,
  • do.stepAIC = FALSE,
  • bm.options = bm.options@options$MAXENT.binary.MAXENT.MAXENT,
  • bm.format = myBiomodData,
  • calib.lines = NULL,
  • metric.eval = "AICc",
  • metric.AIC = "AIC",
  • weights = NULL,
  • ctrl.train = NULL,
  • params.train = maxent.params
  • )

Dataset _allData_allRun Tuning parameters...Package ecospat is not installed, so Continuous Boyce Index (CBI) cannot be calculated. Running initial checks...

Running ENMeval v2.0.3 with maxnet from maxnet package v0.1.4

| | 0% Of 32 total cores using 32... Running in parallel using doSNOW... |=============================================================================================| 100% ENMevaluate completed in 2 minutes 5.9 seconds.

end.time.maxent <- Sys.time() time.elapsed.maxent <- end.time.maxent - start.time.maxent print(paste("MAXENT tuning took", time.elapsed.maxent)) [1] "MAXENT tuning took 2.10798231760661"

print(tuning.result.gbm) $_allData_allRun $_allData_allRun$formula SP ~ 1 + BPI9 + gebco2023PJ_clip + o2_mean_2000PJ + oa_co3_TRI_MPI20002014_co3satarag_Can20002014_IDW3DPJ_clip1 + ph_mean_2000PJ + phyc_mean_2000PJ + si_mean_2000PJ + slope + so_mean_2000PJ + swd_mean_2000PJ + sws_mean_2000PJ + thetao_mean_2000PJ + TPI + wld01_grz_idw3d_ProjminPJ_clip1 + wld01_rck_idw3d_Projmin_PJ_clip1 <environment: 0x000001890dd92258>

$_allData_allRun$distribution [1] "bernoulli"

$_allData_allRun$data list()

$_allData_allRun$weights

$_allData_allRun$var.monotone NULL

$_allData_allRun$n.trees [1] 2500

$_allData_allRun$interaction.depth [1] 5

$_allData_allRun$n.minobsinnode [1] 10

$_allData_allRun$shrinkage [1] 0.01

$_allData_allRun$bag.fraction [1] 0.5

$_allData_allRun$train.fraction [1] 1

$_allData_allRun$cv.folds [1] 0

$_allData_allRun$keep.data [1] TRUE

$_allData_allRun$verbose [1] FALSE

$_allData_allRun$class.stratify.cv NULL

$_allData_allRun$n.cores NULL

print(tuning.result.maxent) $_allData_allRun $_allData_allRun$path_to_maxent.jar [1] "E:/paper11/BioOracleTIFPJ/ssp126/DP"

$_allData_allRun$memory_allocated [1] 512

$_allData_allRun$initial_heap_size NULL

$_allData_allRun$max_heap_size NULL

$_allData_allRun$background_data_dir [1] "default"

$_allData_allRun$visible [1] FALSE

$_allData_allRun$linear [1] TRUE

$_allData_allRun$quadratic [1] FALSE

$_allData_allRun$product [1] FALSE

$_allData_allRun$threshold [1] FALSE

$_allData_allRun$hinge [1] FALSE

$_allData_allRun$lq2lqptthreshold [1] 80

$_allData_allRun$l2lqthreshold [1] 10

$_allData_allRun$hingethreshold [1] 15

$_allData_allRun$beta_threshold [1] -1

$_allData_allRun$beta_categorical [1] -1

$_allData_allRun$beta_lqp [1] -1

$_allData_allRun$beta_hinge [1] -1

$_allData_allRun$betamultiplier [1] 0.5 Levels: 0.5 1

$_allData_allRun$defaultprevalence [1] 0.5

myBiomodModelOut <- BIOMOD_Modeling(

  • bm.format = myBiomodData,
  • models = c('GBM', 'MAXENT'),
  • CV.strategy = 'kfold',
  • CV.nb.rep = 1,
  • CV.k = 10,
  • CV.perc = 0.8,
  • var.import = 3,
  • metric.eval = c('TSS','ROC', 'KAPPA'),
  • bm.options = list(tuning.result.gbm, tuning.result.maxent)
  • )

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Build Single Models -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Checking Models arguments...

> Automatic weights creation to rise a 0.5 prevalence

!!! argument 'bm.options' is obsolete, please use 'OPT.user' instead Creating suitable Workdir...

Checking Cross-Validation arguments...

k-fold cross-validation selection

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Build Modeling Options -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

>  GBM options (datatype: binary , package: gbm , function: gbm )...
>  MAXENT options (datatype: binary , package: MAXENT , function: MAXENT )...

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Done -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= SP Modeling Summary -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

15 environmental variables ( BPI9 gebco2023PJ_clip o2_mean_2000PJ oa_co3_TRI_MPI20002014_co3satarag_Can20002014_IDW3DPJ_clip1 ph_mean_2000PJ phyc_mean_2000PJ si_mean_2000PJ slope so_mean_2000PJ swd_mean_2000PJ sws_mean_2000PJ thetao_mean_2000PJ TPI wld01_grz_idw3d_ProjminPJ_clip1 wld01_rck_idw3d_Projmin_PJ_clip1 ) Number of evaluation repetitions : 11 Models selected : GBM MAXENT

Total number of model runs: 22

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Error in summary.connection(connection) : invalid connection**

HeleneBlt commented 2 days ago

Hi !

This is a commun problem with ENMeval and MAXENT. It opens some clusters and the closure is not always perfect on Windows.

I will advise you to try with biomod2 version 4.2-6-2 first. If you still encounter the same error, you can try to run:

env <- foreach:::.foreachGlobals
rm(list=ls(name=env), pos=env)

between your tuning and your modeling.

In the same time, the argument bm.options is obsolete. Your code will be :

myBiomodModelOut <- BIOMOD_Modeling(
  bm.format = myBiomodData,
  models = c('GBM', 'MAXENT'),
  CV.strategy = 'kfold',
  CV.nb.rep = 1,
  CV.k = 10, 
  CV.perc = 0.8,
  var.import = 3,
  metric.eval = c('TSS','ROC', 'KAPPA'),
  OPT.strategy = "user.defined",
  OPT.user.val = list(MAXENT.binary.MAXENT.MAXENT = tuning.result.maxent,
                      GBM.binary.gbm.gbm = tuning.result.gbm)
)

Don't hesitate if you still have some questions, Hélène

tongruiju commented 1 day ago

Hi Hélène,

I have updated my biomod2 to version 4.2-6-2. However, I encountered the following error. Could you provide any references or resources that I can use to update my old code to version 4.2-6-2? Best, Ruiju

**> tuning.result.gbm <- bm_Tuning(model = "GBM",

HeleneBlt commented 1 day ago

Hello Ruiju,

Have you run all the beginning of your code? There is no big difference about options between version 4.2-5-2 and version 4.2-6-2. However, it seems that biomod2 doesn't find bm.options. I will advise to clean and restart properly 😄

Thanks, Hélène