24小时热门版块排行榜    

查看: 1663  |  回复: 7

o452794544

新虫 (初入文坛)

[求助] 二元非线性拟合,请大神帮忙看下程序哪有问题,谢谢!已有1人参与

两个自变量x1、x2,一个因变量y。通过绘图可以看出各个自变量和因变量的关系分布类似于正态分布,因此选用二维正太分布模型拟合。

下面是二维正态分布模型:

http://baike.baidu.com/view/9306579.htm  
可详见 http://baike.baidu.com/view/9306579.htm 百度百科

下面是数据:

y        x1                 x2
0        1000                2
0        1200                5
1        1400                15
1        1570                20
2        1720                30
2        1790                40
3        1860                60
4        1880                90
6        1980                172
7        2250                200
7        2530                250
8        2850                350
9        3100                450
10        3300                550
11        3500                650
12        3600                800
13        3800                1100
14        4000                1440
14        4200                1501
14        4500                1563
14        4800                1637
6        6800                2863

下面是函数代码:
function yy=fun(beta,x)
b1 = beta(1);
b2 = beta(2);
b3 = beta(3);
b4 = beta(4);
b5 = beta(5);
yy=(2*pi*b3*b4*(1-b5^2)^(1/2))^(-1)*exp(-1/2*(1-b5^2)^(-1)*((x(:,1)-b1)^2*b3^(-2)-2*b5*(x(:,1)-b1)*(x(:,2)-b2)*(b3*b4)^(-1)+(x(:,2)-b2)^2*b4^(-2)));

下面是程序运行代码:
clc
clear
data=load('data.txt');
y=data(:,1);
x=data(:,2:3);
beta=[1,0.1,3,1,0.5];         
[beta_out,r,J,COVB,mse]=nlinfit(x,y,@fun,beta);   
beta_out;
mse;
betaci=nlparci(beta_out,r,'Jacobian',J);   
betaa=[beta_out',betaci];        
[yy,delta]=nlpredci(@fun,x,beta_out,r,'Jacobian',J);
alpha=0.05;
nlintool(x,y,'fun',beta,alpha)  
r=corrcoef(y,yy);      
plotregression(y,yy)  
regstats(y,yy)

运行结果:
Warning: Rank deficient, rank = 0, tol =  0.000000e+00.
> In nlinfit>LMfit at 351
  In nlinfit at 184
  In nihe at 7
Warning: Some columns of the Jacobian are effectively zero at the solution, indicating that the
model is insensitive to some of its parameters.  That may be because those parameters are not
present in the model, or otherwise do not affect the predicted values.  It may also be due to
numerical underflow in the model function, which can sometimes be avoided by choosing better
initial parameter values, or by rescaling or recentering.  Parameter estimates may be unreliable.
> In nlinfit at 253
  In nihe at 7
Warning: Matrix is singular to working precision.
> In nlinfit at 274
  In nihe at 7
Warning: Matrix is singular to working precision.
> In nlparci at 104
  In nihe at 10
Warning: Matrix is singular to working precision.
> In nlpredci at 181
  In nihe at 12
Warning: Matrix is singular to working precision.
> In nlintool>PredictionsPlusError at 409
  In nlintool at 257
  In nihe at 14
Warning: Matrix is singular to working precision.
> In nlintool>PredictionsPlusError at 409
  In nlintool at 257
  In nihe at 14
Warning: Matrix is singular to working precision.
> In nlintool>PredictionsPlusError at 409
  In nlintool at 271
  In nihe at 14
Warning: Matrix is singular to working precision.
> In regstats at 193
  In regstats at 155
  In nihe at 17
Warning: Matrix is singular to working precision.
> In regstats at 208
  In regstats at 155
  In nihe at 17

出现很多错误,拟合度很低或者出现NaN。
求大神看是什么问题。
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingd

铁杆木虫 (职业作家)

【答案】应助回帖

★ ★ ★ ★ ★ ★
感谢参与,应助指数 +1
o452794544: 金币+6, ★★★很有帮助 2016-03-21 16:39:36
换这个公式要好的多:
y=a*exp(-0.5*(((x1-b)/c)^2))+d*exp(-0.5*(((x2-f)/g)^2));

均方差(RMSE):0.401981621559676
残差平方和(SSE):3.55496292957842
相关系数(R): 0.996661569977283
相关系数之平方(R^2): 0.993334285069583
确定系数(DC): 0.993333686971469
卡方系数(Chi-Square): 0.838652138061828
F统计(F-Statistic): 480.02546329649

参数        最佳估算
----------        -------------
a        -5.90625065613002
b        1204.03546366578
c        -526.613682770912
d        14.0704287034134
f        1448.75058061013
g        -1080.76690762784
2楼2016-03-15 14:50:58
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingd

铁杆木虫 (职业作家)

【答案】应助回帖

再加个拟合图
二元非线性拟合,请大神帮忙看下程序哪有问题,谢谢!
c1.jpg

3楼2016-03-15 14:51:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

o452794544

新虫 (初入文坛)

引用回帖:
2楼: Originally posted by dingd at 2016-03-15 14:50:58
换这个公式要好的多:
y=a*exp(-0.5*(((x1-b)/c)^2))+d*exp(-0.5*(((x2-f)/g)^2));

均方差(RMSE):0.401981621559676
残差平方和(SSE):3.55496292957842
相关系数(R): 0.996661569977283
相关系数之平方(R^2) ...

谢谢你的回答,这个是什么函数或模型?请问你为什么选用这个函数?有什么依据吗?
4楼2016-03-15 15:26:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

o452794544

新虫 (初入文坛)

引用回帖:
3楼: Originally posted by dingd at 2016-03-15 14:51:47
再加个拟合图

c1.jpg

还有可以把你的代码发上来吗?谢谢!
5楼2016-03-15 15:34:13
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingd

铁杆木虫 (职业作家)

引用回帖:
4楼: Originally posted by o452794544 at 2016-03-15 15:26:48
谢谢你的回答,这个是什么函数或模型?请问你为什么选用这个函数?有什么依据吗?...

三维高斯函数,专门的峰值函数
6楼2016-03-15 17:09:23
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

o452794544

新虫 (初入文坛)

引用回帖:
6楼: Originally posted by dingd at 2016-03-15 17:09:23
三维高斯函数,专门的峰值函数...

好的,谢谢,如果要是二元以上的多元的,也可以用这类函数吗?只要在函数后面再添加项就可以吗?
7楼2016-03-21 16:38:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

科院内马尔

银虫 (初入文坛)

引用回帖:
7楼: Originally posted by o452794544 at 2016-03-21 16:38:05
好的,谢谢,如果要是二元以上的多元的,也可以用这类函数吗?只要在函数后面再添加项就可以吗?...

楼主,请问你这个是用1stOpt实现的曲线拟合吗?
8楼2016-08-31 21:35:23
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 o452794544 的主题更新
信息提示
请填处理意见