📄 ftparap1.m
字号:
function [Ypred,R]=ftparap1(Xcal,r1,r2,r3,W,Xpred,Ycal,CenMode);
%function [Ypred,R]=ftparap1(Xcal,r1,r2,r3,W,Xpred,Ycal,CenMode);
%
%This particular procedure (ftparap1) calculates the regression
%coefficients of the modelling of Y from A*R=Y. A is calculated
%from the solution to the PARAFAC model.
%NOTE:This predictor is build to, and should ONLY be used with,
%solutions from FTPARA01.M or FTPARA02.M
%(same scheme for updating A)
%
% Xcal : Supermatrix (r1 x r2穜3) from cube (r1 x r2 x r3).
% This supermatrix contains the EEM's for which the
% concentration will be determined.
% r1,r2,r3 : Number of observations along each way.
% W1 : Number of factors.
% Xpred : Supermatrix (rp x r2穜3) with objects whose
% Y-values must be estimated.
% Ycal : Y values to use for calibration, must have same
% number of rows as Xcal. Ycal (r1 x ry)
% CenMode : If CenMode=0 no centering else centering.
% Ypred : Ypred (rp x ry) Predicted values for the objects
% contained in Xpred.
% R : Regression coefficients. R (W x ry)
% Author : Claus A. Andersson, May 1995
% Copyright: Food Technology,
% Royal Veterinary & Agricultural University
% Copenhagen, Denmark
% E-mail : claus.andersson@pop.foodsci.kvl.dk
%Centers X
if CenMode==1,
st=ones(size(Xcal,1),1);
Xcen=mean(Xcal);
Xcal=Xcal-st*Xcen;
end;
%Calculates the scores of the calibration matrix
[Acal Bcal Ccal]=ftpara01(Xcal,r1,r2,r3,W,1,0);
%Centers Y
if CenMode==1,
st=ones(size(Ycal,1),1);
Ycen=mean(Ycal);
Ycal=Ycal-st*Ycen;
end;
%Calculates the regression coefficients in R
R=(Acal'*Acal)\Acal'*Ycal;
%Centers Xpred
if CenMode==1,
st=ones(size(Xpred,1),1);
Xpred=Xpred-st*Xcen;
end;
%Determines scores of the new material in Xnew
rpred1=size(Xpred,1);
Dtcal=diag(Ccal(1,:));
tmp1=Xpred(1:rpred1,1:r2)*Bcal*Dtcal;
tmp2=Dtcal*Bcal'*Bcal*Dtcal;
for t=2:r3,
Dtcal=diag(Ccal(t,:));
tmp1=tmp1+Xpred(1:rpred1,(t-1)*r2+1:t*r2)*Bcal*Dtcal;
tmp2=tmp2+Dtcal*Bcal'*Bcal*Dtcal;
end;
Apred=tmp1/tmp2;
%Predicts Y from new score
Ypred=Apred*R;
%Adds from centering
if CenMode==1,
st=ones(size(Ypred,1),1);
Ypred=Ypred+st*Ycen;
end;
disp('FTPARAP1: Execution ended.')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -