Hçi quy phi tuy¸n

Một phần của tài liệu (LUẬN văn THẠC sĩ) phương pháp bình phương tối thiểu toàn phần (Trang 28 - 37)

Trong tr÷íng hñp mæ h¼nh phi tuy¸n, khâ º ÷a ra mèi quan h» to¡n håc ch½nh x¡c cho vi»c t½nh to¡n c¡c tham sè cõa mæ h¼nh. Trong v½ dö d÷îi ¥y ta s³ minh håa hçi quy phi tuy¸n d¤ng y = ax2 +bx+c. V½ dö 2.2 Cho c¡c iºm dú li»u (1.2855, 11.4827); (1.7693, 10.1865); (1.8751, 11.6311); (2.7917, 12.0355); (3.8174, 10.3946); (5.9197, 12.1562); (7.3133, 12.6762); (8.2018, 10.2297); (9.5408, 11.5356); (10.3918, 10.8350); (11.8336, 8.9380); (12.9259, 9.4711); (13.2589, 9.4175); (14.7536, 7.4543); (15.4299, 5.9990); (16.9608, 5.9532); (17.3013, 6.6710); (18.7012, 3.4274); (19.8249, 5.6086); (20.7231, 2.5100);

T¼m mæ h¼nh phi tuy¸n d¤ng y = ax2+bx+c cho dú li»u tr¶n. Ch÷ìng tr¼nh mæ phäng ¦y õ ÷ñc n¶u ð Phö löc cuèi luªn v«n. K¸t qu£ ÷ñc mæ t£ trong H¼nh 2.4 sau

Mæ h¼nh sû döng ph÷ìng ph¡p LS câ sai sè l  16.90 v  ÷íng parabol ÷ñc cho bði

y = −0.0335x2 + 0.2998y + 10.8836.

Mæ h¼nh sû döng ph÷ìng ph¡p TLS câ sai sè l  15.01 v  ÷íng parabol ÷ñc cho bði

T i li»u tham kh£o

[1] de Groen, Pieter (1996), "An introduction to Total Least Squares," Nieuw Arch. Wisk., 14(2), pp. 237253.

[2] Markovsky, Ivan and Van Huffel, Sabine (2007), Overview of total least-squares methods, Signal processing, 87(10), pp. 22832302. [3] Van Huffel, Sabine & Vanderwalle, Joos (1991), The Total Least

Squares Problem: Computational Aspects and Analysis, SIAM, Philadelphia, PA.

Phö löc

V½ dö 2.1. Sè li»u v· khèi l÷ñng v  chi·u cao cõa phö nú trong ë tuêi tø 30-39, ÷ñc cho trong b£ng sau

Chi·u cao, xi 1.50 1.51 1.52 1.55 1.57 1.60 1.60 1.61

Khèi l÷ñng, yi 52.21 53.12 54.48 55.84 57.20 58.57 59.93 61.29

Chi·u cao, xi 1.60 1.62 1.63 1.60 1.68 1.80 1.83

Khèi l÷ñng, yi 63.11 64.47 66.28 68.10 69.92 72.19 74.46

Ch÷ìng tr¼nh MATLAB ÷ñc sû döng nh÷ sau

Ph÷ìng ph¡p hçi quy tuy¸n t½nh trong khæng gian 2 chi·u function [Err, P] = fit_2D_data(XData, YData, vizualization) % Orthogonal linear regression method in 2D for model: y = a + bx % Input parameters:

% - XData: input data block x: axis % - YData: input data block y: axis % - vizualization: figure ('yes','no') % Return parameters:

% - Err: error - sum of orthogonal distances

% - P: vector of model parameters [b-slope, a-offset] kx=length(XData);

ky=length(YData); if kx = ky

disp('Incompatible X and Y data.'); close all;

n=size(YData,2); sy=sum(YData)./ky; sx=sum(XData)./kx; sxy=sum(XData.*YData); sy2=sum(YData.ˆ2); sx2=sum(XData.ˆ2); B=0.5.*(((sy2-ky.*sy.ˆ2)-(sx2-kx.*sx.ˆ2))./(ky.*sx.*sy-sxy)); b1=-B+(B.ˆ2+1).ˆ0.5; b2=-B-(B.ˆ2+1).ˆ0.5; a1=sy-b1.*sx; a2=sy-b2.*sx; R=corrcoef(XData,YData); if R(1,2) > 0 P=[b1 a1];

Yhat = XData.*b1 + a1; Xhat = ((YData-a1)./b1); end

if R(1,2) < 0 P=[b2 a2];

Yhat = XData.*b2 + a2; Xhat = ((YData-a2)./b2); end alpha = atan(abs((Yhat-YData)./(Xhat-XData))); d=abs(Xhat-XData).*sin(alpha); Err=sum(d.ˆ2); switch lower(vizualization) case 'yes' plot(XData,YData,'blue*');

hold on; plot(XData,Yhat,'black'); hold off

disp('No vizualization.') end

% ========================================== function [F, Srez, Scel]=statindexes(XData, YData, a, b)

% [F, Srez, Scel]=statindexes(xdata, ydata, a, b) % Computation of statistical indicators for linear model % Input parameters:

% - xdata: input data block x: axis % - ydata: input data block y: axis

% - a: parameter of linear model y = bx + a % - b: parameter of linear model /

% Return parameters: % - F: value for F-test

% - Srez: residual dispersion % - Scel: total dispersion

kx=length(XData); ky=length(YData); if kx = ky

