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

📄 dtld.m

📁 多维数据处理:MATLAB源程序用于处理多维数据
💻 M
字号:
function [A,B,C,fit]=dtld(X,DimX,F,SmallMode);

% $ Version 1.02 $ Date 28. July 1998 $ Not compiled $
% $ Version 1.03 $ Date 25. April 1999 $ Not compiled $
%
% See also:
% 'gram' 
%
% 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
%
%
% DIRECT TRILINEAR DECOMPOSITION
%
% calculate the parameters of the three-
% way PARAFAC model directly. The model
% is not the least-squares but will be close
% to for precise data with little model-error
%
% This implementation works with an optimal
% compression using least-squares Tucker3 fitting
% to generate two pseudo-observation matrices that
% maximally span the variation of all samples. per
% default the mode of smallest dimension is compressed
% to two samples, while the remaining modes are 
% compressed to dimension F.
% 
% For large arrays it is fastest to have the smallest
% dimension in the first mode
%
% INPUT
% [A,B,C]=dtld(X,DimX,F);
% X is the I x J x K array unfolded to an I x JK matrix
% DimX = [I J K]
% F is the number of factors to fit
% An optional parameter may be given to enforce which
% mode is to be compressed to dimension two
%
% Copyright 1998
% Rasmus Bro, KVL
% rb@kvl.dk

DontShowOutput = 1;
%rearrange X so smallest dimension is in first mode

if nargin<4

  [a,SmallMode] = min(DimX);

  X = nshape(X,DimX,SmallMode);

  DimX = DimX([SmallMode 1:SmallMode-1 SmallMode+1:3]);

  Fac   = [2 F F];

else

  X = nshape(X,DimX,SmallMode);

  DimX = DimX([SmallMode 1:SmallMode-1 SmallMode+1:3]);

  Fac   = [2 F F];

end



f=F;

if F==1;

  Fac   = [2 2 2];

  f=2;

end 



if DimX(1) < 2

  error(' The smallest dimension must be > 1')

end

if any(DimX(2:3)-Fac(2:3)<0)

  error(' This algorithm requires that two modes are of dimension not less the number of components')

end



% Compress data into a 2 x F x F array. Only 10 iterations are used since exact SL fit is insignificant; only obtaining good truncated bases is important

[Factors,Gt]=tucker(X,DimX,Fac,[0 0 0 0 NaN 10]);

[At,Bt,Ct]=fac2let(Factors,DimX,Fac);



% Fit GRAM to compressed data

[Bg,Cg,Ag]=gram(reshape(Gt(1,:),f,f),reshape(Gt(2,:),f,f),F);



% De-compress data and find A

BB = Bt*Bg;

CC = Ct*Cg;

AA = X*pinv(ppp(BB,CC)).';



if SmallMode == 1

  A=AA;

  B=BB;

  C=CC;

elseif SmallMode == 2 

  A=BB;

  B=AA;

  C=CC;

elseif SmallMode == 3

  A=BB;

  B=CC;

  C=AA;

end





if ~DontShowOutput

  fit = sum(sum(abs(X - AA*ppp(BB,CC).').^2));

  disp([' DTLD fitted raw data with a sum-squared error of ',num2str(fit)])

end

⌨️ 快捷键说明

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