opm2optimr function

Extract optim() solution for one method of opm() result

Extract optim() solution for one method of opm() result

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. UTF-8

opm2optimr(opmobj, rid)

Arguments

  • opmobj: the object returned by opm() from trying to solve an optimization problem with multiple solvers
  • 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.

Returns

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) cat("Summary output from opm\n") print(summary(mychk)) cat("extract result for method 3\n") print(opm2optimr(mychk, 3)) cat("Alternatively for method nvm\n") print(opm2optimr(mychk, "nvm")) cat("Bad inputs check for character method \n") print(try(opm2optimr(mychk, "nvv"))) cat("Bad inputs check for out of range integer") print(try(opm2optimr(mychk, 6)))
  • Maintainer: John C Nash
  • License: GPL-2
  • Last published: 2024-12-10