i'm trying to use the BB package to minimize the sum of the squared deviations for 2 vectors. The only thing am having trouble with is defining the project constraint. I got the upper and lower bounds to work but i am not sure how to create a constraint that the sum of x must be 1. Any help would be greatly appreciated. -- View this message in context: http://www.nabble.com/Help-using-spg-optimization-in-BB-package-tp23175224p23175224.html Sent from the R help mailing list archive at Nabble.com.
You can try defining a "projection" function as follows: project <- function(x) x / sum(x) This should work fine. Let me know if you have any trouble. 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 dre968 Sent: Wednesday, April 22, 2009 8:23 AM To: r-help at r-project.org Subject: [R] Help using spg optimization in BB package i'm trying to use the BB package to minimize the sum of the squared deviations for 2 vectors. The only thing am having trouble with is defining the project constraint. I got the upper and lower bounds to work but i am not sure how to create a constraint that the sum of x must be 1. Any help would be greatly appreciated. -- View this message in context: http://www.nabble.com/Help-using-spg-optimization-in-BB-package-tp23175224p2 3175224.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.
Hi,
Here is an example, with a correction to my previous email.
fr <- function(x) { ## Rosenbrock Banana function
x1 <- x[1]
x2 <- x[2]
100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
require(BB)
proj <- function(x, lower, upper) x / sum(x) # note: you need to specify
"lower" and "upper" as arguments, even if you don't use
them
spg(par=c(0.5, 0.5), fn=fr, project=proj)
Hope this helps,
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 dre968
Sent: Wednesday, April 22, 2009 8:23 AM
To: r-help at r-project.org
Subject: [R] Help using spg optimization in BB package
i'm trying to use the BB package to minimize the sum of the squared
deviations for 2 vectors. The only thing am having trouble with is defining
the project constraint. I got the upper and lower bounds to work but i am
not sure how to create a constraint that the sum of x must be 1. Any help
would be greatly appreciated.
--
View this message in context:
http://www.nabble.com/Help-using-spg-optimization-in-BB-package-tp23175224p2
3175224.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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.
Here is another approach using an augmented penalty lagragian method.
The same example:
fr <- function(x) { ## Rosenbrock Banana function
x1 <- x[1]
x2 <- x[2]
100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
fr.pen <- function(x, k=1e05) {
fr(x) + k * ( 1 - sum(x))^2
}
require(BB)
spg(par=c(0, 0), fn=fr.pen) # Note: this starting value will fail for the
"projection method" due to division by zero
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 dre968
Sent: Wednesday, April 22, 2009 8:23 AM
To: r-help at r-project.org
Subject: [R] Help using spg optimization in BB package
i'm trying to use the BB package to minimize the sum of the squared
deviations for 2 vectors. The only thing am having trouble with is defining
the project constraint. I got the upper and lower bounds to work but i am
not sure how to create a constraint that the sum of x must be 1. Any help
would be greatly appreciated.
--
View this message in context:
http://www.nabble.com/Help-using-spg-optimization-in-BB-package-tp23175224p2
3175224.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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.
Apparently Analagous Threads
- BB - a new package for solving nonlinear system of equations and for optimization with simple constraints
- constrained optimisation in R.
- model selection with spg and AIC (or, convert list to fitted model object)
- Stuck using constrOptim
- Estimates at each iteration of optim()?