Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080305/80536e8c/attachment.pl
box-constrained
7 messages · Gustave Lefou, Ravi Varadhan, Paul Smith
Hi, Let me make the following points in response to your questions: 1. Your call to optim() with "L-BFGS-B" as the method is correct. Just make sure that your function "f" is defined as negative log-likelihood, since optim is by default a minimizer. The other option is to define log-likelihood as usual, but set control=list(fnscale=-1). 2. You can add derivative (or gradient to be more precise) by defining that function and then using the "gr" argument in optim. Specifying exact gradient almost always improves the convergence of the iterative schemes, especially for ill-conditioned problems (flat region around the local minima). So, if it is not too much trouble, and you are confident of your differentiation skills, you should do that. However, in most cases the approximate finite-difference gradient used by optim() should be good enough. 3. Regardless of whether it is easy to compute the exact gradient or not, it is generally a bad idea to maximize the likelihood that involves the product of a large number of very small numbers. It is almost always better to maximize the log-likelihood. Since the objective function is additive rather than multiplicative, it has better numerical conditioning. Ravi. ---------------------------------------------------------------------------- ------- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvaradhan at jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html ---------------------------------------------------------------------------- -------- -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Gustave Lefou Sent: Wednesday, March 05, 2008 1:34 PM To: r-help at r-project.org Subject: [R] box-constrained Hello everybody, I have a question about box-constrained optimization. I've done some research and I found that optim could do that. Are there other ways in R ? Is the following correct if I have a function f of two parameters belonging for example to [0,1] and [0,Infinity] ? optim(par=param, fn=f, method="L-BFGS-B", lower=c(0,0), upper=c(1,Inf)) My other question is whether it is possible to add the derivatives of my function (like in nlm) and whether it is better to add them ? If there is no need to add the derivatives, then I guess I could wish to optimize the likelihood directly rather than to optimize the log-likelihood... Indeed one aspect of the log-likelihood is to make the derivatives tractable (in iid cases). Do you agree ? Thank you ! Gustave ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080306/2698528e/attachment.pl
3 days later
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080309/5fe5daae/attachment.pl
On Sun, Mar 9, 2008 at 9:10 PM, Gustave Lefou <gustave5000 at gmail.com> wrote:
I have another question. I have seen there is a function called "constrOptim" in R. Is it better than "optim", for example to optimize a function f of two parameters belonging to [0,1] and [0,Infinity] ? Do the methods supplied like Nelder-Mead are better than those of optim ?
Could you please give us a concrete example of what you are trying to optimize? Paul
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080310/4b63d97b/attachment.pl
On Mon, Mar 10, 2008 at 4:02 PM, Gustave Lefou <gustave5000 at gmail.com> wrote:
It is just a negative log-likelihood with two parameters belonging to [0,1] and [0,Inf]. constrOptim is valid for all linear inequality constraints. My constraints (box-constrained) are as simple as possible, but maybe the methods used by constrOptim are useful too. My question is whether constrOptim is useful for boundary problems, or if optim is sufficient for box-constrained optimization.
Gustave, It would be useful if you gave us a concrete function (with its functional form defined) as an example. Paul
2008/3/10, Paul Smith <phhs80 at gmail.com>:
On Sun, Mar 9, 2008 at 9:10 PM, Gustave Lefou <gustave5000 at gmail.com>
wrote:
I have another question. I have seen there is a function called "constrOptim" in R. Is it better than "optim", for example to optimize a function f of two parameters belonging to [0,1] and [0,Infinity] ? Do the methods supplied like Nelder-Mead are better than those of optim ?
Could you please give us a concrete example of what you are trying to
optimize?
Paul
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.