Dear R-help,
I am new to optim function and need some help with optimization.
Problem description: I am trying to optimize a weights vector
such that it produce maximum value for a function maxVal. The
optimization is subjected to constraint. The constraints are a) Min
weight should be greater than or equal to Zero. b) Max weight should
be less than or equal to 1 c) Sum of the weights should be equal to 1.
Now after googling around a bit & trying my hands at RSiteSearch , I
found that I can use optim with L-BFGS-B method and could possible use
lower bound and upper bound for constraint, however I am clueless as
to how I can impose the sum(wgts) = 1 condition. In excel solver, this
problem is extremely simple since it's just a matter of setting an
additional constraint of setting the summation cell to 1.
Your kind help is greatly appreciated.
Best Regards
Manoj
Hi Manoj, AFAIK there is no way in R to optimize functions under general linear equality constraints (for inequality constraints there is constrOptim). In your case you could reparametrize such that you estimate weights w(1) ... w(n-1) and simply compute w(n) from those. Even so, it would be great to have a routine that does optimization under general linear constraints. Maybe someone out there could port the OPT++ library to R ... OPT++ is an open source optimization library that does general linear and non-linear and bound-constraint optimization. hth, ingmar> From: Manoj <manojsw at gmail.com> > Reply-To: manojsw at gmail.com > Date: Wed, 21 Sep 2005 17:33:29 +0900 > To: r-help at stat.math.ethz.ch > Subject: [R] Help on optim > > Dear R-help, > I am new to optim function and need some help with optimization. > > Problem description: I am trying to optimize a weights vector > such that it produce maximum value for a function maxVal. The > optimization is subjected to constraint. The constraints are a) Min > weight should be greater than or equal to Zero. b) Max weight should > be less than or equal to 1 c) Sum of the weights should be equal to 1. > > Now after googling around a bit & trying my hands at RSiteSearch , I > found that I can use optim with L-BFGS-B method and could possible use > lower bound and upper bound for constraint, however I am clueless as > to how I can impose the sum(wgts) = 1 condition. In excel solver, this > problem is extremely simple since it's just a matter of setting an > additional constraint of setting the summation cell to 1. > > Your kind help is greatly appreciated. > > Best Regards > > Manoj > > ______________________________________________ > R-help at 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 >
you don't need L-BFGS-B in this case since you can easily
re-parameterize you problem, i.e., you can always write:
pi_i = exp(a_i) / sum(exp(a_i)), with e.g., a_1 = 0
and thus maximize with respect to a_i's.
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Manoj" <manojsw at gmail.com>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, September 21, 2005 10:33 AM
Subject: [R] Help on optim
> Dear R-help,
> I am new to optim function and need some help with
> optimization.
>
> Problem description: I am trying to optimize a weights vector
> such that it produce maximum value for a function maxVal. The
> optimization is subjected to constraint. The constraints are a) Min
> weight should be greater than or equal to Zero. b) Max weight should
> be less than or equal to 1 c) Sum of the weights should be equal to
> 1.
>
> Now after googling around a bit & trying my hands at RSiteSearch , I
> found that I can use optim with L-BFGS-B method and could possible
> use
> lower bound and upper bound for constraint, however I am clueless as
> to how I can impose the sum(wgts) = 1 condition. In excel solver,
> this
> problem is extremely simple since it's just a matter of setting an
> additional constraint of setting the summation cell to 1.
>
> Your kind help is greatly appreciated.
>
> Best Regards
>
> Manoj
>
> ______________________________________________
> R-help at 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
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm