A function that attempts to extract a solution found for one of the multiple solvers used to obtain results of minimization or maximinzation using the opm() multi-solver wrapper.

opm2optimr(opmobj, rid)

Arguments

opmobj

the object returned by opm() from trying to solve an optimization problem with multiple solvers (NOT the summary object)

rid

The identifier of the solver for which the solution should be extracted. This may be a "row ID" in the form of an integer or else a character string for the corresponding solver.

Details

We do not extract the true "message" for a method.

Value

A list of the following items:

par

The best set of parameters found.

value

The value of fn corresponding to par.

counts

A two-element integer vector giving the number of calls to fn and gr respectively. This excludes those calls needed to compute the Hessian even though the opm() result will have these counts

convergence

An integer code. 0 indicates successful completion

message

A character string which for optim() or optimr() may give additional information returned by the optimizer, or NULL. Here will be "Result of conversion from opm() result"

Examples


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", "tnewt")
mychk <- opm(par=c(-1.2,1), fr, grr, method=mset)
#> Warning: kktchk: pHes not symmetric -- symmetrizing
#> 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
#> ncg   0.9999999    0.9999997    1.708733e-14    555    319      0    0 TRUE
#> nvm   1.0000000    1.0000000    1.232595e-32     59     39      0    2 TRUE
#> anms  1.0000000    1.0000000    1.238564e-21    243      0      0    0 TRUE
#> tnewt 1.0000000    1.0000000    1.767495e-24     76     75      0    0 TRUE
#>       kkt2 xtime
#> ncg   TRUE 0.007
#> nvm   TRUE 0.003
#> anms  TRUE 0.008
#> tnewt TRUE 0.003
cat("extract result for method 3\n")
#> extract result for method 3
print(opm2optimr(mychk, 3))
#> $par
#>      p1 p2
#> anms  1  1
#> 
#> $value
#>             value
#> anms 1.238564e-21
#> 
#> $counts
#>      fevals gevals
#> anms    243      0
#> 
#> $convergence
#>      convergence
#> anms           0
#> 
#> $message
#> [1] "Result of conversion from opm() result for method ID=3"
#> 
cat("Alternatively for method nvm\n")
#> Alternatively for method nvm
print(opm2optimr(mychk, "nvm"))
#> $par
#>     p1 p2
#> nvm  1  1
#> 
#> $value
#>            value
#> nvm 1.232595e-32
#> 
#> $counts
#>     fevals gevals
#> nvm     59     39
#> 
#> $convergence
#>     convergence
#> nvm           2
#> 
#> $message
#> [1] "Result of conversion from opm() result for method ID=nvm"
#> 
cat("Bad inputs check for character method \n")
#> Bad inputs check for character method 
print(try(opm2optimr(mychk, "nvv")))
#> Error in opm2optimr(mychk, "nvv") : invalid character rid=nvv
#> [1] "Error in opm2optimr(mychk, \"nvv\") : invalid character rid=nvv\n"
#> attr(,"class")
#> [1] "try-error"
#> attr(,"condition")
#> <simpleError in opm2optimr(mychk, "nvv"): invalid character rid=nvv>
cat("Bad inputs check for out of range integer")
#> Bad inputs check for out of range integer
print(try(opm2optimr(mychk, 6)))
#> Error in opm2optimr(mychk, 6) : invalid numeric rid=6
#> [1] "Error in opm2optimr(mychk, 6) : invalid numeric rid=6\n"
#> attr(,"class")
#> [1] "try-error"
#> attr(,"condition")
#> <simpleError in opm2optimr(mychk, 6): invalid numeric rid=6>