{"id":295,"date":"2013-07-09T15:17:38","date_gmt":"2013-07-09T11:47:38","guid":{"rendered":"http:\/\/vua.nadiran.com\/?p=295"},"modified":"2013-07-09T15:17:38","modified_gmt":"2013-07-09T11:47:38","slug":"%d9%85%d8%ab%d8%a7%d9%84-%d8%b1%da%af%d8%b1%d8%b3%db%8c%d9%88%d9%86-least-square","status":"publish","type":"post","link":"https:\/\/vua.nadiran.com\/?p=295","title":{"rendered":"\u0645\u062b\u0627\u0644 \u0631\u06af\u0631\u0633\u06cc\u0648\u0646 Least Square"},"content":{"rendered":"<div itemprop=\"content\"><a name=\"bqxtsia-1\"><\/a><\/p>\n<h3 dir=\"ltr\" id=\"bqxtsia-1\">Example: Robust Fitting<\/h3>\n<p><a name=\"zmw57dd0e7639\"><\/a><\/p>\n<ol dir=\"ltr\" type=\"1\">\n<li>Create a baseline sinusoidal signal:\n<pre>xdata = (0:0.1:2*pi)'; \r\ny0 = sin(xdata);<\/pre>\n<\/li>\n<li>Add noise to the signal with non-constant variance:\n<pre>% Response-dependent Gaussian noise\r\ngnoise = y0.*randn(size(y0));\r\n\r\n% Salt-and-pepper noise\r\nspnoise = zeros(size(y0)); \r\np = randperm(length(y0));\r\nsppoints = p(1:round(length(p)\/5));\r\nspnoise(sppoints) = 5*sign(y0(sppoints));\r\n\r\nydata = y0 + gnoise + spnoise;<\/pre>\n<\/li>\n<li>Fit the noisy data with a baseline sinusoidal model:\n<pre>f = fittype('a*sin(b*x)'); \r\nfit1 = fit(xdata,ydata,f,'StartPoint',[1 1]);<\/pre>\n<\/li>\n<li>Identify &#8220;outliers&#8221; as points at a distance greater than 1.5 standard deviations from the baseline model, and refit the data with the outliers excluded:\n<pre>fdata = feval(fit1,xdata); \r\nI = abs(fdata - ydata) &gt; 1.5*std(ydata); \r\noutliers = excludedata(xdata,ydata,'indices',I);\r\n\r\nfit2 = fit(xdata,ydata,f,'StartPoint',[1 1],'Exclude',outliers);<\/pre>\n<\/li>\n<li>Compare the effect of excluding the outliers with the effect of giving them lower bisquare weight in a robust fit:\n<pre>fit3 = fit(xdata,ydata,f,'StartPoint',[1 1],'Robust','on');<\/pre>\n<\/li>\n<li>Plot the data, the outliers, and the results of the fits:\n<pre>plot(fit1,'r-',xdata,ydata,'k.',outliers,'m*') \r\nhold on\r\nplot(fit2,'c--')\r\nplot(fit3,'b:')\r\nxlim([0 2*pi])<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-296\" alt=\"fitplots\" src=\"http:\/\/vua.nadiran.com\/wp-content\/uploads\/fitplots.gif\" width=\"465\" height=\"372\" \/><\/li>\n<li>Plot the residuals for the two fits considering outliers:\n<pre>figure \r\nplot(fit2,xdata,ydata,'co','residuals') \r\nhold on\r\nplot(fit3,xdata,ydata,'bx','residuals')<a href=\"http:\/\/vua.nadiran.com\/wp-content\/uploads\/resplot.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-297\" alt=\"resplot\" src=\"http:\/\/vua.nadiran.com\/wp-content\/uploads\/resplot.gif\" width=\"452\" height=\"371\" \/><\/a><\/pre>\n<\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Example: Robust Fitting Create a baseline sinusoidal signal: xdata = (0:0.1:2*pi)&#8217;; y0 = sin(xdata); Add noise to the signal with non-constant variance: % Response-dependent Gaussian noise gnoise = y0.*randn(size(y0)); % Salt-and-pepper noise spnoise = zeros(size(y0)); p = randperm(length(y0)); sppoints = p(1:round(length(p)\/5)); spnoise(sppoints) = 5*sign(y0(sppoints)); ydata = y0 + gnoise + spnoise; Fit the noisy data <a href='https:\/\/vua.nadiran.com\/?p=295' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-295","post","type-post","status-publish","format-standard","hentry","category-1","category-1-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"_links":{"self":[{"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=\/wp\/v2\/posts\/295"}],"collection":[{"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=295"}],"version-history":[{"count":2,"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=\/wp\/v2\/posts\/295\/revisions"}],"predecessor-version":[{"id":299,"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=\/wp\/v2\/posts\/295\/revisions\/299"}],"wp:attachment":[{"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vua.nadiran.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}