If A%*%theta>c, then log(c-A%*%theta) returns NA. if A%*%theta<c, log(A%*%theta-c) returns NA. Only when A%*%theta==c do you get a "number" from log(A%*%theta-c), and that's (-Inf).

However, for an equality constraint, I've had good luck by with an objective function that adds something like the following to my objective function:

constraintViolationPenalty*(A%*%theta-c)^2,

where "constraintViolationPenalty" is passed via "..." in a call to optim. If I want only (A%*%theta>=c), then I might write this as follows:

constraintViolationPenalty*(A%*%theta<c)*(A%*%theta-c)^2

This term is everywhere differentiable and is 0 when the constraint is satisfied.

I may first run optim with a modest value for constraintViolationPenalty then restart it with the output of the initial run as starting values and with a larger value for constraintViolationPenalty.

     hope this helps.  spencer graves

Ingmar Visser wrote:

On 8/9/04 4:52 PM, "Thomas Lumley" <[EMAIL PROTECTED]> wrote:



On Mon, 9 Aug 2004, Kahra Hannu wrote:



1) constrOptim does not work in this case because it only fits inequality
constraints, ie A%*%theta > = c


                         --- I was struggling with the same problem a
few weeks ago in the portfolio optimization context. You can impose
equality constraints by using inequality constraints >= and <=
simultaneously. See the example bellow.



Ick. You do not want to use constrOptim for equality constraints.
constrOptim is a log-barrier interior-point method, meaning that it adds
a multiple of log(A%*%theta-c) to the objective function. This is a really
bad idea as a way of faking equality constraints.

Use Lagrange multipliers and optim.



Is there a package that does all that for me? Or is there example code that does something similar?

ingmar

______________________________________________
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html



______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to