EVOLUTION-MANAGER
Edit File: constrOptim.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Linearly Constrained Optimization</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for constrOptim {stats}"><tr><td>constrOptim {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Linearly Constrained Optimization</h2> <h3>Description</h3> <p>Minimise a function subject to linear inequality constraints using an adaptive barrier algorithm. </p> <h3>Usage</h3> <pre> constrOptim(theta, f, grad, ui, ci, mu = 1e-04, control = list(), method = if(is.null(grad)) "Nelder-Mead" else "BFGS", outer.iterations = 100, outer.eps = 1e-05, ..., hessian = FALSE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>theta</code></td> <td> <p>numeric (vector) starting value (of length <i>p</i>): must be in the feasible region.</p> </td></tr> <tr valign="top"><td><code>f</code></td> <td> <p>function to minimise (see below).</p> </td></tr> <tr valign="top"><td><code>grad</code></td> <td> <p>gradient of <code>f</code> (a <code><a href="../../base/html/function.html">function</a></code> as well), or <code>NULL</code> (see below).</p> </td></tr> <tr valign="top"><td><code>ui</code></td> <td> <p>constraint matrix (<i>k x p</i>), see below.</p> </td></tr> <tr valign="top"><td><code>ci</code></td> <td> <p>constraint vector of length <i>k</i> (see below).</p> </td></tr> <tr valign="top"><td><code>mu</code></td> <td> <p>(Small) tuning parameter.</p> </td></tr> <tr valign="top"><td><code>control, method, hessian</code></td> <td> <p>passed to <code><a href="optim.html">optim</a></code>.</p> </td></tr> <tr valign="top"><td><code>outer.iterations</code></td> <td> <p>iterations of the barrier algorithm.</p> </td></tr> <tr valign="top"><td><code>outer.eps</code></td> <td> <p>non-negative number; the relative convergence tolerance of the barrier algorithm.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Other named arguments to be passed to <code>f</code> and <code>grad</code>: needs to be passed through <code><a href="optim.html">optim</a></code> so should not match its argument names.</p> </td></tr> </table> <h3>Details</h3> <p>The feasible region is defined by <code>ui %*% theta - ci >= 0</code>. The starting value must be in the interior of the feasible region, but the minimum may be on the boundary. </p> <p>A logarithmic barrier is added to enforce the constraints and then <code><a href="optim.html">optim</a></code> is called. The barrier function is chosen so that the objective function should decrease at each outer iteration. Minima in the interior of the feasible region are typically found quite quickly, but a substantial number of outer iterations may be needed for a minimum on the boundary. </p> <p>The tuning parameter <code>mu</code> multiplies the barrier term. Its precise value is often relatively unimportant. As <code>mu</code> increases the augmented objective function becomes closer to the original objective function but also less smooth near the boundary of the feasible region. </p> <p>Any <code>optim</code> method that permits infinite values for the objective function may be used (currently all but "L-BFGS-B"). </p> <p>The objective function <code>f</code> takes as first argument the vector of parameters over which minimisation is to take place. It should return a scalar result. Optional arguments <code>...</code> will be passed to <code>optim</code> and then (if not used by <code>optim</code>) to <code>f</code>. As with <code>optim</code>, the default is to minimise, but maximisation can be performed by setting <code>control$fnscale</code> to a negative value. </p> <p>The gradient function <code>grad</code> must be supplied except with <code>method = "Nelder-Mead"</code>. It should take arguments matching those of <code>f</code> and return a vector containing the gradient. </p> <h3>Value</h3> <p>As for <code><a href="optim.html">optim</a></code>, but with two extra components: <code>barrier.value</code> giving the value of the barrier function at the optimum and <code>outer.iterations</code> gives the number of outer iterations (calls to <code>optim</code>). The <code>counts</code> component contains the <em>sum</em> of all <code><a href="optim.html">optim</a>()$counts</code>. </p> <h3>References</h3> <p>K. Lange <em>Numerical Analysis for Statisticians.</em> Springer 2001, p185ff </p> <h3>See Also</h3> <p><code><a href="optim.html">optim</a></code>, especially <code>method = "L-BFGS-B"</code> which does box-constrained optimisation. </p> <h3>Examples</h3> <pre> ## from optim 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)) } optim(c(-1.2,1), fr, grr) #Box-constraint, optimum on the boundary constrOptim(c(-1.2,0.9), fr, grr, ui = rbind(c(-1,0), c(0,-1)), ci = c(-1,-1)) # x <= 0.9, y - x > 0.1 constrOptim(c(.5,0), fr, grr, ui = rbind(c(-1,0), c(1,-1)), ci = c(-0.9,0.1)) ## Solves linear and quadratic programming problems ## but needs a feasible starting value # # from example(solve.QP) in 'quadprog' # no derivative fQP <- function(b) {-sum(c(0,5,0)*b)+0.5*sum(b*b)} Amat <- matrix(c(-4,-3,0,2,1,0,0,-2,1), 3, 3) bvec <- c(-8, 2, 0) constrOptim(c(2,-1,-1), fQP, NULL, ui = t(Amat), ci = bvec) # derivative gQP <- function(b) {-c(0, 5, 0) + b} constrOptim(c(2,-1,-1), fQP, gQP, ui = t(Amat), ci = bvec) ## Now with maximisation instead of minimisation hQP <- function(b) {sum(c(0,5,0)*b)-0.5*sum(b*b)} constrOptim(c(2,-1,-1), hQP, NULL, ui = t(Amat), ci = bvec, control = list(fnscale = -1)) </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>