Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of sltensor_svd
Home > sltoolbox > tensor > sltensor_svd.m

sltensor_svd

PURPOSE ^

SLTENSOR_SVD Performs a Higher-Order SVD on a Tensor

SYNOPSIS ^

function varargout = sltensor_svd(T, n)

DESCRIPTION ^

SLTENSOR_SVD Performs a Higher-Order SVD on a Tensor

 $ Syntax $
   - [S, U1, U2, ...] = sltensor_svd(T)
   - [S, U1, U2, ...] = sltensor_svd(T, n)
   - [S, Us] = sltensor_svd(...)

 $ Description $
   - [S, U1, U2, ...] = sltensor_svd(T) Performs a Higher Order Singular Value
   Decomposition to a Tensor T. In the output arguments, S is the core
   tensor, U1, U2, ... are the singular vector matrices of mode 1, 2,...

   - [S, U1, U2, ...] = sltensor_svd(T, n) Here n specifies the order of the
   tensor T, n should be not less than ndims(T). If n > ndims(T) is just
   regarded as a tensor of dimensions d1xd2x...x1. 

   - [S, Us] = sltensor_svd(...) where all mode matrices are returned to Us,
   which is an 1 x n cell array, with each cell containing a mode matrix.
 
 $ History $
   - Created by Dahua Lin on Dec 17th, 2005

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout = sltensor_svd(T, n)
0002 %SLTENSOR_SVD Performs a Higher-Order SVD on a Tensor
0003 %
0004 % $ Syntax $
0005 %   - [S, U1, U2, ...] = sltensor_svd(T)
0006 %   - [S, U1, U2, ...] = sltensor_svd(T, n)
0007 %   - [S, Us] = sltensor_svd(...)
0008 %
0009 % $ Description $
0010 %   - [S, U1, U2, ...] = sltensor_svd(T) Performs a Higher Order Singular Value
0011 %   Decomposition to a Tensor T. In the output arguments, S is the core
0012 %   tensor, U1, U2, ... are the singular vector matrices of mode 1, 2,...
0013 %
0014 %   - [S, U1, U2, ...] = sltensor_svd(T, n) Here n specifies the order of the
0015 %   tensor T, n should be not less than ndims(T). If n > ndims(T) is just
0016 %   regarded as a tensor of dimensions d1xd2x...x1.
0017 %
0018 %   - [S, Us] = sltensor_svd(...) where all mode matrices are returned to Us,
0019 %   which is an 1 x n cell array, with each cell containing a mode matrix.
0020 %
0021 % $ History $
0022 %   - Created by Dahua Lin on Dec 17th, 2005
0023 %
0024 
0025 %% parse and verify the arguments
0026 slchknargs(nargin, 1);
0027 n0 = ndims(T);
0028 if nargin == 1
0029     n = n0;
0030 else
0031     if n < n0;
0032         error('sltoolbox:invalidarg', ...
0033             'The order %d is too small', n);
0034     end
0035 end
0036 if nargout > 2 && nargout ~= n+1
0037     error('sltoolbox:invalidnargout', ...
0038         'The number of outputs is not valid');
0039 end
0040 
0041 %% compute
0042 
0043 Us = cell(n, 1);
0044 S = T;
0045 for i = 1 : n0
0046     M = sltensor_unfold(T, i);
0047     [d1, d2] = size(M);
0048     if d1 < d2
0049         [V, D, U] = svd(M', 0);
0050     else
0051         [U, D, V] = svd(M, 0);
0052     end
0053     slignorevars(D, V);
0054     clear D V;
0055     
0056     Us{i} = U;
0057     S = sltensor_multiply(S, U', i);
0058 end
0059 if n > n0
0060     for i = n0+1 : n
0061         Us{i} = 1;
0062     end
0063 end
0064 
0065 %% output
0066 varargout{1} = S;
0067 if nargout == 2
0068     varargout{2} = Us;
0069 else
0070     varargout(2:n+1) = Us;
0071 end
0072 
0073 
0074     
0075 
0076 
0077 
0078 
0079 
0080 
0081     
0082

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com