[R] Optim with two constraints
Berwin A Turlach
berwin at maths.uwa.edu.au
Thu Oct 20 13:49:35 CEST 2005
>>>>> "AD" == Alexis Diamond <alexisjdiamond at gmail.com> writes:
AD> I have a follow-up from Jens's question and Professor Ripley's
AD> response.
AD> 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
AD> how does one set both constraints in quadprog, per
AD> Prof. Ripley's suggestion? i know how to get quadprog to
AD> handle the second constraint,
The first is actually not one constraint but 2*k constraints, where k
is the number of elements in "par". But there is quite some
redundancy in this set of equation. It suffices to constrain each
element to be bigger or equal to 0 and that they should sum to 1. If
these constraints are fulfilled, then each element must be less or
equal to one.
AD> but not BOTH, since quadprog only takes as inputs the
AD> constraint matrix "A" and constraint vector "b"--
So what stops you from coding the k constraints from 1.) in the form
that quadprog requires them? From memory, i.e. untested:
m <- length(par)
Amat <- cbind(rep(1,m), diag(m))
bvec <- c(1,rep(0,m))
meq <- 1
solve.QP(Dmat, dvec, Amat, bvec, meq)
AD> unlike in "ipop" (kernlab), there is no additional option for
AD> box constraints.
Well, the problems that I had (and still have) usually don't involve
box constraints, but I see that other people use them again and again.
So probably it would be a good idea to implement them... But, more
importantly, would be to implement Powell's modifications of the
Goldfarb-Idnani algorithm to make it numerically more robust... Oh,
yeah, and a warm start option from a feasible point would be nice
too.... Probably all in a future version which should be released
sometime before Xmas 20xx. :)
AD> apologies if i am not seeing something obvious here.
Apologies accepted. :)
Cheers,
Berwin
More information about the R-help
mailing list