Library: | nummath |
See also: | nmsimpen |
Quantlet: | nmqpenalty | |
Description: | auxiliary quantlet for constrained minimization using nmsimpen. Computes a penalized function value: P(x,delta) = f(x) + delta*sum((constr(x))^2) |
Usage: | pval = nmqpenalty(x) | |
Input: | ||
x | n x 1 vector, the point at which penalized function has to be evaluated | |
nmlagrangianfname | global variable, 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 a 1 x k vector, respectively. | |
nmlagrangiancname | global variable, string containing the name of a function evaluating equality constraints or a list containing at least one of nmlagrangiancname.eq and nmlagrangiancname.neq, both strings containing names of functions evaluating equality and inequality constraints, respectively. | |
nmlagrangiandelta | global variable, scalar, penalization factor | |
Output: | ||
pval | scalar, value of penalized function | |
nmlagrangianconstr | global variable, a list with elements nmlagrangianconstr.cvaleq and nmlagrangianconstr.cvalneq, containing values of penalized constraints, i.e., cvaleq = eq(x) and cvalneq = -min(0 | neq(x)) |
If nmlagrangiancname is a string, a problem with only equality constraints (evaluated by nmlagrangiancname) is considered.
Inequality constraints should be defined so that cneq(x) >= 0 in a feasible set.
library("nummath") proc(fval)=ftion(x) fval = x[1,]^2 + x[1,].*x[2,] - 1 endp proc(cval)=constr(x) cval = x[1,] + x[2,]^2 - 2 endp nmlagrangianfname = "ftion" nmlagrangiancname = "constr" nmlagrangiandelta = 10 putglobal("nmlagrangianfname") putglobal("nmlagrangiancname") putglobal("nmlagrangiandelta") nmqpenalty(#(0,0))
Contents of pval [1,] 39
library("nummath") proc(fval) = ftion(x) fval = x[1,]^2 + x[1,].*x[2,] - 1 endp ; equality constraint: x1 + x2^2 = 2 proc(cval) = ceq(x) cval = x[1,] + x[2,]^2 - 2 endp ; inequality constraint: x1 <= 0, i.e., -x1 >= 0 proc(cval) = cneq(x) cval = -x[1,] endp nmlagrangianfname = "ftion" eq = "ceq" neq = "cneq" nmlagrangiancname = list(eq,neq) nmlagrangiandelta = 10 putglobal("nmlagrangianfname") putglobal("nmlagrangiancname") putglobal("nmlagrangiandelta") nmqpenalty(#(2,1))
Contents of pval [1,] 55