91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 13KB
    文件類型: .m
    金幣: 1
    下載: 3 次
    發布日期: 2021-06-08
  • 語言: Matlab
  • 標簽: matlab??ols??

資源簡介

ols,正交最小二乘法的matlab代碼,在曲線擬合中可以使用到,有注釋。

資源截圖

代碼片段和文件信息

function?[x?ind?r_act?A_o?x_o]?=?ols(Abrthreshold)
%?OLS???Orthogonal?Least?Quares.
%?
%?[x?ind]?=?OLS(Abr)?gives?the?solution?to?the?least?squares?problem?
%?using?only?the?best?r?regressors?chosen?from?the?ones?present?in?matrix?A.?
%?This?function?also?returns?in?the?vector?ind?the?indexes?of?the
%?best?r?regressors?(i.e.?the?best?columns?of?A?to?use).
%
%?If?r?is?equal?to?n?the?solution?x?given?by?OLS?is?the?same?as?the?solution?
%?given?by?A\b?but?in?ind?we?still?have?the?regressors?sorted?by?their?
%?importance.?%?This?means?that?one?can?perform?a?feature?selection?by?taking?
%?the?first?k?entries?in?ind?(k%?
%?THEORETICAL?BACKGROUND
%?Let?us?consider?the?Linear?Least?Squares?Problem:
%?
%??????min???(A*x-b)‘*(A*x-b)
%?
%?where?A?is?a?m-by-n?matrix?b?an?m-dimentional?vector?and?x?the?unknown?
%?an?n-dimentional?vector.?The?problem?is?well?posed?when?m>n.?
%?A?can?be?viewed?as?a?set?of?columns?usually?called?regressors?while?b?typically?
%?is?the?vector?of?desired?outputs.
%?The?solution?to?this?problem?can?be?computed?in?Matlab?through?the?function?
%?MLDIVIDE?as?follows:
%
%???x?=?A\b
%
%?Although?this?function?is?very?powerful?it?does?not?give?any?information?on?which?
%?regressor?is?better?than?others.?
%?On?the?other?hand?Orthogonal?Least?Squares?(OLS)?can?extract?this?information.
%?It?is?mainly?based?on?the?Gram-Schmidt?orthogonalization?algorithm.
%?
%?In?pattern?recognition?problems?usually?a?training?matrix?A_tr?is?given?
%?associated?with?the?vector?of?desired?outputs?b_tr?plus?a?test?set?pair?(A_ts?b_ts)?
%?where?the?system?has?to?be?tested.?In?such?cases?the?OLS?function?can?be
%?used?as?follows?with?a?value?of?r?chosen?by?the?user:
%
%?[x?ind]?=?OLS(A_tr?b_tr?r);
%
%?err_tr?=?(A_tr*x-b_tr)‘?*(A_tr*x-b_tr)/length(b_tr);?%?Mean?Squared?Error?on?training?set.
%?err_ts?=?(A_ts*x-b_ts)‘?*(A_ts*x-b_ts)/length(b_ts);?%?Mean?Squared?Error?on?test?set.
%?While?a?large?value?for?r?will?probably?give?a?low?error?on?the?training?set?
%?it?could?happen?that?a?lower?value?of?it?would?give?a?lower?error?on?the?test?set.?
%?In?such?cases?the?value?of?r?which?minimizes?the?error?on?the?test?set?should?be?chosen.
%?
%?ALTERNATIVE?SYNTAX
%
%?[x?ind?r_act]?=?OLS(Ab[]?threshold)?is?another?way?to?call?the?OLS?function.?
%?This?call?requires?a?threshold?in?place?of?the?number?of?regressors?r.?
%?The?threshold?which?has?to?be?a?decimal?number?in?the?interval?[01]?
%?indicates?the?maximum?relative?error?allowed?between?the?approximated?output?b_r?
%?and?the?desired?output?b?when?the?number?of?regressors?used?is?r.?
%?The?provided?output?r_act?gives?the?number?of?regressors?actually?used?which
%?are?necessary?to?reduce?the?error?untill?the?desired?value?of?the?threshold.
%?Please?not?that?r_act?is?also?equal?to?the?length?of?the?vector?ind.?
%?The?pseudocode?for?this?call?is?the?following:
%
%?for?r=1:n
%?????x_r?=?OLS(Abr);
%?????b_r?=?A*x_r;
%??

評論

共有 條評論