📄 pls程序0.txt
字号:
function [B,p,w,b]=pls1(x,y,A);
%[p,w,b]=pls1(x,y,maxnum) is a program by using pls1 algorithm to build a PLS model.
%x is a n*m matrix,where m is wavelength number and n sample number.
%y is a n*1 vector.
% A is a input parameter stated maximum of principle component number.
%output p is loadings, w weights and b is the regression coefficient.
% example for the application of the program
%
%[p,w,b]=pls1(x,y,10);
%for i=1:10 % with different latent variable number
% beta=w(:,1:i)/(p(:,1:i)'*w(:,1:i))*b(1:i);
% ype=xp*beta; % xp is a spectrum or spectra (a row vector or a matrix) to be used to predict
% SEP=[SEP sqrt((yp-ype)'*(yp-ype)/(length(yp)))];% calculate the standard error of prediction
%end;
% By Yiping Du, 2002,10,30, modeified in 2003,06,17
[n,m]=size(x);%
[nc,mc]=size(y);
if n~=nc
errordlg('error input of x and y','pls');
return;
end;
n_p=min([m,n,A]);
t=[];p=[];b=[];w=[];resi_y=[];resi_x=[];
for i=1:n_p
t=y;%one column with n elements
w=t'*x/(t'*t);%one row with m elements, w is mid var. of p
w=w/norm(w,2);%norm(w,2)=sqrt(w*w')
t=x*w'/(w*w');% one column with n elements
p=t'*x/(t'*t);
b=y'*t/(t'*t);%b is actually the q in models usually used.
pp(i,:)=p;
tt(:,i)=t;
ww(i,:)=w;
bb(i)=b;
x=x-t*p;
y=y-b*t;
end;
p=pp';
w=ww';
b=bb';
B=w(:,1:A)/(p(:,1:A)'*w(:,1:A))*b(1:A);
%resi_x=x;
%resi_y=y;
--
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -