[R] Help using spg optimization in BB package

Ravi Varadhan RVaradhan at jhmi.edu
Wed Apr 22 17:26:14 CEST 2009


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.




More information about the R-help mailing list