[Rd] nlminb with constraints failing on some platforms
Oliver Dechant
dech@nt @end|ng |rom d@|@c@
Fri Feb 1 21:40:58 CET 2019
Hello,
> sessionInfo()
R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 9 (stretch)
Matrix products: default
BLAS/LAPACK:
/opt/intel/compilers_and_libraries_2019.1.144/linux/mkl/lib/intel64_lin/libmkl_rt.so
locale:
[1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_CA.UTF-8 LC_COLLATE=en_CA.UTF-8
[5] LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=en_CA.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.5.2
> f <- function(x) sum( log(diff(x)^2+.01) + (x[1]-1)^2 )
> opt <- nlminb(rep(0, 10), f, lower=-1, upper=3)
> str(opt)
List of 6
$ par : num [1:10] 1 1 1 1 1 ...
$ objective : num -41.4
$ convergence: int 0
$ iterations : int 67
$ evaluations: Named int [1:2] 98 850
..- attr(*, "names")= chr [1:2] "function" "gradient"
$ message : chr "relative convergence (4)"
> xhat <- rep(1, 10)
> all.equal(opt$par, xhat, tol=0) # good: 5.53 e-7
[1] "Mean relative difference: 5.349781e-07"
> all.equal(opt$objective, f(xhat), tol=0) # good: 1.8 e-12
[1] "Mean relative difference: 3.812222e-12"
> abs( opt$objective - f(xhat) ) < 1e-4 ## Must be TRUE
[1] TRUE
On 2019-02-01 4:23 p.m., Rui Barradas wrote:
> Hello,
>
> R 3.5.2 on ubuntu 18.04. sessionInfo() at the end.
> Works with me, same results, cannot reproduce the error.
>
>
> f <- function(x) sum( log(diff(x)^2+.01) + (x[1]-1)^2 )
> opt <- nlminb(rep(0, 10), f, lower=-1, upper=3)
> str(opt)
>
> xhat <- rep(1, 10)
> all.equal(opt$par, xhat, tol=0) # good: 5.53 e-7
> #[1] "Mean relative difference: 5.534757e-07"
> all.equal(opt$objective, f(xhat), tol=0) # good: 1.8 e-12
> #[1] "Mean relative difference: 1.816536e-12"
> abs( opt$objective - f(xhat) ) < 1e-4 ## Must be TRUE
> #[1] TRUE
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> sessionInfo()
> R version 3.5.2 (2018-12-20)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Ubuntu 18.04.1 LTS
>
> Matrix products: default
> BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
>
> locale:
> [1] LC_CTYPE=pt_PT.UTF-8 LC_NUMERIC=C
> [3] LC_TIME=pt_PT.UTF-8 LC_COLLATE=pt_PT.UTF-8
> [5] LC_MONETARY=pt_PT.UTF-8 LC_MESSAGES=pt_PT.UTF-8
> [7] LC_PAPER=pt_PT.UTF-8 LC_NAME=C
> [9] LC_ADDRESS=C LC_TELEPHONE=C
> [11] LC_MEASUREMENT=pt_PT.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
>
> loaded via a namespace (and not attached):
> [1] Rcpp_1.0.0 rstudioapi_0.8 bindr_0.1.1 magrittr_1.5
> [5] tidyselect_0.2.5 munsell_0.5.0 colorspace_1.3-2 lattice_0.20-38
> [9] R6_2.3.0 rlang_0.3.0.1 stringr_1.3.1 plyr_1.8.4
> [13] dplyr_0.7.8 tools_3.5.2 grid_3.5.2 yaml_2.2.0
> [17] assertthat_0.2.0 tibble_1.4.2 crayon_1.3.4 bindrcpp_0.2.2
> [21] purrr_0.2.5 reshape2_1.4.3 glue_1.3.0 stringi_1.2.4
> [25] compiler_3.5.2 pillar_1.3.1 scales_1.0.0 lubridate_1.7.4
> [29] pkgconfig_2.0.2 zoo_1.8-4
>
>
>
>
> Às 09:00 de 01/02/2019, Martin Maechler escreveu:
>>>>>>> Kasper Kristensen via R-devel
>>>>>>> on Mon, 28 Jan 2019 08:56:39 +0000 writes:
>>
>> > I've noticed unstable behavior of nlminb on some Linux
>> > systems. The problem can be reproduced by compiling
>> > R-3.5.2 using gcc-8.2 and running the following snippet:
>>
>> > f <- function(x) sum( log(diff(x)^2+.01) + (x[1]-1)^2 )
>> > opt <- nlminb(rep(0, 10), f, lower=-1, upper=3)
>> > xhat <- rep(1, 10)
>> > abs( opt$objective - f(xhat) ) < 1e-4 ## Must be TRUE
>>
>> > The example works perfectly when removing the bounds. However,
>> when bounds are added the snippet returns 'FALSE'.
>>
>> > An older R version (3.4.4), compiled using the same gcc-8.2,
>> did not have the problem. Between the two versions R has changed the
>> flags to compile Fortran sources:
>>
>> > < SAFE_FFLAGS = -O2 -fomit-frame-pointer -ffloat-store
>> > ---
>> >> SAFE_FFLAGS = -O2 -fomit-frame-pointer -msse2 -mfpmath=sse
>>
>> > Reverting to the old SAFE_FFLAGS 'solves' the problem.
>>
>> >> sessionInfo()
>> > R version 3.5.2 (2018-12-20)
>> > Platform: x86_64-pc-linux-gnu (64-bit)
>> > Running under: Scientific Linux release 6.4 (Carbon)
>>
>> > Matrix products: default
>> > BLAS/LAPACK:
>> /zdata/groups/nfsopt/intel/2018update3/compilers_and_libraries_2018.3.222/linux/mkl/lib/intel64_lin/libmkl_gf_lp64.so
>>
>>
>> > locale:
>> > [1] C
>>
>> > attached base packages:
>> > [1] stats graphics grDevices utils datasets methods
>> base
>>
>> > loaded via a namespace (and not attached):
>> > [1] compiler_3.5.2
>>
>> So you us Intel's MKL library for BLAS/LAPACK ..
>>
>> I also use gcc 8.2 (on Fedora 28 Linux) and R's own BLAS/LAPACK
>> and don't see such problems:
>>
>> The code
>>
>> f <- function(x) sum( log(diff(x)^2+.01) + (x[1]-1)^2 )
>> opt <- nlminb(rep(0, 10), f, lower=-1, upper=3)
>> str(opt)
>> xhat <- rep(1, 10)
>> all.equal(opt$par, xhat, tol=0) # good: 5.53 e-7
>> all.equal(opt$objective, f(xhat), tol=0) # good: 1.8 e-12
>> abs( opt$objective - f(xhat) ) < 1e-4 ## Must be TRUE
>>
>> gives
>>
>>> f <- function(x) sum( log(diff(x)^2+.01) + (x[1]-1)^2 )
>>> opt <- nlminb(rep(0, 10), f, lower=-1, upper=3)
>>> str(opt)
>> List of 6
>> $ par : num [1:10] 1 1 1 1 1 ...
>> $ objective : num -41.4
>> $ convergence: int 0
>> $ iterations : int 66
>> $ evaluations: Named int [1:2] 96 830
>> ..- attr(*, "names")= chr [1:2] "function" "gradient"
>> $ message : chr "relative convergence (4)"
>>> xhat <- rep(1, 10)
>>> all.equal(opt$par, xhat, tol=0) # good: 5.53 e-7
>> [1] "Mean relative difference: 5.534757e-07"
>>> all.equal(opt$objective, f(xhat), tol=0) # good: 1.8 e-12
>> [1] "Mean relative difference: 1.816536e-12"
>>> abs( opt$objective - f(xhat) ) < 1e-4 ## Must be TRUE
>> [1] TRUE
>>>
>>
>> for me. Maybe others can quickly run the above 7 lines and report ?
>>
>> Maybe there's something else unusual with your Linux
>> distribution's libraries?
>>
>> I'm not an expert on these compiler flags; have you seen what
>> the R-admin manual
>> https://cran.r-project.org/doc/manuals/R-admin.html#Linux
>> says about them?
>>
>> Best,
>> Martin
>>
>> ______________________________________________
>> R-devel using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list