disp('Incompatible X and Y data.'); close all; end n=size(YData,2); Srez = sum((YData-(a+b*XData)/(sqrt(1+bˆ2))).ˆ2)/(n-2); Scel=sum((YData-mean(YData)).ˆ2+(XData-mean(XData)).ˆ2)/(n- 1); F=Scel/Srez; % ========================================== clear all; close all;

1.80 1.83];

ydata=[52.21 53.12 54.48 52.84 57.20 58.57 59.93 61.29 63.11 64.47 66.28 68.10 69.92 72.19 74.46];

[ErrTLS, P1] = fit_2D_data(xdata, ydata, 'no') YhatTLS=polyval(P1,xdata);

[F_TLS, Srez_TLS, Scel_TLS] = statindexes(xdata, ydata, P1(2), P1(1))

P2=polyfit(xdata, ydata, 1) YhatLS=polyval(P2,xdata);

ErrLS=sum((YhatLS-ydata).ˆ2)

[F_LS, Srez_LS, Scel_LS] = statindexes(xdata, ydata, P2(2), P2(1)) plot(xdata, ydata, '*'); hold on plot(xdata,YhatTLS,'k'); hold on plot(xdata,YhatLS,'b','linewidth',1.5,'markersize',2); xlabel('x'); ylabel('y'); legend('Data','Model (TLS)', 'Model (LS)').

V½ dö 2.2. Cho c¡c iºm dú li»u (1.2855, 11.4827); (1.7693, 10.1865); (1.8751, 11.6311); (2.7917, 12.0355); (3.8174, 10.3946); (5.9197, 12.1562); (7.3133, 12.6762); (8.2018, 10.2297); (9.5408, 11.5356); (10.3918, 10.8350); (11.8336, 8.9380); (12.9259, 9.4711); (13.2589, 9.4175); (14.7536, 7.4543); (15.4299, 5.9990); (16.9608, 5.9532); (17.3013, 6.6710); (18.7012, 3.4274); (19.8249, 5.6086); (20.7231, 2.5100);

T¼m mæ h¼nh phi tuy¸n d¤ng y = ax2+bx+c cho dú li»u tr¶n. º minh håa t½nh hi»u qu£ cõa ph÷ìng ph¡p TLS v  LS, ta sû döng c¡c h m MATLAB nh÷ sau

%==================================

% Demo on Nonlinear regression models via TLS and classical LS method function [Err, min_param]=numerFminS(fun, p, LBa, UBa, xdata, ydata)

if (exist('fminsearchbnd', 'file') == 2) P = requireFEXpackage(8277);

% fminsearchbnd is part of 8277 at MathWorks.com end

warning off all

options1 = odeset('RelTol',1e-6,'AbsTol',1e-6); options = optimset('MaxIter',1e+4,'MaxFunEvals',1e+4,'TolX',1e-6,'TolFun',1e- 6); Mpoints(:,1)=xdata; Mpoints(:,2)=ydata; sum=0; a0=zeros(1,p); [a,fval,exitflag,output] = fminsearchbnd(@calculation,a0,LBa,UBa,options);

% calculating with optimized parameters: [yy]=fun(xdata, a);

x=xdata; y=yy;

%some output information about the minimization: algoritm=output.algorithm;

funcCount=output.funcCount; iter=output.iterations;

output.message; min_param=a;

%================================

%function for evaluating the model with optimized parameters function [sum] = calculation (a)

sum=0; [yy]=fun(xdata, a); x=xdata; y=yy; points(:,1)=x; points(:,2)=y; for m=1:size(Mpoints,1) [min_dist, IP]=dist_dsearch(points,Mpoints(m,:),'off'); sum=sum+(min_dist).ˆ2; end Err=sum; end end %=============================

function [I] = corrindex(XData, YData, YDataM, par_number)

% Function for calculation of the correlation index % Inputs: XData: x data % YData: y data % YDataM: model data % par_number: number of model parameters % Output: I: correlation index

kx=length(XData); ky=length(YData); kym=length(YDataM); if kx = ky

disp('Incompatible X and Y data.'); close all;

n=kym;

sey=(sum((YData-YDataM).ˆ2))/(n-par_number);

sy=var(YData); I=(1-(sey./sy))ˆ0.5;

%============================== clear all; close all;

xdata=[1.2855 1.7693 1.8751 2.7917 3.8174 5.9197 7.3133 8.2018 9.5408 10.3918 11.8336 12.9259 13.2589 14.7536 15.4299 16.9608 17.3013 18.7012 19.8249 20.7231]; ydata=[11.4827 10.1865 11.6311 12.0355 10.3946 12.1562 12.6762 10.2297 11.5356 10.8350 8.9380 9.4711 9.4175 7.4543 5.9990 5.9532 6.6710 3.4274 5.6086 2.5100]; par_number = 3; [ErrTLS,P1]=numerFminS(@model,par_number,[-0.05 0.5 9.5], [-0.04 0.7 10.0], xdata, ydata) YhatTLS=polyval(P1(1:par_number),xdata);

Index_TLS = corrindex(xdata, ydata, YhatTLS, par_number) P2=polyfit(xdata,ydata,2)

YhatLS=polyval(P2,xdata);

Index_LS = corrindex(xdata, ydata, YhatLS, par_number) plot(xdata, ydata, '*'); hold on plot(xdata,YhatTLS,'k'); hold on plot(xdata,YhatLS,'r'); xlabel('x'); ylabel('y'); legend('Data','Model (TLS)', 'Model (LS)');

Một phần của tài liệu (LUẬN văn THẠC sĩ) phương pháp bình phương tối thiểu toàn phần (Trang 28 - 37)

Tải bản đầy đủ (PDF)

(37 trang)