hzambran / hydroPSO

Model-Independent Particle Swarm Optimisation for Environmental Models
https://cran.r-project.org/package=hydroPSO
GNU General Public License v2.0
36 stars 18 forks source link

Errors running examples in hydroPSO 0.5-0 #18

Closed cneyens closed 3 years ago

cneyens commented 4 years ago

The hydroPSO function seems to be broken for hydroPSO 0.5-0 as installed from CRAN.

See example from hydroPSO docs:

library(hydroPSO)
#> (C) 2011-2020 M. Zambrano-Bigiarini and R. Rojas (GPL >=2 license)
#> Type 'citation('hydroPSO')' to see how to cite this package

# Number of dimensions of the optimisation problem (for all the examples)
D <- 5

# Boundaries of the search space (Rastrigin function)
lower <- rep(-5.12, D)
upper <- rep(5.12, D)

## Not run: 
# Setting the home directory of the user as working directory 
setwd("~")

################################ 
# Example 1. Basic use         #
################################ 

# Setting the seed (for reproducible results)         
set.seed(100)

# Basic use 1. Rastrigin function (non-linear and multi-modal with many local minima)
# Results are not saved to the hard disk, for faster execution ('write2disk=FALSE')
hydroPSO(fn=rastrigin, lower=lower, upper=upper, control=list(write2disk=FALSE) )
#> 
#> ================================================================================
#> [                                Initialising  ...                             ]
#> ================================================================================
#> 
#> [npart=40 ; maxit=1000 ; method=spso2011 ; topology=random ; boundary.wall=absorbing2011]
#> 
#> [ user-definitions in control: write2disk=FALSE ]
#> 
#> 
#> ================================================================================
#> [                                 Running  PSO ...                             ]
#> ================================================================================
#> 
#> Error in hydroPSO(fn = rastrigin, lower = lower, upper = upper, control = list(write2disk = FALSE)): object 'GoF' not found

Created on 2020-04-23 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 3.6.3 (2020-02-29) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate Dutch_Belgium.1252 #> ctype Dutch_Belgium.1252 #> tz Europe/Paris #> date 2020-04-23 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> acepack 1.4.1 2016-10-29 [1] CRAN (R 3.6.1) #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.1) #> automap 1.0-14 2013-08-29 [1] CRAN (R 3.6.1) #> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1) #> base64enc 0.1-3 2015-07-28 [1] CRAN (R 3.6.0) #> callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.3) #> checkmate 2.0.0 2020-02-06 [1] CRAN (R 3.6.3) #> class 7.3-15 2019-01-01 [2] CRAN (R 3.6.3) #> cli 2.0.2 2020-02-28 [1] CRAN (R 3.6.3) #> cluster 2.1.0 2019-06-19 [2] CRAN (R 3.6.3) #> colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.1) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.1) #> data.table 1.12.8 2019-12-09 [1] CRAN (R 3.6.3) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.1) #> devtools 2.2.2 2020-02-17 [1] CRAN (R 3.6.3) #> digest 0.6.25 2020-02-23 [1] CRAN (R 3.6.3) #> dplyr 0.8.5 2020-03-07 [1] CRAN (R 3.6.3) #> e1071 1.7-3 2019-11-26 [1] CRAN (R 3.6.3) #> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.1) #> fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.3) #> FNN 1.1.3 2019-02-15 [1] CRAN (R 3.6.1) #> foreign 0.8-75 2020-01-20 [2] CRAN (R 3.6.3) #> Formula 1.2-3 2018-05-03 [1] CRAN (R 3.6.0) #> fs 1.3.2 2020-03-05 [1] CRAN (R 3.6.3) #> ggplot2 3.3.0 2020-03-05 [1] CRAN (R 3.6.3) #> glue 1.3.2 2020-03-12 [1] CRAN (R 3.6.3) #> gridExtra 2.3 2017-09-09 [1] CRAN (R 3.6.1) #> gstat 2.0-4 2020-01-21 [1] CRAN (R 3.6.3) #> gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.1) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.1) #> Hmisc 4.3-1 2020-02-07 [1] CRAN (R 3.6.3) #> htmlTable 1.13.3 2019-12-04 [1] CRAN (R 3.6.3) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1) #> htmlwidgets 1.5.1 2019-10-08 [1] CRAN (R 3.6.1) #> hydroGOF 0.4-0 2020-03-12 [1] CRAN (R 3.6.3) #> hydroPSO * 0.5-0 2020-03-18 [1] CRAN (R 3.6.3) #> hydroTSM 0.6-0 2020-03-11 [1] CRAN (R 3.6.3) #> intervals 0.15.1 2015-08-27 [1] CRAN (R 3.6.0) #> jpeg 0.1-8.1 2019-10-24 [1] CRAN (R 3.6.1) #> knitr 1.28 2020-02-06 [1] CRAN (R 3.6.3) #> lattice 0.20-38 2018-11-04 [2] CRAN (R 3.6.3) #> latticeExtra 0.6-29 2019-12-19 [1] CRAN (R 3.6.3) #> lhs 1.0.1 2019-02-03 [1] CRAN (R 3.6.1) #> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 3.6.3) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.1) #> maptools 0.9-9 2019-12-01 [1] CRAN (R 3.6.3) #> Matrix 1.2-18 2019-11-27 [2] CRAN (R 3.6.3) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.1) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.1) #> nnet 7.3-12 2016-02-02 [2] CRAN (R 3.6.3) #> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.3) #> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1) #> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.1) #> plyr 1.8.6 2020-03-03 [1] CRAN (R 3.6.3) #> png 0.1-7 2013-12-03 [1] CRAN (R 3.6.0) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.3) #> processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.3) #> ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.3) #> purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.1) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.3) #> RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.6.0) #> Rcpp 1.0.4 2020-03-17 [1] CRAN (R 3.6.3) #> remotes 2.1.1 2020-02-15 [1] CRAN (R 3.6.3) #> reshape 0.8.8 2018-10-23 [1] CRAN (R 3.6.1) #> rlang 0.4.5 2020-03-01 [1] CRAN (R 3.6.3) #> rmarkdown 1.16 2019-10-01 [1] CRAN (R 3.6.1) #> rpart 4.1-15 2019-04-12 [2] CRAN (R 3.6.3) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.1) #> rstudioapi 0.11 2020-02-07 [1] CRAN (R 3.6.3) #> scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.3) #> scatterplot3d 0.3-41 2018-03-14 [1] CRAN (R 3.6.0) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.1) #> sm 2.2-5.6 2018-09-27 [1] CRAN (R 3.6.1) #> sp 1.4-1 2020-02-28 [1] CRAN (R 3.6.3) #> spacetime 1.2-3 2020-01-21 [1] CRAN (R 3.6.3) #> stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.1) #> survival 3.1-8 2019-12-03 [2] CRAN (R 3.6.3) #> testthat 2.3.2 2020-03-02 [1] CRAN (R 3.6.3) #> tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.1) #> tidyselect 1.0.0 2020-01-27 [1] CRAN (R 3.6.3) #> usethis 1.5.1 2019-07-04 [1] CRAN (R 3.6.1) #> vioplot 0.3.4 2019-11-29 [1] CRAN (R 3.6.3) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.1) #> xfun 0.12 2020-01-13 [1] CRAN (R 3.6.3) #> xts 0.12-0 2020-01-19 [1] CRAN (R 3.6.3) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.6.2) #> zoo 1.8-7 2020-01-10 [1] CRAN (R 3.6.3) #> #> [1] C:/Users/casne/Documents/R/library_cas #> [2] C:/Users/casne/Documents/R/R-3.6.3/library ```

