24小时热门版块排行榜    

查看: 1867  |  回复: 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的回帖

o452794544

新虫 (初入文坛)

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

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

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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[硕博家园] 请教兼职经验 +3 是阿文鸭 2026-08-09 3/150 2026-08-14 12:07 by HER12025
[基金申请] filecode +15 documentary 2026-08-10 17/850 2026-08-14 10:08 by kissu88
[基金申请] FileCode能看出啥? +10 要乐观耀哥 2026-08-10 32/1600 2026-08-14 09:37 by 要乐观耀哥
[基金申请] 我的国基提前知道中了,可是同事的操作让我实在接受不了,怎么会有这样的人 +10 家与远方 2026-08-10 15/750 2026-08-14 02:08 by 绵羊哥哥
[文学芳草园] 阿姨 +4 汪汪锅 2026-08-09 4/200 2026-08-13 19:43 by arzu_hma
[基金申请] 有时候,自然基金真的不能太认真 (我的申报经验) +4 majunge000 2026-08-11 6/300 2026-08-13 16:50 by 四季常青藤
[基金申请] 重要来源:本周末出结果 +10 瞬息宇宙 2026-08-12 10/500 2026-08-13 15:46 by likettle
[基金申请] 不应该看fileCode +7 且听虎啸 2026-08-12 9/450 2026-08-13 14:27 by flydreamws
[基金申请] 分享一下我之前已中青C的计划书的filecode +4 布布和一二 2026-08-11 5/250 2026-08-13 12:56 by cratir
[基金申请] 结合人工智能,周易传统文化,filecode打分制来了,3分以上希望很大。 +3 Tide man 2026-08-12 4/200 2026-08-13 08:35 by ZJTJZ
[基金申请] 2019年青年基金涵评意见,大家看看几个A,几个B? +11 Tide man 2026-08-11 11/550 2026-08-13 07:35 by 撸猫猫
[基金申请] 应该是93bebmhtak前后十一个字符比较关键 +22 Lanmanbaby 2026-08-09 36/1800 2026-08-12 22:50 by sdfapple719
[基金申请] 奇怪,两个人的filecode固定段从头到尾一模一样 +7 布布和一二 2026-08-10 10/500 2026-08-12 09:12 by 布布和一二
[基金申请] 是这周出结果还是下周出结果? +3 yuleib84 2026-08-11 3/150 2026-08-11 21:53 by jnhyjjm
[基金申请] 帮忙看看fileCode +7 wwncly 2026-08-10 13/650 2026-08-11 19:36 by 冰心玉壶晴
[基金申请] 什么时候出结果,有咨询渠道??? +3 Tide man 2026-08-11 3/150 2026-08-11 17:54 by kudofaye
[基金申请] 国自然结果 +4 Vierhys 2026-08-10 8/400 2026-08-10 15:06 by Vierhys
[基金申请] 这样的filecode谁见过 +11 布布和一二 2026-08-08 22/1100 2026-08-10 11:10 by wmfsnow
[基金申请] 国基金的申报应该改成非等额制,评价高的钱多评价低的钱少,但是增加资助率 +7 a089 2026-08-07 7/350 2026-08-08 18:05 by gltch
[基金申请] 化学口download_prp&fileCode的固定段好像这几天一直没变,有变的大神么? +3 Tide man 2026-08-07 4/200 2026-08-07 22:39 by Tide man
信息提示
请填处理意见