diff --git a/DESCRIPTION b/DESCRIPTION index 7f3840a..b613167 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: subplex Version: 1.5-6 -Date: 2018-09-21 +Date: 2018-09-22 Title: Unconstrained Optimization using the Subplex Algorithm Authors@R: c(person(given=c("Aaron","A."),family="King", role=c("aut","trl","cre"),email="kingaa@umich.edu"), @@ -10,4 +10,8 @@ Depends: R(>= 2.5.1) URL: https://github.com/kingaa/subplex/ BugReports: https://github.com/kingaa/subplex/issues/ Description: The subplex algorithm for unconstrained optimization, developed by Tom Rowan . - +Encoding: UTF-8 +RoxygenNote: 6.1.0 +Collate: + 'subplex-package.R' + 'subplex.R' diff --git a/Makefile b/Makefile index cf933d3..6e49c10 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ INSTALL = install PKG = $(shell perl -ne 'print $$1 if /Package:\s+((\w+[-\.]?)+)/;' DESCRIPTION) VERSION = $(shell perl -ne 'print $$1 if /Version:\s+((\d+[-\.]?)+)/;' DESCRIPTION) PKGVERS = $(PKG)_$(VERSION) -SOURCE=$(shell ls R/*R src/* man/*Rd data/* tests/*R) +SOURCE=$(shell ls R/*R src/* man/*Rd tests/*R) default: @echo $(PKGVERS) diff --git a/NAMESPACE b/NAMESPACE index 1d70130..c462ccc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,2 +1,4 @@ -useDynLib(subplex,.registration=TRUE) +# Generated by roxygen2: do not edit by hand + export(subplex) +useDynLib(subplex, .registration = TRUE) diff --git a/R/subplex-package.R b/R/subplex-package.R new file mode 100644 index 0000000..2dabe90 --- /dev/null +++ b/R/subplex-package.R @@ -0,0 +1,30 @@ +##' Subplex unconstrained optimization algorithm +##' +##' The \pkg{subplex} package implements Tom Rowan's subspace-searching simplex +##' algorithm for unconstrained minimization of a function. +##' +##' Subplex is a subspace-searching simplex method for the unconstrained +##' optimization of general multivariate functions. Like the Nelder-Mead simplex +##' method it generalizes, the subplex method is well suited for optimizing +##' noisy objective functions. The number of function evaluations required for +##' convergence typically increases only linearly with the problem size, so for +##' most applications the subplex method is much more efficient than the simplex +##' method. +##' +##' Subplex was written in FORTRAN by Tom Rowan (Oak Ridge National Laboratory). +##' The FORTRAN source code is maintained on the netlib repository (netlib.org). +##' +##' @name subplex-package +##' @docType package +##' @author Aaron A. King (kingaa at umich dot edu) +##' @seealso \code{\link{subplex}}, \code{\link{optim}} +##' @references T. Rowan, "Functional Stability Analysis of Numerical +##' Algorithms", Ph.D. thesis, Department of Computer Sciences, University of +##' Texas at Austin, 1990. +##' @keywords optimize +##' @useDynLib subplex, .registration = TRUE +##' +NULL + + + diff --git a/R/subplex.R b/R/subplex.R index 78557d7..ff7ee1f 100644 --- a/R/subplex.R +++ b/R/subplex.R @@ -1,10 +1,88 @@ +##' Minimization of a function by the subplex algorithm +##' +##' \code{subplex} minimizes a function. +##' +##' The convergence codes are as follows: \describe{ \item{-2}{invalid input} +##' \item{-1}{number of function evaluations needed exceeds \code{maxnfe}} +##' \item{0}{success: tolerance \code{tol} satisfied} \item{1}{limit of machine +##' precision reached} } +##' +##' For more details, see the source code. +##' +##' @name subplex +##' @rdname subplex +##' @include subplex-package.R +##' +##' @param par Initial guess of the parameters to be optimized over. +##' @param fn The function to be minimized. Its first argument must be the +##' vector of parameters to be optimized over. It should return a scalar +##' result. +##' @param control A list of control parameters, consisting of some or all of +##' the following: \describe{ \item{reltol}{ The relative optimization tolerance +##' for \code{par}. This must be a positive number. The default value is +##' \code{.Machine$double.eps}. } \item{maxit}{ Maximum number of function +##' evaluations to perform before giving up. The default value is \code{10000}. +##' } \item{parscale}{ The scale and initial stepsizes for the components of +##' \code{par}. This must either be a single scalar, in which case the same +##' scale is used for all parameters, or a vector of length equal to the length +##' of \code{par}. For \code{parscale} to be valid, it must not be too small +##' relative to \code{par}: if \code{par + parscale = par} in any component, +##' \code{parscale} is too small. The default value is \code{1}. } } +##' @param hessian If \code{hessian=TRUE}, the Hessian of the objective at the +##' estimated optimum will be numerically computed. +##' @param \dots Additional arguments to be passed to the function \code{fn}. +##' @return \code{subplex} returns a list containing the following: +##' \item{par}{Estimated parameters that minimize the function.} +##' \item{value}{Minimized value of the function.} \item{count}{Number of +##' function evaluations required.} \item{convergence}{Convergence code (see +##' Details).} \item{message}{ A character string giving a diagnostic message +##' from the optimizer, or 'NULL'. } \item{hessian}{Hessian matrix.} +##' @author Aaron A. King \email{kingaa@@umich.edu} +##' @seealso \code{\link{optim}} +##' @references T. Rowan, ``Functional Stability Analysis of Numerical +##' Algorithms'', Ph.D. thesis, Department of Computer Sciences, University of +##' Texas at Austin, 1990. +##' @keywords optimize +##' @examples +##' +##' rosen <- function (x) { ## Rosenbrock Banana function +##' x1 <- x[1] +##' x2 <- x[2] +##' 100*(x2-x1*x1)^2+(1-x1)^2 +##' } +##' subplex(par=c(11,-33),fn=rosen) +##' +##' rosen2 <- function (x) { +##' X <- matrix(x,ncol=2) +##' sum(apply(X,1,rosen)) +##' } +##' subplex(par=c(-33,11,14,9,0,12),fn=rosen2,control=list(maxit=30000)) +##' ## compare with optim: +##' optim(par=c(-33,11,14,9,0,12),fn=rosen2,control=list(maxit=30000)) +##' +##' ripple <- function (x) { +##' r <- sqrt(sum(x^2)) +##' 1-exp(-r^2)*cos(10*r)^2 +##' } +##' subplex(par=c(1),fn=ripple,hessian=TRUE) +##' subplex(par=c(0.1,3),fn=ripple,hessian=TRUE) +##' subplex(par=c(0.1,3,2),fn=ripple,hessian=TRUE) +##' +##' rosen <- function (x, g = 0, h = 0) { ## Rosenbrock Banana function (using names) +##' x1 <- x['a'] +##' x2 <- x['b']-h +##' 100*(x2-x1*x1)^2+(1-x1)^2+g +##' } +##' subplex(par=c(b=11,a=-33),fn=rosen,h=22,control=list(abstol=1e-9,parscale=5),hessian=TRUE) +##' +##' @export subplex subplex <- function (par, fn, control = list(), hessian = FALSE, ...) { -## set default control parameters + ## set default control parameters con <- list( - reltol = .Machine$double.eps, - maxit = 10000, - parscale = 1 - ) + reltol = .Machine$double.eps, + maxit = 10000, + parscale = 1 + ) namc <- names(control)[names(control)%in%names(con)] con[namc] <- control[namc] fn <- match.fun(fn) diff --git a/man/subplex-package.Rd b/man/subplex-package.Rd index 062a5a1..5bc0ee1 100644 --- a/man/subplex-package.Rd +++ b/man/subplex-package.Rd @@ -1,26 +1,34 @@ -\name{subplex-package} +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/subplex-package.R \docType{package} +\name{subplex-package} \alias{subplex-package} \title{Subplex unconstrained optimization algorithm} -\description{The `subplex' package implements Tom Rowan's - subspace-searching simplex algorithm for unconstrained minimization of - a function.} +\description{ +The \pkg{subplex} package implements Tom Rowan's subspace-searching simplex +algorithm for unconstrained minimization of a function. +} \details{ - Subplex is a subspace-searching simplex method for the unconstrained - optimization of general multivariate functions. Like the Nelder-Mead - simplex method it generalizes, the subplex method is well suited for - optimizing noisy objective functions. The number of function - evaluations required for convergence typically increases only linearly - with the problem size, so for most applications the subplex method is - much more efficient than the simplex method. +Subplex is a subspace-searching simplex method for the unconstrained +optimization of general multivariate functions. Like the Nelder-Mead simplex +method it generalizes, the subplex method is well suited for optimizing +noisy objective functions. The number of function evaluations required for +convergence typically increases only linearly with the problem size, so for +most applications the subplex method is much more efficient than the simplex +method. - Subplex was written in FORTRAN by Tom Rowan (Oak Ridge National - Laboratory). The FORTRAN source code is maintained on the netlib - repository (netlib.org). +Subplex was written in FORTRAN by Tom Rowan (Oak Ridge National Laboratory). +The FORTRAN source code is maintained on the netlib repository (netlib.org). +} +\references{ +T. Rowan, "Functional Stability Analysis of Numerical +Algorithms", Ph.D. thesis, Department of Computer Sciences, University of +Texas at Austin, 1990. +} +\seealso{ +\code{\link{subplex}}, \code{\link{optim}} +} +\author{ +Aaron A. King (kingaa at umich dot edu) } -\references{T. Rowan, "Functional Stability Analysis of Numerical - Algorithms", Ph.D. thesis, Department of Computer Sciences, University - of Texas at Austin, 1990.} -\author{Aaron A. King (kingaa at umich dot edu)} -\seealso{\code{\link{subplex}}, \code{\link{optim}}} \keyword{optimize} diff --git a/man/subplex.Rd b/man/subplex.Rd index 210182f..41eab47 100644 --- a/man/subplex.Rd +++ b/man/subplex.Rd @@ -1,81 +1,56 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/subplex.R \name{subplex} \alias{subplex} \title{Minimization of a function by the subplex algorithm} -\description{ - \code{subplex} minimizes a function. -} \usage{ -subplex(par, fn, control = list(), hessian = FALSE, \dots) +subplex(par, fn, control = list(), hessian = FALSE, ...) } \arguments{ - \item{par}{ - Initial guess of the parameters to be optimized over. - } - \item{fn}{ - The function to be minimized. - Its first argument must be the vector of parameters to be optimized over. - It should return a scalar result. - } - \item{control}{ - A list of control parameters, consisting of some or all of the following: - \describe{ - \item{reltol}{ - The relative optimization tolerance for \code{par}. - This must be a positive number. - The default value is \code{.Machine$double.eps}. - } - \item{maxit}{ - Maximum number of function evaluations to perform before giving up. - The default value is \code{10000}. - } - \item{parscale}{ - The scale and initial stepsizes for the components of \code{par}. - This must either be a single scalar, in which case the same scale is used for all parameters, or a vector of length equal to the length of \code{par}. - For \code{parscale} to be valid, it must not be too small relative to \code{par}: - if \code{par + parscale = par} in any component, \code{parscale} is too small. - The default value is \code{1}. - } - } - } - \item{hessian}{ - If \code{hessian=TRUE}, the Hessian of the objective at the estimated optimum will be numerically computed. - } - \item{\dots}{ - Additional arguments to be passed to the function \code{fn}. - } +\item{par}{Initial guess of the parameters to be optimized over.} + +\item{fn}{The function to be minimized. Its first argument must be the +vector of parameters to be optimized over. It should return a scalar +result.} + +\item{control}{A list of control parameters, consisting of some or all of +the following: \describe{ \item{reltol}{ The relative optimization tolerance +for \code{par}. This must be a positive number. The default value is +\code{.Machine$double.eps}. } \item{maxit}{ Maximum number of function +evaluations to perform before giving up. The default value is \code{10000}. +} \item{parscale}{ The scale and initial stepsizes for the components of +\code{par}. This must either be a single scalar, in which case the same +scale is used for all parameters, or a vector of length equal to the length +of \code{par}. For \code{parscale} to be valid, it must not be too small +relative to \code{par}: if \code{par + parscale = par} in any component, +\code{parscale} is too small. The default value is \code{1}. } }} + +\item{hessian}{If \code{hessian=TRUE}, the Hessian of the objective at the +estimated optimum will be numerically computed.} + +\item{\dots}{Additional arguments to be passed to the function \code{fn}.} } \value{ - \code{subplex} returns a list containing the following: - \item{par}{Estimated parameters that minimize the function.} - \item{value}{Minimized value of the function.} - \item{count}{Number of function evaluations required.} - \item{convergence}{Convergence code (see Details).} - \item{message}{ - A character string giving a diagnostic message from the optimizer, or 'NULL'. - } - \item{hessian}{Hessian matrix.} +\code{subplex} returns a list containing the following: +\item{par}{Estimated parameters that minimize the function.} +\item{value}{Minimized value of the function.} \item{count}{Number of +function evaluations required.} \item{convergence}{Convergence code (see +Details).} \item{message}{ A character string giving a diagnostic message +from the optimizer, or 'NULL'. } \item{hessian}{Hessian matrix.} +} +\description{ +\code{subplex} minimizes a function. } \details{ - The convergence codes are as follows: - \describe{ - \item{-2}{invalid input} - \item{-1}{number of function evaluations needed exceeds \code{maxnfe}} - \item{0}{success: tolerance \code{tol} satisfied} - \item{1}{limit of machine precision reached} - } +The convergence codes are as follows: \describe{ \item{-2}{invalid input} +\item{-1}{number of function evaluations needed exceeds \code{maxnfe}} +\item{0}{success: tolerance \code{tol} satisfied} \item{1}{limit of machine +precision reached} } - For more details, see the source code. -} -\author{Aaron A. King \email{kingaa@umich.edu}} -\references{ - T. Rowan, - ``Functional Stability Analysis of Numerical Algorithms'', - Ph.D. thesis, - Department of Computer Sciences, - University of Texas at Austin, - 1990. +For more details, see the source code. } \examples{ + rosen <- function (x) { ## Rosenbrock Banana function x1 <- x[1] x2 <- x[2] @@ -105,7 +80,17 @@ rosen <- function (x, g = 0, h = 0) { ## Rosenbrock Banana function (using nam 100*(x2-x1*x1)^2+(1-x1)^2+g } subplex(par=c(b=11,a=-33),fn=rosen,h=22,control=list(abstol=1e-9,parscale=5),hessian=TRUE) + +} +\references{ +T. Rowan, ``Functional Stability Analysis of Numerical +Algorithms'', Ph.D. thesis, Department of Computer Sciences, University of +Texas at Austin, 1990. +} +\seealso{ +\code{\link{optim}} +} +\author{ +Aaron A. King \email{kingaa@umich.edu} } -\seealso{\code{\link{optim}}} \keyword{optimize} - diff --git a/subplex.Rproj b/subplex.Rproj index 9833a70..5311070 100644 --- a/subplex.Rproj +++ b/subplex.Rproj @@ -17,4 +17,7 @@ StripTrailingWhitespace: Yes BuildType: Package PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source +PackageInstallArgs: --no-multiarch --with-keep.source --library=~/library +PackageBuildArgs: --force --no-manual --resave-data --compact-vignettes=both --md5 +PackageBuildBinaryArgs: --library=~/library +PackageRoxygenize: rd,collate,namespace