When reinstalling 0.4-1 this example does work:

library(hydroPSO)
#> (C) 2011-2018 M. Zambrano-Bigiarini and R. Rojas (GPL >=2 license)
#> Type 'citation('hydroPSO')' to see how to cite this package

# Number of dimensions of the optimisation problem (for all the examples)
D <- 5

# Boundaries of the search space (Rastrigin function)
lower <- rep(-5.12, D)
upper <- rep(5.12, D)

## Not run: 
# Setting the home directory of the user as working directory 
setwd("~")

################################ 
# Example 1. Basic use         #
################################ 

# Setting the seed (for reproducible results)         
set.seed(100)

# Basic use 1. Rastrigin function (non-linear and multi-modal with many local minima)
# Results are not saved to the hard disk, for faster execution ('write2disk=FALSE')
hydroPSO(fn=rastrigin, lower=lower, upper=upper, control=list(write2disk=FALSE) )
#> 
#> ================================================================================
#> [                                Initialising  ...                             ]
#> ================================================================================
#> 
#> [npart=40 ; maxit=1000 ; method=spso2011 ; topology=random ; boundary.wall=absorbing2011]
#> 
#> [ user-definitions in control: write2disk=FALSE ]
#> 
#> 
#> ================================================================================
#> [                                 Running  PSO ...                             ]
#> ================================================================================
#> 
#> iter: 100  Gbest: 2.992E+00  Gbest_rate:  0.08%  Iter_best_fit: 2.992E+00  nSwarm_Radius: 2.96E-02  |g-mean(p)|/mean(p): 69.36%
#>                                     |
#> ================================================================================
#> [                          Creating the R output ...                           ]
#> ================================================================================
#> $par
#>       Param1       Param2       Param3       Param4       Param5 
#> 4.382399e-05 9.947626e-01 9.950853e-01 9.948407e-01 5.619973e-05 
#> 
#> $value
#> [1] 2.984892
#> 
#> $best.particle
#> [1] 5
#> 
#> $counts
#> function.calls     iterations    regroupings 
#>           5920            148              0 
#> 
#> $convergence
#> [1] 1
#> 
#> $message
#> [1] "Converged ('reltol' criterion)"

Created on 2020-04-23 by the reprex package (v0.3.0)

hzambran commented 4 years ago

Thank you very much for reporting this problem. It has just been fixed.

The new version will be submitted to CRAN today. Meanwhile, you can install the fixed version with:

library(devtools) install_github("hzambran/hydroPSO")

Kind regards,

hzambran commented 4 years ago

The new hydroPSO version (0.5-1) is on CRAN now: https://cran.r-project.org/package=hydroPSO