Dear list, hi ! I am a R beginner and I have a function to optimize . alpha = argmin{ f(x,alpha) } I want alpha to be in [0,1]. Is there any function that can work? I use nlm() but i can't fix the domain of alpha. thanks in advance _______________________ Jiang Peng, Ph.D. Candidate Department of Mathematics & Antai college of Economics and Management Shanghai Jiao Tong University Address: Room 127, #3 Building, Xuhui Campus E-mail: jp021 at sjtu.edu.cn jp021 at 126.com MSN: jp021 at hotmail.com iChat: mathfrog at mac.com Mobile: +86-138 168 780 95
On the help page for nlm (type ?nlm) check out the 'See Also' section. It mentions other functions such as 'optim' and 'nlminb' which can do constrained optimizations. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Jiang Peng Sent: Monday, November 24, 2008 5:28 AM To: r-help at r-project.org Subject: [R] optimization problem Dear list, hi ! I am a R beginner and I have a function to optimize . alpha = argmin{ f(x,alpha) } I want alpha to be in [0,1]. Is there any function that can work? I use nlm() but i can't fix the domain of alpha. thanks in advance _______________________ Jiang Peng, Ph.D. Candidate Department of Mathematics & Antai college of Economics and Management Shanghai Jiao Tong University Address: Room 127, #3 Building, Xuhui Campus E-mail: jp021 at sjtu.edu.cn jp021 at 126.com MSN: jp021 at hotmail.com iChat: mathfrog at mac.com Mobile: +86-138 168 780 95 ______________________________________________ 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.
Is this the actual problem that you are trying to optimize, i.e. optimize a function with respect to a scalar unknown parameter? If so, just use "optimize" and specify the search interval for the algorithm as [0,1]. 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 Jiang Peng Sent: Monday, November 24, 2008 6:28 AM To: r-help at r-project.org Subject: [R] optimization problem Dear list, hi ! I am a R beginner and I have a function to optimize . alpha = argmin{ f(x,alpha) } I want alpha to be in [0,1]. Is there any function that can work? I use nlm() but i can't fix the domain of alpha. thanks in advance _______________________ Jiang Peng, Ph.D. Candidate Department of Mathematics & Antai college of Economics and Management Shanghai Jiao Tong University Address: Room 127, #3 Building, Xuhui Campus E-mail: jp021 at sjtu.edu.cn jp021 at 126.com MSN: jp021 at hotmail.com iChat: mathfrog at mac.com Mobile: +86-138 168 780 95 ______________________________________________ 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, all I am facing an optimization problem. I am using the function optim(par,fun), but I find that every time I give different original guess parameter, I can get different result. For example I have a data frame named data: head(data) price s x t 1 1678.0 12817 11200 0.1495902 2 1675.5 12817 11200 0.1495902 3 1678.0 12817 11200 0.1495902 4 1688.0 12817 11200 0.1495902 5 1677.0 12817 11200 0.1495902 6 1678.5 12817 11200 0.1495902 ??. ??. ??. f<-function(p,...){ v=exp(p[1]+p[2]*(x/s)+p[3]*(x/s)^2) d1=(log(s/x)+(v^2)*t/2)/(v*sqrt(t)) d2=(log(s/x)-(v^2)*t/2)/(v*sqrt(t)) sum((price-(s*pnorm(d1)-x*pnorm(d2)))^2) } p=c(-0.1,-0.1,0.01) optim(par=p,f) # use the default algorism $par [1] -1.2669459 0.4840307 -0.6607008 $value [1] 14534.56 $counts function gradient 154 NA $convergence [1] 0 If I try a different original guess estimes, I can get different number> p=c(-1,-0.1,0.5) > optim(par=p,f)$par [1] -0.7784273 -0.4776970 -0.1877029 $value [1] 14292.19 $counts function gradient 76 NA $convergence [1] 0 $message NULL I have other different original estimes, It also show me different result. Why? Thanks. -- View this message in context: http://www.nabble.com/optimization-problem-tp20730032p20730032.html Sent from the R help mailing list archive at Nabble.com.
Hi, I guess your function has several local minima and depending on where you start, i.e. your initial variables, you get into another mimimum. HTH Armin
If I want to find out the globle minia, how shoul I change my code? Thanks a lot Armin Meier wrote:> > Hi, > I guess your function has several local minima and depending on where > you start, i.e. your initial variables, you get into another mimimum. > > HTH > Armin > > ______________________________________________ > 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. > >-- View this message in context: http://www.nabble.com/optimization-problem-tp20730032p20737066.html Sent from the R help mailing list archive at Nabble.com.
tedzxx asked about apparent multiple optima. See below. Users should be aware that optim() does local optimization. The default Nelder-Mead approach is fairly robust at finding such a local minimum, though it may halt if it is on a flat area of the loss function surface. I would recommend trying one of the BFGS codes (they use somewhat different approaches) and look at the gradient information. With only 3 parameters, these should work fine. There is also another package (I forget the name -- someone?) that does full Newton with Hessian computed. That may be worth using to get more complete information about your problem. tedzxx: If you send me the data off-list (maybe also include the function again to save me digging it up again), I'll try to provide more information. John Nash>Date: Thu, 27 Nov 2008 23:30:56 -0800 (PST) >From: tedzzx <zengzhenxing at gmail.com> >Subject: [R] optimization problem >To: r-help at r-project.org >Message-ID: <20730032.post at talk.nabble.com> >Content-Type: text/plain; charset=UTF-8I am facing an optimization problem. I am using the function optim(par,fun), but I find that every time I give different original guess parameter, I can get different result. For example I have a data frame named data: head(data) price s x t 1 1678.0 12817 11200 0.1495902 2 1675.5 12817 11200 0.1495902 3 1678.0 12817 11200 0.1495902 4 1688.0 12817 11200 0.1495902 5 1677.0 12817 11200 0.1495902 6 1678.5 12817 11200 0.1495902 ??. f<-function(p,...){ v=exp(p[1]+p[2]*(x/s)+p[3]*(x/s)2) d1=(log(s/x)+(v2)*t/2)/(v*sqrt(t)) d2=(log(s/x)-(v2)*t/2)/(v*sqrt(t)) sum((price-(s*pnorm(d1)-x*pnorm(d2)))2) } p=c(-0.1,-0.1,0.01) optim(par=p,f) # use the default algorism I have other different original estimes, It also show me different result. Why? Thanks.