Subsurface Hydrology and Data Assimilation分享 http://blog.sciencenet.cn/u/lryj

博文

Curve Fitting

已有 5057 次阅读 2010-8-11 21:49 |个人分类:生活点滴|系统分类:科研笔记| function, curve, fitting

There are several method for curve fitting should be summarized for latter use. 1. "Solver" in Excel Step1 Define the objective parameters; Step2 Calculate the objective function with initial estimation of parameters and the observation data; Step3 Calculate and sum " { y_obs [ i ]-y_pred [ i ] }^2 "; Step4 Click "Solver" in the "Tool" tab; Step5 Select the "objective cell" and let "Solver" guess the "changed cell", and press "Solve" Advantage: Easy to implement without coding; Disadvantage: Time-consuming in estimating the reasonable initial value of parameters without priori-knowledge. 2. "lsqcurvefit" and "nlinfit"function F=fun(x,xdata)F=(x(1)./(xdata-x(2))).^(x(3)+1).*exp(-x(1)./(xdata-x(2)))/(x(1)*gamma(x(3))); xdata=[0.00020381 0.000305715 0.00045857]; ydata=[11.14050727 20.10060944 30.02599];x0=[0.00397 -0.0028687 0.822]; [x,resnorm]=nlinfit(xdata,ydata,@fun,x0) or[x,resnorm]=lsqcurvefit(@fun,x0,xdata,ydata) MaxValue=max(xdata); MinValue=min(xdata); x1=[MinValue:MaxValue/25:MaxValue]; y1=(x(1)./(xdata-x(2))).^(x(3)+1).*exp(-x(1)./(xdata-x(2)))/(x(1)*gamma(x(3))); loglog(xdata, ydata, 'ko',xdata,y1,'k-') Summary: The "Isqcurvefit" doesn't need very accurate initial estimation of parameters,however, the result is much worse than solver or good initial estimation of parameters. The "nlinfit" needs good estimation of initial parameters to get results. 3. Maximum Likelihood Estimation The advantage of this method is the loose need for the accurate initial estimation of the parameters. And, it is super-good method to do the curve fitting for the data set span several orders of magnitude. Open the M file of “Inverse_Gamma” Step1. Prepare Input Data Copy the bin of landslide area into “A_L” at line 5; Copy the calculated probability into “y” at line 11; Copy the frequency of landslides into “y_freq” at line 15; Step2. Change function ‘mlecustom’ in MATLAB Open ‘mlecustom’ with the path of “InstallationDrive:Matlabtoolboxstatsprivatemlecustom.m”; Or type ‘mlecustom’ in MATLAB Editor, then, select the string, right-click the string, and select ‘Open Selection’ in the popup list; Right after the function head, type in “global y_freq”; At line 150, replace “uncensFreq=freq(c);” with “uncensFreq =y_freq;” Step3. Output Run the script (Inverse_Gamma.m) in MATLAB Editor; The optimized parameters and the coefficient of determination will be showed in the command window; The fitting curve is showed in the figure window;


https://wap.sciencenet.cn/blog-304608-352126.html

上一篇:Data Assimilation 01-02: What is White Noise
下一篇:这个新家,太值得日后经常使用,促进自己的学术研究
收藏 IP: .*| 热度|

0

发表评论 评论 (2 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-30 16:38

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部