1717# # nlm() testing ---- partly same as in ../demo/nlm.R
1818# # NB: Strict regression tests -- output not "looked at"
1919library(stats )
20+ str <- utils :: str
2021
2122# # "truly 64 bit platform"
2223# # {have seen "x86-64" (instead of "x86_64") on Windows 2008 server}
@@ -53,7 +54,7 @@ nlm3 <- function(x0, ...) {
5354 nl.fgh = nlm(fgh , x0 , ... ))
5455}
5556
56- utils :: str(l3.0 <- nlm3(x0 = c(- 1.2 , 1 )))
57+ str(l3.0 <- nlm3(x0 = c(- 1.2 , 1 )))
5758
5859chkNlm <- function (nlL , estimate , tols , codes.wanted = 1 : 2 )
5960{
@@ -65,16 +66,17 @@ chkNlm <- function(nlL, estimate, tols, codes.wanted = 1:2)
6566 p <- length(estimate )
6667 n <- length(nlL )
6768 tols <- lapply(tols , rep_len , length.out = n )
68- cat(" delta.estim.:\n " )
69- print(d.est <- abs(vapply(nlL , `[[` , estimate , " estimate" ) - estimate ))
70- stopifnot(
71- vapply(nlL , `[[` , pi , " minimum" ) < = tols $ min ,
72- # #----
73- d.est < = rep(tols $ est , each = p ),
74- # #----
75- abs(vapply(nlL , `[[` , c(0 ,0 ), " gradient" )) < = rep(tols $ grad , each = p ),
76- # #----
77- vapply(nlL , `[[` , 0L , " code" ) %in% codes.wanted )
69+ myPrt <- function (x , digits = 3 , ... ) print(x , digits = digits , ... )
70+ cat(" delta(estim.) :\n " ); myPrt(d.est <- abs(vapply(nlL , `[[` , estimate , " estimate" ) - estimate ))
71+ cat(' return "code"s:\n ' ); myPrt(codes <- vapply(nlL , `[[` , 0L , " code" ))
72+ cat(' "minimum"s:\n ' ); myPrt(mins <- vapply(nlL , `[[` , .5 , " minimum" ))
73+ cat(' |"gradient"|s:\n ' ); myPrt(grads <- abs(vapply(nlL , `[[` , c(0 ,0 ), " gradient" )))
74+ stopifnot(mins < = tols $ min
75+ , d.est < = rep(tols $ est , each = p )
76+ , grads < = rep(tols $ grad , each = p )
77+ # #----
78+ , codes %in% codes.wanted
79+ )
7880}
7981
8082chkNlm(l3.0 , estimate = c(1 ,1 ),
@@ -84,12 +86,11 @@ chkNlm(l3.0, estimate = c(1,1),
8486 grad = c(1e-6 , 9e-9 , 7e-7 )))
8587
8688
87-
8889# # nl.fgh, the one with the Hessian had failed in R <= 3.4.0
8990# # ------- and still is less accurate here than the gradient-only version
9091
9192# # all converge here, too, fgh now being best
92- utils :: str(l3.10 <- nlm3(x0 = c(- 10 , 10 ), ndigit = 14 , gradtol = 1e-8 ))
93+ str(l3.10 <- nlm3(x0 = c(- 10 , 10 ), ndigit = 14 , gradtol = 1e-8 ))
9394
9495# # Tolerances loosened for 32-bit Linux and 64-bit Ubuntu 22.04.1 LTS :
9596chkNlm(l3.10 , estimate = c(1 ,1 ), # lower tolerances now, notably for fgh:
@@ -100,7 +101,7 @@ chkNlm(l3.10, estimate = c(1,1), # lower tolerances now, notably for fgh:
100101 codes.wanted = if (Lb64 ) 1 : 2 else 1 : 3 )
101102
102103# # all 3 fail to converge here
103- utils :: str(l3.1c <- nlm3(x0 = c(- 100 , 100 ), iterlim = 1000 ))
104+ str(l3.1c <- nlm3(x0 = c(- 100 , 100 ), iterlim = 1000 ))
104105# # i.e., all convergence codes > 1:
105106sapply(l3.1c , `[[` , " code" )
106107# # nl.f nl.fg nl.fgh (seen on 32-bit and 64-bit)
0 commit comments