📄 npred.m
字号:
function [ypred,T,ssX,Xres]=npred(X,DimX,DimY,Fac,Xfactors,Yfactors,B,show)
% $ Version 1.02 $ Date 28. July 1998 $ Not compiled $
%
% See also:
% 'npls' 'testreg'
%
% Copyright, 1998 -
% This M-file and the code in it belongs to the holder of the
% copyrights and is made public under the following constraints:
% It must not be changed or modified and code cannot be added.
% The file must be regarded as read-only. Furthermore, the
% code can not be made part of anything but the 'N-way Toolbox'.
% In case of doubt, contact the holder of the copyrights.
%
% Rasmus Bro
% Chemometrics Group, Food Technology
% Department of Food and Dairy Science
% Royal Veterinary and Agricultutal University
% Rolighedsvej 30, DK-1958 Frederiksberg, Denmark
% Phone +45 35283296
% Fax +45 35283245
% E-mail rb@kvl.dk
%
%
% Predict Y for a new set of samples using an N-PLS model
%
% [ypred,T,ssx,Xres] = npred(X,DimX,DimY,Fac,Xfactors,Yfactors,B,show);
%
% INPUT
% X The array to be predicted
% DimX The size of the CALIBRATION X-array
% DimY The size of the CALIBRATION y-array
% Fac Number of factors to use in prediction
% Xfactors Parameters of the calibration model of X (incl. scores)
% Yfactors Parameters of the calibration model of Y (incl. scores)
% B Regression matrix of calibration model
%
% OUTPUT
% ypred the predictions of y
% T is the scores of the new samples
% ssX sum-of-squares of x residuals
% ssX(1,1) sum-of-squares of X
% ssX(2,1) sum-of-squares of residuals
% ssX(1,2) percentage variation explained after 0 component (=0)
% ssX(2,2) percentage variation explained after Fac component
%
% Xres is the residuals of X
%
%
% Copyright
% Rasmus Bro 1995
% Denmark
% E-mail rb@kvl.dk
if nargin==0
disp(' ')
disp(' NPRED')
disp('[ypred,T,ssx,Xres] = npred(X,DimX,DimY,Fac,Xfactors,Yfactors,B,show);')
disp(' ')
break
end
ord=length(DimX);
OrigFac=round(length(Xfactors)/sum(DimX));
if length(Xfactors)~=OrigFac*sum(DimX)
error('DimX must describe the size of the CALIBRATION X')
elseif length(Yfactors)~=OrigFac*sum(DimY)
error('DimY must describe the size of the CALIBRATION Y')
end
if ~exist('show')==1
show=1;
end
maxit=20;
[I,not]=size(X);
if any(isnan(X(:)))
miss=1-isnan(X);
Missing=1;
else
Missing=0;
end
Xres=X;
T=zeros(I,Fac);
W=fac2let(Xfactors(DimX(1)*OrigFac+1:length(Xfactors)),[DimX(2:length(DimX))],OrigFac,1);
Q=fac2let(Yfactors(DimX(1)*OrigFac+1:length(Yfactors)),[DimY(2:length(DimY))],OrigFac,1);
for f=1:Fac
if Missing
for i=1:I
T(i,f)=Xres(i,find(miss(i,:)))*W(find(miss(i,:)),f)/(W(find(miss(i,:)),f)'*W(find(miss(i,:)),f));
end
Xres=Xres-T(:,f)*W(:,f)';
else
T(:,f)=Xres*W(:,f);
Xres=Xres-T(:,f)*W(:,f)';
end
end
ypred=T*B(1:Fac,1:Fac)*Q(:,1:Fac)';
ssx=sum(Xres(find(~isnan(Xres))).^2);
ssX=sum(X(find(~isnan(Xres))).^2);
ssX=[ssX 0;ssx 100*(1-ssx/ssX)];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -