全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2223 3
2012-12-04
NLS.pdf
大小:(102.99 KB)

只需: 10 个论坛币  马上下载



找到这个东东以后我骂了句粗话,早找到就好了,写这个code写得我晕了,function不同的要要稍微改改。

必须跟大家分享了。


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2012-12-4 07:02:55
精彩部分,免费分享,欲知详情请下载全文。

#Exponential model
fun=function(th,x){
y = th[2]+((th[1]-th[2])*exp(-th[3]*x))
return(y)
}
fun(th,x) #try it out -- should give you fitted values
#Calculate the residual sum of squares
resid=function(th,x,y){
yhat=fun(th,x)
rss=t(y-yhat)%*%(y-yhat)
return(rss)
}
resid(th,x,y) #try it out -- should give a scalar for output
#Calulate the Jacobian matrix
firder=function(th,x){
j1=exp(-th[3]*x)
j2=1-j1
j3=-x*(th[1]-th[2])*exp(-th[3]*x)
j=cbind(j1,j2,j3)
return(j)
}
firder(th,x)
#Calculate the Second Derivatives
secder=function(th,x){
h11=rep(0,times=length(x))
h21=h11
h22=h11
h31=-x*exp(-th[3]*x)
h32=-h31
h33=(x**2)*((th[1]-th[2])*exp(-th[3]*x))
hmat=cbind(h11,h21,h22,h31,h32,h33)
return(hmat)
}
secder(th,x)
#Gradient evaluated at "th"
grad=function(th,x,y){
fd=firder(th,x)
hm=secder(th,x)
yhat=fun(th,x)
r=y-yhat
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-12-4 08:07:28
10个币?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2012-12-4 08:54:08
具体什么用处?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群