optimr2opm.RdA function that attempts to add a row to an opm() result matrix. opm() is a multi-method optimization wrapper.
optimr2opm(ans, opmmat)An object in the form of an opm() multiple solver result with either one
row if opmobj does not exist, or one new row at the bottom if it
does.
fr <- function(x) { ## Rosenbrock Banana function
x1 <- x[1]
x2 <- x[2]
100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
grr <- function(x) { ## Gradient of 'fr'
x1 <- x[1]
x2 <- x[2]
c(-400 * x1 * (x2 - x1 * x1) - 2 * (1 - x1),
200 * (x2 - x1 * x1))
}
mset <- c("ncg", "nvm", "anms")
x0<-c(-1.2,1)
mychk <- opm(par=x0, fr, grr, method=mset)
#> Warning: kktchk: pHes not symmetric -- symmetrizing
#> Warning: kktchk: pHes not symmetric -- symmetrizing
#> Warning: kktchk: pHes not symmetric -- symmetrizing
cat("Summary output from opm\n")
#> Summary output from opm
print(summary(mychk))
#> p1 s1 p2 s2 value fevals gevals hevals conv kkt1 kkt2
#> ncg 0.9999999 0.9999997 1.708733e-14 555 319 0 0 TRUE TRUE
#> nvm 1.0000000 1.0000000 1.232595e-32 59 39 0 2 TRUE TRUE
#> anms 1.0000000 1.0000000 1.238564e-21 243 0 0 0 TRUE TRUE
#> xtime
#> ncg 0.005
#> nvm 0.002
#> anms 0.006
myans<-optimr(x0, fr, grr, method="tnewt")
cat("Add the solution from method 'tnewt'\n")
#> Add the solution from method 'tnewt'
mychk2<-optimr2opm(myans, mychk)
print(summary(mychk2))
#> p1 s1 p2 s2 value fevals gevals hevals conv kkt1
#> ncg 0.9999999 0.9999997 1.708733e-14 555 319 0 0 1
#> nvm 1.0000000 1.0000000 1.232595e-32 59 39 0 2 1
#> anms 1.0000000 1.0000000 1.238564e-21 243 0 0 0 1
#> tnewt 1.0000000 1.0000000 1.767495e-24 76 75 0 0 NA
#> kkt2 xtime
#> ncg 1 0.005
#> nvm 1 0.002
#> anms 1 0.006
#> tnewt NA NA