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

📄 fnipals1.m

📁 Tucker, PARAFAC, GRAM, RAFA and misc. 2nd order models with a test data set (old version now covered
💻 M
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -