fnipals1.m

来自「Tucker, PARAFAC, GRAM, RAFA and misc. 2n」· M 代码 · 共 52 行

M
52
字号
function [T,P]=fnipals1(X,W)
%function [T,P]=fnipals1(X,W)
% T and P are found so that X = T*P'
% The decomposition uses the power method.
%
% X        : The matrix to be decomposed into T and P
% W        : Number of factors to extract
% Author   : Claus A. Andersson, April 1995
% Copyright: Food Technology,
%            Royal Veterinary & Agricultural University
%            Copenhagen, Denmark
% E-mail   : ca@kvl.dk
%
% Rev.     : One-column X's to give a valid T. Will
%            not check for W, but return X in T for all W, since
%            W>1 is invalid for column X (as the call is void),
%            22-7-97 CA

[a b]=size(X);
T=zeros(a,W);
P=zeros(b,W);
if b>1,
  for i=1:W,
    t=sum(X')'/a; 
    told=t+1;
    d=1;
    it=0;
    while (d>1e-10) & (it<300),
      it=it+1;
      p1=X'*t;
      p=p1/sqrt(sum(p1.^2));
      t=X*p;
      d=sum((t-told).^2)/sum(t.^2);
      told=t;
    end;
    X=X-t*p';
    if b>1,
      T(:,i)=t;
      P(:,i)=p;
    else
      T=t;
      P=p;
    end;
  end;
else
  T=X;
  P=1;
end;
if it>299,
  disp('Message from fnipals1 : Did not converge!')
end;

⌨️ 快捷键说明

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