Keywords - Function groups - @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Library: nummath
See also: nmmulpen nmqpenalty nmcongrad nmBFGS

Quantlet: nmsimpen
Description: constrained optimization using simple penalty function

Usage: min = nmsimpen(fname,cname,x0{,fder,opt})
Input:
fname string, name of the function to minimize. The function should have just one parameter x, which is either a n x 1 vector, or a n x k matrix (for any k >= 1) containing x = (x1,x2,...,xk); xi (n x 1 vector; i=1..k) represent points at which the function should be evaluated. As a result, the function should return a scalar or 1 x k vector, respectively.
cname string, name of a function evaluating equality constraints or a list containing at least one of cname.eq and cname.neq, both strings containing names of functions evaluating equality and inequality constraints, respectively. The functions should have just one parameter x, which is either a n x 1 vector, or a n x k matrix (for any k >= 1) containing x = (x1,x2,...,xk); xi (n x 1 vector; i=1..k) represent points at which the constraints should be evaluated. As a result, the functions should return c x 1 vector (for c constraints), resp. c x k matrix in case of input matrix.
x0 n x 1 vector, the initial estimate of the minimum
fder optional string or scalar, reserved for future usage as follows: derivatives of fname; there are several possible formats: 1. string, name of the function for computing the gradient of func; its output is a n x 1 vector 2. empty string; in this case the gradient will be computed automatically using the quantlet nmgraddiff with a default step h; this possibility is used now for any input values of fder 3. scalar h; the gradient will be computed automatically using the quantlet nmgraddiff with the given step h
opt.xtol optional scalar, convergence tolerance for x; default is xtol = 1e-5
opt.ftol optional scalar, convergence tolerance of the function value; default is ftol = 1e-5
opt.maxiter optional scalar, maximal number of iterations; default is maxiter = 10
opt.method optional string, name of the routine for unconstrained minimization; default is method = "nmcongrad"
Output:
min.xmin n x 1 vector, minimum of fname (isolated to a fractional precision of tol)
min.fmin scalar, minimal function value f(xmin)
min.penalty list with elements cvaleq and cvalneq, scalars containing the maximal absolute value of the equality and inequality constraints evaluated at xmin
min.iter scalar, number of iterations performed

Note:

Example:
library("nummath")
; function definition
proc(p)=ftion(x)
  p = x[1,]^2 + x[1,].*x[2,] - 1
endp
; constraint definition
proc(c)=constr(x)
  c = x[1,] + x[2,]^2 - 2
endp
conmin = nmsimpen("ftion","constr",#(1,1))
conmin
; minimization of ftion under equality constraint constr
; starting from the initial point x =(1,1)

Result:
Contents of conmin.xmin
[1,]  -1.0137
[2,]    1.736

Contents of conmin.fmin
[1,]  -1.7322

Contents of conmin.penalty.cvaleq
[1,]  1.4574e-06

Contents of conmin.penalty.cvalneq
[1,]        0

Contents of conmin.iter
[1,]        5
Example:
library("nummath")
; function definition: x1^2 + x2^4
proc(p)=ftion(x)
  p = x[1,]^2 + x[2,]^4
endp
; equality constraints: x1^4 + x2^2 = 3
proc(cval) = ceq(x)
  cval = x[1,]^4 + x[2,]^2 - 3
endp
; inequality constraint: x1 + x2 >= 2
proc(cval) = cneq(x)
  cval = x[1,] + x[2,] - 2
endp
eq  = "ceq"
neq = "cneq"
conmin = nmsimpen("ftion",list(eq,neq),#(0,0))
conmin
; minimization with both equality and inequality
; constraints, starting at x1 = x2 = 0

Result:
Contents of conmin.xmin
[1,]   1.2494
[2,]  0.75062

Contents of conmin.fmin
[1,]   1.8784

Contents of conmin.penalty.cvaleq
[1,] -1.0463e-06

Contents of conmin.penalty.cvalneq
[1,]  8.6553e-07

Contents of conmin.iter
[1,]        6
Example:
library("nummath")
; function definition
proc(p)=ftion(x)
  p = x[1,]^2 + x[2,]^4
endp
; two inequality constraint:
; x1 + x2 >= 2 and x1 <= 1, i.e., -x1 + 1 >= 0
proc(cval) = cneq(x)
  cval =(x[1,] + x[2,] - 2) |(- x[1,] + 1)
endp
neq = "cneq"
conmin = nmsimpen("ftion",list(neq),#(0,0))
conmin

Result:
Contents of conmin.xmin
[1,]        1
[2,]        1

Contents of conmin.fmin
[1,]        2

Contents of conmin.penalty.cvaleq
[1,]        0

Contents of conmin.penalty.cvalneq
[1,]  5.0487e-08

Contents of conmin.iter
[1,]        7

Notice that conmin.penalty.cvalneq contains
the maximum of absolute values of inequality
constraints evaluated at xmin. You can check it
it by entering command cneq(conmin.xmin)
that produces the result

Contents of cval
[1,] -5.0487e-08
[2,]  2.5243e-08



Author: L. Cizkova, 20020430 license MD*Tech
(C) MD*TECH Method and Data Technologies, 05.02.2006