R Under development (unstable) (2024-08-16 r87026 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 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. > library(minqa) > > ## maxfn <- function(x) 10 - crossprod(x - seq_along(x))^2 > minfn <- function(x) crossprod(x - seq_along(x))^2 - 10 > > x0 <- rep.int(pi, 4) > reschk <- function(res) { + # stopifnot(is.list(res), + # inherits(res, "minqa"), + # names(res) == c("par", "fval", "feval", "ierr", "msg"), + # is.numeric(res$par), + # all.equal(res$par, 1:4, tol = 2e-4), + # is.numeric(res$fval), + # all.equal(as.vector(res$fval), -10, check.attributes = FALSE, tol = 1e-4), + # is.integer(res$feval), + # res$feval > 0) + test<-c(is.list(res), + inherits(res, "minqa"), + isTRUE(all(names(res) == c("par", "fval", "feval", "ierr", "msg"))), + is.numeric(res$par), + isTRUE(all.equal(res$par, 1:4, tol = 2e-4)), + is.numeric(res$fval), + isTRUE(all.equal(as.vector(res$fval), -10, check.attributes = FALSE, tol = 1e-4)), + is.integer(res$feval), + res$feval > 0) + names(test)<-c("is.list", "inheritsOK", "namesOK", "is.numeric-par", + "paramsOK","is.numeric-fn","fnOK","is.integer-fval", + "feval>0") + idx<-which(! test) + msg<-paste("reschk failed",names(test)[idx],sep=', ') + if ( ! all(test)) warning(msg) + } > # NOTE: we do not check ierr or msg here. JN 20100810 > sessionInfo() R Under development (unstable) (2024-08-16 r87026 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] minqa_1.2.8 loaded via a namespace (and not attached): [1] compiler_4.5.0 Rcpp_1.0.13 > reschk(ans.nd <- newuoa(x0, minfn, control = list(iprint = 2))) npt = 6 , n = 4 rhobeg = 0.6283185 , rhoend = 6.283185e-07 start par. = 3.141593 3.141593 3.141593 3.141593 fn = 34.17682 rho: 0.063 eval: 11 fn: -4.01972 par: 2.46553 2.48381 2.77080 3.89476 rho: 0.0063 eval: 52 fn: -9.87159 par: 1.41393 2.33022 3.22579 4.16424 rho: 0.00063 eval: 134 fn: -9.99965 par:0.957686 2.07714 3.08847 4.05495 rho: 6.3e-05 eval: 303 fn: -9.99999 par:0.945746 2.00915 2.99361 3.98800 rho: 6.3e-06 eval: 765 fn: -10.000 par:0.996645 1.99927 2.99658 3.99927 rho: 6.3e-07 eval: 1069 fn: -10.000 par: 1.00010 2.00062 2.99957 3.99978 At return eval: 1076 fn: -10.00000 par: 1.00010 2.00062 2.99957 3.99978 > ans.nd parameter estimates: 1.0000977777008, 2.0006151514101, 2.99957051944661, 3.99978232129179 objective: -9.99999999999962 number of function evaluations: 1076 > reschk(ans.ud <- uobyqa(x0, minfn, control = list(iprint = 2))) npt = 6 , n = 4 rhobeg = 0.6283185 , rhoend = 6.283185e-07 start par. = 3.141593 3.141593 3.141593 3.141593 fn = 34.17682 rho: 0.063 eval: 38 fn: -9.99248 par:-1.25915 0.890636 2.28247 4.84038 rho: 0.0063 eval: 73 fn: -10.000 par: 1.06352 1.98876 3.28135 3.98821 rho: 0.00063 eval: 91 fn: -10.000 par:0.991424 1.99623 3.00680 4.00414 rho: 6.3e-05 eval: 130 fn: -10.000 par: 1.00344 2.00075 2.99845 4.00288 rho: 6.3e-06 eval: 149 fn: -10.0000 par: 1.00010 1.99991 3.00004 3.99997 rho: 6.3e-07 eval: 167 fn: -10.0000 par: 1.00013 1.99998 3.00007 3.99993 At return eval: 185 fn: -10.000000 par: 1.00013 1.99998 3.00007 3.99993 > ans.ud parameter estimates: 1.00013258272029, 1.99997564506603, 3.0000690875344, 3.99992530015774 objective: -10 number of function evaluations: 185 > reschk(ans.bd <- bobyqa(x0, minfn, control = list(iprint = 2))) npt = 6 , n = 4 rhobeg = 0.6283185 , rhoend = 6.283185e-07 start par. = 3.141593 3.141593 3.141593 3.141593 fn = 34.17682 rho: 0.063 eval: 9 fn: -3.97899 par: 2.46646 2.48616 2.76457 3.89280 rho: 0.0063 eval: 29 fn: -8.92984 par: 1.87729 2.38076 2.76474 3.74600 rho: 0.00063 eval: 105 fn: -9.98701 par: 1.19666 2.18089 3.17408 3.88915 rho: 6.3e-05 eval: 220 fn: -9.99787 par: 1.03040 2.17388 3.06368 3.89530 rho: 6.3e-06 eval: 954 fn: -10.000 par: 1.00974 1.99725 3.01109 3.99097 rho: 6.3e-07 eval: 1241 fn: -10.000 par: 1.00458 1.99980 2.99883 3.99969 At return eval: 1467 fn: -10.00000 par: 1.00035 1.99999 2.99949 4.00010 > ans.bd parameter estimates: 1.00034513321313, 1.99999253185041, 2.99948597291991, 4.00010041869965 objective: -9.99999999999985 number of function evaluations: 1467 > > > proc.time() user system elapsed 0.23 0.04 0.26