taoR is an R package which lets you use the TAO library from R. TAO is a library of optimization algorithms. Among them is Pounders. Pounders can be a useful tool for economists who estimate structural models using indirect inference, because unlike commonly used algorithms such as Nelder-Mead, Pounders is tailored for minimizing a non-linear sum of squares objective function, and therefore may require fewer iterations to arrive at a local optimum than Nelder-Mead. For more details, see here and here.
Please note that this package is currently a work in progress.
TAO is part of PETSc. If you do not have PETSc installed on your system, then taoR will attempt to install PETSc for you. There are two different ways to install taoR.
PETSc will be compiled using the same set of compilers that R uses. Building the PETSc binaries will take several minutes.
source("http://jtilly.io/taoR/install_taoR.R")
install_taoR(compile_binaries = TRUE)
See here for detailed instructions on how to install PETSc.
source("http://jtilly.io/taoR/install_taoR.R")
install_taoR(PETSC_DIR = "/path/to/petsc", PETSC_ARCH = "...")
Note that taoR copies the PETSc binary into the R package directory. Installing the package this way may require manual adjustment of the flags in src/Makevars.in
before installation.
We minimize the objective function (x[1] - 3) ^ 2 + (x[2] + 1) ^ 2
with respect to x
. The syntax is similar to R's optim
function.
library("taoR")
# the objective function is (x[1] - 3) ^ 2 + (x[2] + 1) ^2
# with solution vector c(3, -1)
# use pounders
objfun = function(x) c((x[1] - 3), (x[2] + 1))
ret = tao(par = c(1, 2),
fn = objfun,
method = "pounders",
control = list("tao_pounders_gqt" = ""))
ret$x
# [1] 3 -1
ret$iterations
# [1] 7
# use Nelder-Mead
objfun = function(x) sum(c((x[1] - 3), (x[2] + 1))^2)
ret = tao(par = c(1, 2),
fn = objfun,
method = "nm",
control = list())
ret$x
# [1] 3.005468 -1.004479
ret$iterations
# [1] 20
The parameter method
can be set to one of the following optimizers.
nls
: Newton's method with line search for unconstrained minimizationntr
: Newton's method with trust region for unconstrained minimizationntl
: Newton's method with trust region, line search for unconstrained minimizationlmvm
: Limited memory variable metric method for unconstrained minimizationcg
: Nonlinear conjugate gradient method for unconstrained minimizationnm
: Nelder-Mead algorithm for derivate-free unconstrained minimizationtron
: Newton Trust Region method for bound constrained minimizationgpcg
: Newton Trust Region method for quadratic bound constrained minimizationblmvm
: Limited memory variable metric method for bound constrained minimizationpounders
: Derivative-free model-based algorithm for nonlinear least squares