[R] optimization problem
John C Nash
nashjc at uottawa.ca
Fri Nov 28 17:28:29 CET 2008
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-8
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)+(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.
More information about the R-help
mailing list