Re: [R] Optim with two constraints

From: Thomas Wood <twood_at_fortmasoncapital.com>
Date: Fri 21 Oct 2005 - 02:15:44 EST

   Alexis,
   WIKI:
   You create the box constraints with two inequality constraints for    each element. Suppose that you have five elements, and your upper    bound is .33, and your lower bound is 0. Then quadprog would require    constraints as:

   A[1,]=(1,0,0,0,0)    b=(0)
   A[2,]=(-1,0,0,0,0)   b=(-.33)
   A[3,]=(0,1,0,0,0)     b=(0)
   A[4,]=(0,-1,0,0,0)      b=(-.33)

   .....and so on.
   The syntax is not quite correct but you get the picture. Remember    that quadprog distinguishes between equality and inequality    constraints, and these must be inequality constraints. The trick to    the upper bound is to multiply the constraint by -1 (as indicated),    which effectively translates the constraint from a <= constraint into    the >= type of constraint required by quadprog.    Regards,
   Tom
   Alexis Diamond wrote:

   I have a follow-up from Jens's question and Professor Ripley's    response. Jens wants to do quadratic optimization with 2 constraints:

> > > # I need two constraints:
> > > # 1. each element in par needs to be between 0 and 1
> > > # 2. sum(par)=1, i.e. the elements in par need to sum to 1         

how does one set both constraints in quadprog, per Prof. Ripley's suggestion?

i know how to get quadprog to handle the second constraint, but not BOTH, since quadprog only takes as inputs the constraint matrix "A" and constraint vector "b"--
unlike in "ipop" (kernlab), there is no additional option for box constraints.

apologies if i am not seeing something obvious here.

thanks in advance,

alexis   

   --

   Tom Wood
   Fort Mason Capital
   456 Montgomery Street 22nd Floor
   San Francisco, CA 94104
   Direct: 415-249-3387
   Fax: 415-249-3389
   [1]twood@fortmasoncapital.com

References

  1. mailto:twood@fortmasoncapital.com
    R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Fri Oct 21 03:52:04 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 19:13:48 EST