R Under development (unstable) (2023-10-23 r85401 ucrt) -- "Unsuffered Consequences" Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # rm(list=ls()) > ## author: John C. Nash > # fname<-paste(format(Sys.time(), "%Y%m%d%H%M"),"-btnvm.out",sep='') > # sink(fname, append=TRUE, split=TRUE) > require("optimx") Loading required package: optimx > # Following is used when starting from opx21 directory > # source("optimx/tests/simplefun.R") > # Following is for use in package testing > # Simple Test Function 1: > simfun.f = function(x) { + fun <- sum(x^2 ) + # print(c(x = x, fun = fun)) + fun + } > simfun.g = function(x) { + grad<-2.0*x + grad + } > simfun.h = function(x) { + n<-length(x) + t<-rep(2.0,n) + hess<-diag(t) + } > sessionInfo() R Under development (unstable) (2023-10-23 r85401 ucrt) Platform: x86_64-w64-mingw32/x64 Running under: Windows Server 2022 x64 (build 20348) Matrix products: default locale: [1] LC_COLLATE=C LC_CTYPE=German_Germany.utf8 [3] LC_MONETARY=C LC_NUMERIC=C [5] LC_TIME=C time zone: Europe/Berlin tzcode source: internal attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] optimx_2023-10.21 loaded via a namespace (and not attached): [1] compiler_4.4.0 nloptr_2.0.3 numDeriv_2016.8-1.1 [4] pracma_2.4.2 > ##################### > > # This test script illustrates the use of bounds in optimr() with the > # optimizers nvm and L-BFGS-B, as well as a Kuhn Karush Tucker check > # on the final parameters from the second optimization. > # Masks are tested at the very end for the two methods for which they are > # available. Note that they must be called via the opm() function. > > > n<-4 > lower<-rep(0,n) > upper<-lower # to get arrays set > bdmsk<-rep(1,n) > # bdmsk[(trunc(n/2)+1)]<-0 > for (i in 1:n) { + lower[i]<-1.0*(i-1)*(n-1)/n + upper[i]<-1.0*i*(n+1)/n + } > xx<-0.5*(lower+upper) > > cat("lower bounds:") lower bounds:> print(lower) [1] 0.00 0.75 1.50 2.25 > cat("start: ") start: > print(xx) [1] 0.625 1.625 2.625 3.625 > cat("upper bounds:") upper bounds:> print(upper) [1] 1.25 2.50 3.75 5.00 > > cat("nvm\n") # changed from Rvmmin 2023-10-22 nvm > > abtrvm <- optimr(xx, simfun.f, simfun.g, lower=lower, upper=upper, + method="nvm", control=list(trace=0)) > # Note: use lower=lower etc. because there is a missing hess= argument > proptimr(abtrvm) Result abtrvm ( nvm -> (no_name) ) calc. min. = 7.875 at 0 L 0.75 L 1.5 L 2.25 L After 8 fn evals, and 8 gr evals and 0 hessian evals Termination code is 2 : NA ------------------------------------------------- > > cat("Axial search") Axial search> axabtrvm <- axsearch(abtrvm$par, fn=simfun.f, fmin=abtrvm$value, lower, upper, bdmsk=NULL) > print(axabtrvm) $bestfn [1] 7.875 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "nvm" attr(,"ptype") [1] "C" $par [1] 0.00 0.75 1.50 2.25 attr(,"status") [1] "L" "L" "L" "L" $details par0 fback rep.fmin..npar. ffwd parstep tilt roc 1 0.00 NA 7.875 7.875000 3.666853e-07 90 NaN 2 0.75 NA 7.875 7.875682 4.545258e-04 90 NaN 3 1.50 NA 7.875 7.877727 9.086849e-04 90 NaN 4 2.25 NA 7.875 7.881135 1.362844e-03 90 NaN > > cat("Now force an early stop\n") Now force an early stop > abtrvm1 <- optimr(xx, simfun.f, simfun.g, lower=lower, upper=upper, method="nvm", + control=list(maxit=1, trace=0)) Warning message: In nvm(par = spar, fn = efn, gr = egr, bds = bdmsk, control = mcontrol) : Too many gradient evaluations > print(abtrvm1) $par [1] 0.625 1.625 2.625 3.625 attr(,"status") [1] " " " " " " " " $value [1] 8.884958 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "nvm" attr(,"ptype") [1] "C" $counts function gradient 2 2 $convergence [1] 1 $message [1] NA $scounts [1] 2 2 0 > cat("Axial search") Axial search> axabtrvm1 <- axsearch(abtrvm1$par, fn=simfun.f, fmin=abtrvm1$value, lower, upper, bdmsk=NULL) > print(axabtrvm1) $bestfn [1] 8.884958 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "nvm" attr(,"ptype") [1] "C" $par [1] 0.625 1.625 2.625 3.625 attr(,"status") [1] " " " " " " " " $details par0 fback rep.fmin..npar. ffwd parstep tilt roc 1 0.625 23.06203 8.884958 23.06297 0.0003788326 -51.34019 4.152308e-08 2 1.625 23.05930 8.884958 23.06570 0.0009843780 -72.89727 2.687203e-06 3 2.625 23.05416 8.884958 23.07085 0.0015899235 -79.21570 2.721735e-05 4 3.625 23.04659 8.884958 23.07842 0.0021954689 -82.14669 1.332738e-04 > > > cat("Maximization test\n") Maximization test > mabtrvm <- optimr(xx, simfun.f, simfun.g, lower=lower, upper=upper, method="nvm", + control=list(trace=1, maximize=TRUE)) admissible = TRUE maskadded = FALSE parchanged = FALSE Parameter scaling:[1] 1 1 1 1 nvm -- J C Nash 2009-2015 - an R implementation of Alg 21 Problem of size n= 4 Initial fn= -23.0625 ig= 1 gnorm= 9.604686 1 1 -23.0625 ig= 2 gnorm= 8.689381 2 2 -43.87634 No acceptable point Reset to gradient search 2 2 -43.87634 ig= 3 gnorm= 4.974424 3 3 -45.24872 No acceptable point Reset to gradient search 3 3 -45.24872 ig= 4 gnorm= 1.923077 4 4 -46.23706 No acceptable point Reset to gradient search 4 4 -46.23706 ig= 5 gnorm= 0 Seem to be done nvm admissible = TRUE maskadded = FALSE parchanged = FALSE At least one parameter is on a bound existing parameter status:[1] "?" "?" "?" "?" > # Note: use lower=lower etc. because there is a missing hess= argument > print(mabtrvm) $par [1] 1.25 2.50 3.75 5.00 attr(,"status") [1] "U" "U" "U" "U" $value [1] 46.875 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "nvm" attr(,"ptype") [1] "C" $counts function gradient 5 5 $convergence [1] 2 $message [1] NA $scounts [1] 5 5 0 > cat("Do NOT try axsearch() with maximize\n") Do NOT try axsearch() with maximize > cat("KKT condition check\n") KKT condition check > akktm <- kktchk(mabtrvm$par, simfun.f, simfun.g, hess=NULL, upper=upper, lower=lower, + maximize=TRUE, control=list(trace=0)) Warning message: In kktchk(mabtrvm$par, simfun.f, simfun.g, hess = NULL, upper = upper, : All parameters are constrained > print(akktm) $gmax [1] 0 $evratio [1] NA $kkt1 [1] TRUE $kkt2 [1] TRUE $hev [1] 0 0 0 0 $ngatend [1] 2.5 5.0 7.5 10.0 attr(,"status") [1] "U" "U" "U" "U" $nhatend [,1] [,2] [,3] [,4] [1,] -2 0 0 0 [2,] 0 -2 0 0 [3,] 0 0 -2 0 [4,] 0 0 0 -2 > > alb<-optimr(xx,simfun.f, simfun.g, lower=lower, upper=upper, method="L-BFGS-B", + control=list(trace=0)) > print(alb) $par [1] 0.00 0.75 1.50 2.25 attr(,"status") [1] "L" "L" "L" "L" $value [1] 7.875 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "L-BFGS-B" attr(,"ptype") [1] "C" $counts function gradient 2 2 $convergence [1] 0 $message [1] "CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL" $scounts [1] 2 2 0 > > cat("KKT condition check\n") KKT condition check > alkkt <- kktchk(alb$par, simfun.f, simfun.g, hess=NULL, upper=upper, lower=lower, maximize=FALSE, control=list(trace=0)) Warning message: In kktchk(alb$par, simfun.f, simfun.g, hess = NULL, upper = upper, : All parameters are constrained > print(alkkt) $gmax [1] 0 $evratio [1] NA $kkt1 [1] TRUE $kkt2 [1] TRUE $hev [1] 0 0 0 0 $ngatend [1] 0.0 1.5 3.0 4.5 attr(,"status") [1] "L" "L" "L" "L" $nhatend [,1] [,2] [,3] [,4] [1,] 2 0 0 0 [2,] 0 2 0 0 [3,] 0 0 2 0 [4,] 0 0 0 2 > > alhn<-optimr(xx, simfun.f, lower=lower, upper=upper, method="hjn", + control=list(trace=0)) > print(alhn) $par [1] 0.00 0.75 1.50 2.25 attr(,"status") [1] "L" "L" "L" "L" $value [1] 7.875 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "hjn" attr(,"ptype") [1] "C" $counts [1] 70 NA $convergence [1] 0 $message [1] "hjn success" $scounts [1] 70 0 0 > > #sink() > cat("All bounded methods attempt with opm\n") # ?? should give errors All bounded methods attempt with opm > allbds <- opm(xx, simfun.f, simfun.g, lower=lower, upper=upper, method="MOST", control=list(trace=0)) Non-bounds methods requested:[1] "Nelder-Mead" "nlm" "ucminf" "subplex" "mla" [6] "pracmanm" Warning messages: 1: In opm(xx, simfun.f, simfun.g, lower = lower, upper = upper, method = "MOST", : A method requested does not handle bounds 2: In opm(xx, simfun.f, simfun.g, lower = lower, upper = upper, method = "MOST", : 'snewtm' removed from 'method' -- no hess() 3: In minqa::bobyqa(par = spar, fn = efn, lower = slower, upper = supper, : All upper - lower must be >= 2*rhobeg. Changing rhobeg > print(summary(allbds, order=value)) p1 s1 p2 s2 p3 s3 p4 s4 value fevals gevals hevals conv nlminb 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 4 2 0 0 lbfgsb3c 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 3 3 0 0 Rtnmin 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 11 11 0 0 spg 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 36 3 0 0 bobyqa 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 30 0 0 0 ncg 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 9 8 0 0 Rcgmin 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 9 8 0 0 nvm 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 8 8 0 2 Rvmmin 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 8 8 0 2 slsqp 5.2180e-15 0.75 L 1.5 L 2.25 L 7.875 16 15 0 0 tnewt 0.0000e+00 L 0.75 L 1.5 L 2.25 L 7.875 7 6 0 0 nmkb 5.4088e-08 0.75 L 1.5 L 2.25 L 7.875 62 0 0 0 nlnm 0.0000e+00 L 0.75 L 1.5 2.25 L 7.875 1343 0 0 0 kkt1 kkt2 xtime nlminb FALSE TRUE 0.00 lbfgsb3c FALSE TRUE 0.06 Rtnmin FALSE TRUE 0.01 spg FALSE TRUE 0.00 bobyqa FALSE TRUE 0.02 ncg FALSE TRUE 0.00 Rcgmin FALSE TRUE 0.00 nvm FALSE TRUE 0.00 Rvmmin FALSE TRUE 0.00 slsqp FALSE TRUE 0.00 tnewt FALSE TRUE 0.00 nmkb FALSE TRUE 0.00 nlnm FALSE TRUE 0.02 > > cat("Now force a mask upper=lower for parameter 3 and see what happens\n") Now force a mask upper=lower for parameter 3 and see what happens > lower[3] <- upper[3] > xx[3] <- lower[3] # MUST reset parameter also > > > ncgbdm <- optimr(xx, simfun.f, simfun.g, lower=lower, upper=upper, method="ncg", + control=list(trace=1, watch=TRUE)) admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE parchanged = FALSE At least one parameter is on a bound Parameter scaling:[1] 1 1 1 1 Masks present ncg -- J C Nash 2023 - bounds constraint version of new CG an R implementation of Alg 22 with Yuan/Dai modification stepredn = 0.2 Initial function value= 30.234 Initial fn= 30.234 1 0 1 30.234 last decrease= NA 3 1 2 20.293 last decrease= 9.9416 Yuan/Dai cycle reset 3 2 1 20.293 last decrease= NA 5 3 2 19.771 last decrease= 0.5221 Yuan/Dai cycle reset 5 4 1 19.771 last decrease= NA 7 5 2 19.688 last decrease= 0.08321 Very small gradient -- gradsqr = 0 ncg seems to have converged admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE parchanged = FALSE At least one parameter is on a bound existing parameter status:[1] "?" "?" "?" "?" > proptimr(ncgbdm) Result ncgbdm ( ncg -> (no_name) ) calc. min. = 19.688 at 0 L 0.75 L 3.75 M 2.25 L After 7 fn evals, and 6 gr evals and 0 hessian evals Termination code is 0 : NA ------------------------------------------------- > > ## lbfmsk <- optim(xx, simfun.f, simfun.g, lower=lower, upper=upper, method="L-BFGS-B", > ## control=list(trace=1, watch=TRUE)) > ## proptimr(ncgbdm) > > allbdm <- try(opm(xx, simfun.f, simfun.g, lower=lower, upper=upper, method="MOST", + control=list(trace=2))) opm: wrapper to call optimr to run multiple optimizers Non-bounds methods requested:[1] "Nelder-Mead" "nlm" "ucminf" "subplex" "mla" [6] "pracmanm" Method: nlminb Initial parameters:[1] 0.625 1.625 3.750 3.625 admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound Parameter scaling:[1] 1 1 1 1 Masks present 0: 30.234375: 0.625000 1.62500 3.75000 3.62500 1: 19.687500: 0.00000 0.750000 3.75000 2.25000 2: 19.687500: 0.00000 0.750000 3.75000 2.25000 Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "?" "?" "?" "?" admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound existing parameter status:[1] "?" "?" "?" "?" Post processing for method nlminb Successful convergence! kktchk: kkttol= 0.001 kkt2tol= 1e-06 control$trace= 2 KKT condition testing Number of parameters = 4 fval = 19.688 Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" parchanged = FALSE existing parameter status:[1] "L" "L" "M" "L" Number of free parameters = 4 gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" projected gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" max abs projected gradient element = 7.5 test tol = 0.020688 KKT1 result = FALSE Hessian eigenvalues of constrained Hessian: [1] 2 2 2 2 KKT2 result = TRUE Save results from method nlminb $par [1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" $convergence [1] 0 $message [1] "both X-convergence and relative convergence (5)" $value [1] 19.688 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "nlminb" attr(,"ptype") [1] "C" $counts [1] 3 2 $scounts [1] 4 2 0 $gevals [1] 2 $fevals [1] 4 $hevals [1] 0 $kkt1 [1] FALSE $kkt2 [1] TRUE $xtimes user.self 0 Method: lbfgsb3c Initial parameters:[1] 0.625 1.625 3.750 3.625 admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound Parameter scaling:[1] 1 1 1 1 Timing stopped at: 0 0 0 Error in optimr(par, fn, gr, hess = hess, method = meth, lower = lower, : Method lbfgsb3c cannot handle masked (fixed) parameters In addition: Warning messages: 1: In opm(xx, simfun.f, simfun.g, lower = lower, upper = upper, method = "MOST", : A method requested does not handle bounds 2: In opm(xx, simfun.f, simfun.g, lower = lower, upper = upper, method = "MOST", : 'snewtm' removed from 'method' -- no hess() > print(summary(allbdm, order=value)) Length Class Mode 1 try-error character > > mmth <- ctrldefault(2)$maskmeth > allmsk <- try(opm(xx, simfun.f, simfun.g, lower=lower, upper=upper, method=mmth, + control=list(trace=2))) opm: wrapper to call optimr to run multiple optimizers Method: Rcgmin Initial parameters:[1] 0.625 1.625 3.750 3.625 admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound Parameter scaling:[1] 1 1 1 1 Masks present Rcgmin -- J C Nash 2009 - bounds constraint version of new CG an R implementation of Alg 22 with Yuan/Dai modification Initial function value= 30.234 Initial fn= 30.234 1 0 1 30.234 last decrease= NA Parameter 1 is free Parameter 2 is free Parameter 4 is free Gradsqr = 64.688 g1, g2 64.688 0 fmin= 30.234 Gradproj = -64.688 reset steplegth= 0.18966 accpoint = TRUE OKpoint = TRUE 3 1 2 20.293 last decrease= 9.9416 Parameter 1 is free Parameter 2 is free Gradsqr = 4.6712 g1, g2 -2.8546 57.162 fmin= 20.293 Yuan/Dai cycle reset End inner loop, cycle = 0 3 2 1 20.293 last decrease= NA Parameter 1 is free Parameter 2 is free Gradsqr = 4.6712 g1, g2 4.6712 0 fmin= 20.293 Gradproj = -4.6712 reset steplegth= 0.12821 accpoint = TRUE OKpoint = TRUE 5 3 2 19.771 last decrease= 0.5221 Parameter 1 is free Gradsqr = 0.33284 g1, g2 -0.11477 4.2236 fmin= 19.771 Yuan/Dai cycle reset End inner loop, cycle = 0 5 4 1 19.771 last decrease= NA Parameter 1 is free Gradsqr = 0.33284 g1, g2 0.33284 0 fmin= 19.771 Gradproj = -0.33284 reset steplegth= 0.19231 accpoint = TRUE OKpoint = TRUE 7 5 2 19.688 last decrease= 0.08321 freeing parameter 1 Gradsqr = 0 g1, g2 0 0.33284 fmin= 19.688 Very small gradient -- gradsqr = 0 End inner loop, cycle = 2 Rcgmin seems to have converged Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "?" "?" "?" "?" admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound existing parameter status:[1] "?" "?" "?" "?" Post processing for method Rcgmin Successful convergence! kktchk: kkttol= 0.001 kkt2tol= 1e-06 control$trace= 2 KKT condition testing Number of parameters = 4 fval = 19.688 Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" parchanged = FALSE existing parameter status:[1] "L" "L" "M" "L" Number of free parameters = 4 gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" projected gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" max abs projected gradient element = 7.5 test tol = 0.020688 KKT1 result = FALSE Hessian eigenvalues of constrained Hessian: [1] 2 2 2 2 KKT2 result = TRUE Save results from method Rcgmin $par [1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" $value [1] 19.688 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "Rcgmin" attr(,"ptype") [1] "C" $counts [1] 7 6 $convergence [1] 0 $message [1] NA $scounts [1] 7 6 0 $gevals [1] 6 $fevals [1] 7 $hevals [1] 0 $kkt1 [1] FALSE $kkt2 [1] TRUE $xtimes user.self 0 Method: nvm Initial parameters:[1] 0.625 1.625 3.750 3.625 admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound Parameter scaling:[1] 1 1 1 1 Masks present nvm -- J C Nash 2009-2015 - an R implementation of Alg 21 lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 par:[1] 0.625 1.625 3.750 3.625 Bounds: nolower = FALSE noupper = FALSE bounds = TRUE Problem of size n= 4 Initial fn= 30.234 ig= 1 gnorm= 10.997 Reset Inv. Hessian approx at ilast = 1 1 1 30.234 Gradproj = -64.688 reset steplength= 0.18966 Parameter 1 is free Parameter 2 is free ig= 2 gnorm= 2.1613 2 2 20.293 freeing parameter 4 Gradproj = -6.0239 reset steplength= 0 Unchanged in step redn No acceptable point Reset to gradient search Reset Inv. Hessian approx at ilast = 2 2 2 20.293 Gradproj = -4.6712 reset steplength= 0.12821 Parameter 1 is free ig= 3 gnorm= 0.57692 3 3 19.771 freeing parameter 2 freeing parameter 4 Gradproj = -0.36074 reset steplength= 0.46133 freeing parameter 1 Parameter 2 is free ig= 4 gnorm= 1.5306 4 4 19.711 freeing parameter 4 Gradproj = -0.23835 reset steplength= 0 Unchanged in step redn No acceptable point Reset to gradient search Reset Inv. Hessian approx at ilast = 4 4 4 19.711 Gradproj = -2.3429 reset steplength= 0.010012 freeing parameter 1 ig= 5 gnorm= 0 Small gradient norm Seem to be done nvm Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "?" "?" "?" "?" admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound existing parameter status:[1] "?" "?" "?" "?" Post processing for method nvm kktchk: kkttol= 0.001 kkt2tol= 1e-06 control$trace= 2 KKT condition testing Number of parameters = 4 fval = 19.688 Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" parchanged = FALSE existing parameter status:[1] "L" "L" "M" "L" Number of free parameters = 4 gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" projected gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" max abs projected gradient element = 7.5 test tol = 0.020688 KKT1 result = FALSE Hessian eigenvalues of constrained Hessian: [1] 2 2 2 2 KKT2 result = TRUE Save results from method nvm $par [1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" $value [1] 19.688 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "nvm" attr(,"ptype") [1] "C" $counts function gradient 5 5 $convergence [1] 2 $message [1] NA $scounts [1] 5 5 0 $gevals [1] 5 $fevals [1] 5 $hevals [1] 0 $kkt1 [1] FALSE $kkt2 [1] TRUE $xtimes user.self 0 Method: hjn Initial parameters:[1] 0.625 1.625 3.750 3.625 admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound Parameter scaling:[1] 1 1 1 1 Masks present hjn:control$have.bounds = TRUE optimr - hjn - msk:[1] 1 1 0 1 hjn:bdmsk:[1] 1 1 0 1 Exploratory move - stepsize = 1 p-start:[1] 0.625 1.625 3.750 3.625 axial search with stepsize = 1 fn value = 21.516 after 7 maxfeval = 10000 PM from:[1] 0.000 0.750 3.750 2.625 pbest:[1] 0.000 0.750 3.750 2.625 PM to:[1] 0.00 0.75 3.75 2.25 Exploratory move - stepsize = 1 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 1 fn value = 20.688 after 10 maxfeval = 10000 PM from:[1] 1.00 0.75 3.75 2.25 pbest:[1] 1.00 0.75 3.75 2.25 PM to:[1] 1.25 0.75 3.75 2.25 Exploratory move - stepsize = 1 p-start:[1] 1.25 0.75 3.75 2.25 axial search with stepsize = 1 fn value = 19.75 after 13 maxfeval = 10000 PM from:[1] 0.25 0.75 3.75 2.25 pbest:[1] 0.25 0.75 3.75 2.25 PM to:[1] 0.00 0.75 3.75 2.25 Exploratory move - stepsize = 1 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 1 fn value = 19.75 after 16 maxfeval = 10000 return to base at:[1] 0.25 0.75 3.75 2.25 Exploratory move - stepsize = 1 p-start:[1] 0.25 0.75 3.75 2.25 axial search with stepsize = 1 fn value = 19.688 after 20 maxfeval = 10000 PM from:[1] 0.00 0.75 3.75 2.25 pbest:[1] 0.00 0.75 3.75 2.25 PM to:[1] 0.00 0.75 3.75 2.25 Exploratory move - stepsize = 1 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 1 fn value = 19.688 after 23 maxfeval = 10000 Reducing step to 0.2 Exploratory move - stepsize = 0.2 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 0.2 fn value = 19.688 after 26 maxfeval = 10000 Reducing step to 0.04 Exploratory move - stepsize = 0.04 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 0.04 fn value = 19.688 after 29 maxfeval = 10000 Reducing step to 0.008 Exploratory move - stepsize = 0.008 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 0.008 fn value = 19.688 after 32 maxfeval = 10000 Reducing step to 0.0016 Exploratory move - stepsize = 0.0016 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 0.0016 fn value = 19.688 after 35 maxfeval = 10000 Reducing step to 0.00032 Exploratory move - stepsize = 0.00032 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 0.00032 fn value = 19.688 after 38 maxfeval = 10000 Reducing step to 6.4e-05 Exploratory move - stepsize = 6.4e-05 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 6.4e-05 fn value = 19.688 after 41 maxfeval = 10000 Reducing step to 1.28e-05 Exploratory move - stepsize = 1.28e-05 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 1.28e-05 fn value = 19.688 after 44 maxfeval = 10000 Reducing step to 2.56e-06 Exploratory move - stepsize = 2.56e-06 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 2.56e-06 fn value = 19.688 after 47 maxfeval = 10000 Reducing step to 5.12e-07 Exploratory move - stepsize = 5.12e-07 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 5.12e-07 fn value = 19.688 after 50 maxfeval = 10000 Reducing step to 1.024e-07 Exploratory move - stepsize = 1.024e-07 p-start:[1] 0.00 0.75 3.75 2.25 axial search with stepsize = 1.024e-07 fn value = 19.688 after 53 maxfeval = 10000 Reducing step to 2.048e-08 pbase = pbest Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "?" "?" "?" "?" admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound existing parameter status:[1] "?" "?" "?" "?" Post processing for method hjn Successful convergence! kktchk: kkttol= 0.001 kkt2tol= 1e-06 control$trace= 2 KKT condition testing Number of parameters = 4 fval = 19.688 Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" parchanged = FALSE existing parameter status:[1] "L" "L" "M" "L" Number of free parameters = 4 gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" projected gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" max abs projected gradient element = 7.5 test tol = 0.020688 KKT1 result = FALSE Hessian eigenvalues of constrained Hessian: [1] 2 2 2 2 KKT2 result = TRUE Save results from method hjn $par [1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" $value [1] 19.688 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "hjn" attr(,"ptype") [1] "C" $counts [1] 53 NA $convergence [1] 0 $message [1] "hjn success" $scounts [1] 53 0 0 $gevals [1] 0 $fevals [1] 53 $hevals [1] 0 $kkt1 [1] FALSE $kkt2 [1] TRUE $xtimes user.self 0.01 Method: ncg Initial parameters:[1] 0.625 1.625 3.750 3.625 admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound Parameter scaling:[1] 1 1 1 1 Masks present ncg -- J C Nash 2023 - bounds constraint version of new CG an R implementation of Alg 22 with Yuan/Dai modification stepredn = 0.2 Initial function value= 30.234 Initial fn= 30.234 1 0 1 30.234 last decrease= NA Parameter 1 is free Parameter 2 is free Parameter 4 is free Gradsqr = 64.688 g1, g2 64.688 0 fmin= 30.234 Gradproj = -64.688 reset steplegth= 0.18966 accpoint = TRUE OKpoint = TRUE 3 1 2 20.293 last decrease= 9.9416 Parameter 1 is free Parameter 2 is free Gradsqr = 4.6712 g1, g2 -2.8546 57.162 fmin= 20.293 Yuan/Dai cycle reset End inner loop, cycle = 0 3 2 1 20.293 last decrease= NA Parameter 1 is free Parameter 2 is free Gradsqr = 4.6712 g1, g2 4.6712 0 fmin= 20.293 Gradproj = -4.6712 reset steplegth= 0.12821 accpoint = TRUE OKpoint = TRUE 5 3 2 19.771 last decrease= 0.5221 Parameter 1 is free Gradsqr = 0.33284 g1, g2 -0.11477 4.2236 fmin= 19.771 Yuan/Dai cycle reset End inner loop, cycle = 0 5 4 1 19.771 last decrease= NA Parameter 1 is free Gradsqr = 0.33284 g1, g2 0.33284 0 fmin= 19.771 Gradproj = -0.33284 reset steplegth= 0.19231 accpoint = TRUE OKpoint = TRUE 7 5 2 19.688 last decrease= 0.08321 freeing parameter 1 Gradsqr = 0 g1, g2 0 0.33284 fmin= 19.688 Very small gradient -- gradsqr = 0 End inner loop, cycle = 2 ncg seems to have converged Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "?" "?" "?" "?" admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound existing parameter status:[1] "?" "?" "?" "?" Post processing for method ncg Successful convergence! kktchk: kkttol= 0.001 kkt2tol= 1e-06 control$trace= 2 KKT condition testing Number of parameters = 4 fval = 19.688 Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" parchanged = FALSE existing parameter status:[1] "L" "L" "M" "L" Number of free parameters = 4 gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" projected gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" max abs projected gradient element = 7.5 test tol = 0.020688 KKT1 result = FALSE Hessian eigenvalues of constrained Hessian: [1] 2 2 2 2 KKT2 result = TRUE Save results from method ncg $par [1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" $value [1] 19.688 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "ncg" attr(,"ptype") [1] "C" $counts [1] 7 6 $convergence [1] 0 $message [1] NA $scounts [1] 7 6 0 $gevals [1] 6 $fevals [1] 7 $hevals [1] 0 $kkt1 [1] FALSE $kkt2 [1] TRUE $xtimes user.self 0 Method: nlminb Initial parameters:[1] 0.625 1.625 3.750 3.625 admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound Parameter scaling:[1] 1 1 1 1 Masks present 0: 30.234375: 0.625000 1.62500 3.75000 3.62500 1: 19.687500: 0.00000 0.750000 3.75000 2.25000 2: 19.687500: 0.00000 0.750000 3.75000 2.25000 Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "?" "?" "?" "?" admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound existing parameter status:[1] "?" "?" "?" "?" Post processing for method nlminb Successful convergence! kktchk: kkttol= 0.001 kkt2tol= 1e-06 control$trace= 2 KKT condition testing Number of parameters = 4 fval = 19.688 Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" parchanged = FALSE existing parameter status:[1] "L" "L" "M" "L" Number of free parameters = 4 gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" projected gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" max abs projected gradient element = 7.5 test tol = 0.020688 KKT1 result = FALSE Hessian eigenvalues of constrained Hessian: [1] 2 2 2 2 KKT2 result = TRUE Save results from method nlminb $par [1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" $convergence [1] 0 $message [1] "both X-convergence and relative convergence (5)" $value [1] 19.688 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "nlminb" attr(,"ptype") [1] "C" $counts [1] 3 2 $scounts [1] 4 2 0 $gevals [1] 2 $fevals [1] 4 $hevals [1] 0 $kkt1 [1] FALSE $kkt2 [1] TRUE $xtimes user.self 0 Method: L-BFGS-B Initial parameters:[1] 0.625 1.625 3.750 3.625 admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound Parameter scaling:[1] 1 1 1 1 Masks present N = 4, M = 5 machine precision = 2.22045e-16 iterations 1 function evaluations 2 segments explored during Cauchy searches 4 BFGS updates skipped 0 active bounds at final generalized Cauchy point 4 norm of the final projected gradient 0 final function value 19.6875 final value 19.687500 converged Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "?" "?" "?" "?" admissible = TRUE Imposing mask as lower ~= upper for following parameters [1] 3 maskadded = TRUE lower:[1] 0.00 0.75 3.75 2.25 upper:[1] 1.25 2.50 3.75 5.00 parchanged = FALSE At least one parameter is on a bound existing parameter status:[1] "?" "?" "?" "?" Post processing for method L-BFGS-B Successful convergence! kktchk: kkttol= 0.001 kkt2tol= 1e-06 control$trace= 2 KKT condition testing Number of parameters = 4 fval = 19.688 Initial parameters:[1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" parchanged = FALSE existing parameter status:[1] "L" "L" "M" "L" Number of free parameters = 4 gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" projected gradient:[1] 0.0 1.5 7.5 4.5 attr(,"status") [1] "L" "L" "M" "L" max abs projected gradient element = 7.5 test tol = 0.020688 KKT1 result = FALSE Hessian eigenvalues of constrained Hessian: [1] 2 2 2 2 KKT2 result = TRUE Save results from method L-BFGS-B $par [1] 0.00 0.75 3.75 2.25 attr(,"status") [1] "L" "L" "M" "L" $value [1] 19.688 attr(,"fname") [1] "(no_name)" attr(,"method") [1] "L-BFGS-B" attr(,"ptype") [1] "C" $counts function gradient 2 2 $convergence [1] 0 $message [1] "CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL" $scounts [1] 2 2 0 $gevals [1] 2 $fevals [1] 2 $hevals [1] 0 $kkt1 [1] FALSE $kkt2 [1] TRUE $xtimes user.self 0 Warning messages: 1: In opm(xx, simfun.f, simfun.g, lower = lower, upper = upper, method = mmth, : 'snewtonm' removed from 'method' -- no hess() 2: In hjn(spar, efn, lower = slower, upper = supper, bdmsk = msk, control = mcontrol) : hjn: lower >= upper for some parameters -- set masks > print(summary(allmsk, order=value)) p1 s1 p2 s2 p3 s3 p4 s4 value fevals gevals hevals conv kkt1 Rcgmin 0 L 0.75 L 3.75 M 2.25 L 19.688 7 6 0 0 FALSE nvm 0 L 0.75 L 3.75 M 2.25 L 19.688 5 5 0 2 FALSE hjn 0 L 0.75 L 3.75 M 2.25 L 19.688 53 0 0 0 FALSE ncg 0 L 0.75 L 3.75 M 2.25 L 19.688 7 6 0 0 FALSE nlminb 0 L 0.75 L 3.75 M 2.25 L 19.688 4 2 0 0 FALSE L-BFGS-B 0 L 0.75 L 3.75 M 2.25 L 19.688 2 2 0 0 FALSE kkt2 xtime Rcgmin TRUE 0.00 nvm TRUE 0.00 hjn TRUE 0.01 ncg TRUE 0.00 nlminb TRUE 0.00 L-BFGS-B TRUE 0.00 > > # Check unsuitable method trap > try(optimr(xx, simfun.f, simfun.g, method="ucminf", lower=lower, upper=upper)) Error in optimr(xx, simfun.f, simfun.g, method = "ucminf", lower = lower, : Bounded problem with unsuitable method > > proc.time() user system elapsed 0.76 0.10 0.87