⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftupcap1.m

📁 Tucker, PARAFAC, GRAM, RAFA and misc. 2nd order models with a test data set (old version now covered
💻 M
字号:
function [Ypred,R]=ftupcap1(Xcal,r1,r2,r3,W,Xpred,Ycal,CenMode);
%function [Ypred,R]=ftupcap1(Xcal,r1,r2,r3,W,Xpred,Ycal,CenMode);
%
%This particular procedure (ftupcap1) calculates the regression
%coefficients of the modelling of Y from A*R=Y when A is calculated
%from calibrated loadings B and C.
%
% 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.
% W        : Number of factors along each way, note that for
%            calibration purposes W1=W2=W3=W.
% 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. (r1 x ry)
% CenMode  : If CenMode=1 then all data are centered.
% Ypred    : Ypred (rp x ry) Predicted values for the objects
%            contained in Xpred.
% R        : Regression coefficients. R (W1 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 scores and loads of the calibration matrix
[Acal Bcal Ccal]=ftupca01(Xcal,r1,r2,r3,W,W,W);
%Unfolds the loadingplane 
loads=zeros(W,r2*r3);
for w=1:W,
  loads(w,:)=kron(Ccal(:,w)',Bcal(:,w)');
end;
%Calculates the scores
Acal=zeros(r1,W);
for i=1:r1,
  for w=1:W,
    Acal(i,w)=Acal(i,w)+Xcal(i,:)*loads(w,:)';
  end;
end;

%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 Xpred
rpred1=size(Xpred,1);
Apred=zeros(rpred1,W);
for i=1:rpred1,
  for w=1:W,
    Apred(i,w)=Apred(i,w)+Xpred(i,:)*loads(w,:)';
  end;
end;

%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('FTUPCAP1: Execution ended.')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -