Multilinear singular value decomposition and low multilinear rank approximation¶
Figure 37: A (truncated) multilinear singular value decomposition or a low multilinear rank approximation of a third-order tensor.
In both the multilinear singular value decomposition (MLSVD) [17] and the low multilinear rank approximation (LMLRA) [4][5][6] a tensor \(\ten{T}\) of size \(I_1 \times I_2 \times \cdots \times I_N\) is written as the multilinear tensor-matrix product of a core tensor \(\ten{S}\) of size \(R_1 \times R_2 \times \cdots \times R_N\) with \(N\) factors \(\mat{U}^{(n)}\) of size \(I_n \times R_n\):
in which \(\tmprod_n\) is the tensor-matrix product in mode \(n\) (see Tensor operations). For all \(n\), \(R_n \leq I_n\). A visual representation of these decompositions in the third-order case is shown in Figure 37. The relations between the two decompositions are explained in the demo on “Multilinear Singular Value Decomposition and Low Multilinear Rank Approximation”. The differences between the MLSVD and the LMLRA lie in the computation and the optimality of the decomposition. As the decompositions are closely related and have the same format, both are discussed together here.
Problem and tensor generation¶
Generating pseudorandom factor matrices and core tensor¶
Tensorlab stores the core tensor \(\ten{S} \in \C^{R_1\times
R_2\times\cdots\times R_N}\) and the factor matrices \(\mat{U}^{(n)} \in
\C^{I_n\times R_n}\), \(n=1,\ldots,N\) corresponding to an MLSVD or LMLRA of a
tensor of dimensions \(I_1 \times I_2 \times \cdots \times I_N\) as a Matlab
array S and a cell array U = {U{1}, U{2}, ..., U{N}}. The
lmlra_rnd method can be used to generate a pseudorandom core tensor
\(\ten{S}\) and pseudorandom factor matrices \(\mat{U}^{(n)}\)
corresponding to an MLSVD or LMLRA. For example, to construct a tensor of dimensions
size_tens = [I1, I2, ..., IN] and with core size
size_core = [R1, R2, ..., RN] we can use:
size_tens = [17 19 21];
size_core = [3 5 7];
[U,S] = lmlra_rnd(size_tens,size_core);
By default, lmlra_rnd generates U{n} and S using randn, after
which the result is normalized such that the factors \(\mat{U}^{(n)}\) have
orthonormal columns and such that \(\ten{S}\) is all-orthogonal and has
ordered multilinear singular values. Other generators can
also be specified by providing option as a structure or as key-value pairs,
e.g.:
% using a structure
options = struct;
options.Real = @rand;
options.Imag = @rand;
[U,S] = lmlra_rnd(size_tens,size_core,options);
% using key-value pairs
[U,S] = lmlra_rnd(size_tens, size_core, 'Real', @rand, 'Imag', @rand);
The core tensor S is generated as rand(size_core) + rand(size_core)*1i,
and is then normalized. Before the normalization, the factor matrices U{n}
are generated as
rand(size_tens(n),size_core(n)) + rand(size_tens(n),size_core(n))*1i``.
The normalization of the factors matrices and the core tensor can be disabled by
setting the Unitary and Normalize options to false.
Generating the associated full tensor¶
Given a cell array of factor matrices U = {U{1},U{2},...} and core tensor
S, its associated full tensor T can be computed with
T = lmlragen(U,S); % or
T = ful({U,S});
Note that additional braces {} are necessary for the ful command. The tensor T = lmlragen(U,S) can be computed using elementary tensor
operations as
T = tmprod(S,U,1:length(U));
Both the ful and the lmlragen method also allow the generation of
subtensors:
[U, S] = lmlra_rnd([10 11 12], [3 4 2]);
T = lmlragen(U,S);
t1 = lmlragen(U, S, [1 1 2 3 5 8]); % using linear indices
frob(t1 - T([1 1 2 3 5 8])) % is zero up to machine precision
t2 = ful({U,S}, ':', ':', 9); % using subscripts (':' is a string!)
frob(t2 - T(:,:,9)) % is zero up to machine precision
Computing an MLSVD¶
To compute an MLSVD of a tensor \(\ten{T}\), three algorithms are available:
mlsvd can be used for dense tensors, mlsvds can be used for sparse
tensors and mlsvd_rsi can be used for large tensors, which can be both dense and sparse.
Currently, there exist no MLSVD algorithms for incomplete or efficiently
represented tensors in Tensorlab. In the latter case ful(T) can be used,
in the former case LMLRA algorithms can be used.
For a dense tensor \(\ten{T}\), the full MLSVD and the multilinear singular values can be computed using
[U, S] = lmlra_rnd([10 11 12], [3 4 5]);
T = lmlragen(U,S);
Tn = noisy(T, 40); % add Gaussian noise with an SNR of 40dB
[U, S, sv] = mlsvd(T);
It is often useful to inspect the multilinear singular values sv as they
provide useful information on the multilinear rank of the tensor. As an example,
the singular values can be plotted using:
for n = 1:3
subplot(1,3,n);
semilogy(sv{n});
end
For a sparse tensor \(\ten{T}\), the core size needs to be provided; hence, to compute the full MLSVD the following command can be used:
% Create sparse tensor with 4% non-zeros
T = randn(10, 11, 12);
T(randperm(numel(T), ceil(0.96*numel(T)))) = 0;
T = fmt(T);
% Compute mlsvd
[U, S, sv] = mlsvds(T, [10 11 12]);
Often, the MLSVD is truncated, i.e., the size of the core is smaller than the size of the tensor. An MLSVD can be truncated manually: for the tensor above, we can use
new_core = [5 4 7];
Ut = arrayfun(@(n) U(:,1:new_core(n)), U, new_core, 'UniformOutput', false);
St = S(1:new_core(1),1:new_core(2),1:new_core(3));
Alternatively, the core size can be passed to the mlsvd and mlsvds
algorithms as an additional parameter. For example, the following code can be used to
generate a multilinear rank-\((2, 3, 4)\) approximation:
Tfull = randn(10, 11, 12);
[Ufull, Sfull] = mlsvd(Tfull, [2 3 4]);
Tsparse = randn(10, 11, 12);
Tsparse(randperm(numel(Tsparse), ceil(0.96*numel(Tsparse)))) = 0;
Tsparse = fmt(Tsparse);
[Usparse, Ssparse] = mlsvds(Tsparse, [2 3 4]);
The sizes of the core tensor and the factor matrices are now
Ufull
size(Sfull)
Ufull =
[10x2 double] [11x3 double] [12x4 double]
ans =
2 3 4
T = randn(10, 11, 12);
[U, S] = mlsvd(T, [2 2 5], [], 'FullSVD', true); % perms = [] uses default
The MLSVD relies on singular value decompositions (SVD) of matrix
representations of the given tensor.
These SVDs can be expensive for larger tensors. The mlsvd_rsi routine uses
randomized SVDs to improve the computation speed for dense and sparse
tensors:
size_core = [5 6 7];
[U, S] = lmlra_rnd([30,40,50], size_core);
T = lmlragen(U,S);
tic, [U1, S1] = mlsvd(T, size_core); toc
tic, [U2, S2] = mlsvd_rsi(T, size_core); toc
Elapsed time is 0.073221 seconds.
Elapsed time is 0.027600 seconds.
Major improvements can be obtained for larger tensors. The accuracy of the results
computed by mlsvd_rsi is most often similar to the accuracy of the
results computed by mlsvd or mlsvds:
froblmlrares(T, U1, S1)/frob(T)
froblmlrares(T, U2, S2)/frob(T)
ans =
2.4422e-15
ans =
1.4491e-15
Computing an LMLRA¶
Several algorithms are available to compute the LMLRA of a dense, sparse,
incomplete or structured tensor \(\ten{T}\) with a (fixed) core size
\(R_1 \times R_2 \times \cdots \times R_N\). The commands lmlra_nls and
lmlra_minf are optimization-based algorithms using nonlinear unconstrained
optimization and nonlinear least squares, respectively. lmlra_aca uses
adaptive cross approximation. This method often provides a good initialization.
Finally, the principal method is lmlra, which automatically computes an
initialization and refines this initial guess using one of the
optimization-based methods. All optimization-based algorithms accept dense,
sparse, incomplete and efficient representations of structured tensors (see Datasets: dense, incomplete, sparse and structured). If efficient representations are used, and a solution accurate up to machine precision is needed, make sure to read the note at the end of this chapter.
The principal method¶
The lmlra method is the easiest way to compute an LMLRA of a tensor
\(\ten{T}\). For example
% Generate pseudorandom LMLRA (U,S) and associated full tensor T.
size_tens = [17 19 21];
size_core = [3 5 7];
[U,S] = lmlra_rnd(size_tens,size_core);
T = lmlragen(U,S);
% Compute an LMLRA of a noisy version of T with 20dB SNR.
[Uhat,Shat] = lmlra(noisy(T,20), size_core);
generates a real rank-(3,5,7) tensor and computes its low multilinear rank
approximation. Internally, lmlra chooses a method to generate an
initialization U0 and S0, e.g., mlsvd_rsi or lmlra_aca. Next it
executes an algorithm to compute the LMLRA given the initialization, e.g.,
lmlra_nls.
The command lmlra(T, size_core) computes an initial solution with the
desired multilinear rank. Alternatively an initial solution can be provided
using
[Uinit, Sinit] = lmlra_rnd([10 11 12], size_core);
[Uhat, Shat] = lmlra(T, Uinit, Sinit);
The default initialization methods mlsvd_rsi or lmlra_aca return nearly
the same initialization for every run. Therefore, if multiple runs are performed
for a specific tensor \(\ten{T}\) and a specific multilinear rank
\((R_1,R_2,\ldots,R_N)\) (for the same options), the initialization method
should be changed, e.g., to lmlra_rnd. The following example uses the
mlsvd_rsi algorithm as initialization method for the first run, and uses a
random initialization (lmlra_rnd) for the other runs:
init = @mlsvd_rsi;
resultU = cell(1, 5);
resultS = cell(1, 5);
for n = 1:5
[resultU{n}, resultS{n}]= lmlra(T, size_core, 'Initialization', init);
init = @lmlra_rnd;
end
The next subsection explains different options for the lmlra routine.
Setting the options¶
Different options can be used to customize the two steps in lmlra (see
help lmlra for more information). Options can be provided using an
options structure, or using key-value pairs, e.g.,
options.Display = true; % Show progress on the command line.
options.Initialization = @lmlra_rnd; % Select pseudorandom initialization.
options.Algorithm = @lmlra_minf; % Select NLS as the main algorithm.
options.AlgorithmOptions.TolFun = 1e-12; % Set stop criteria.
options.AlgorithmOptions.TolX = 1e-12;
[Uhat,Shat] = lmlra(T,size_core,options);
The structures InitializationOptions and AlgorithmOptions are passed
as options structures to the algorithms corresponding to the initialization and
algorithm steps, respectively.
See help lmlra for a full overview of the possible options. The following is
worthwhile to be highlighted:
ExpandLimit: allows a structured tensorTto be expanded for the compression and/or initialization steps ifprod(getsize(T)) <= ExpandLimit. SetExpandLimit = 1to make sure tensors are never expanded. The default is \(10^6\).
Viewing the algorithm output¶
Each step may output additional information specific to that step. For
instance, most LMLRA algorithms such as lmlra_hooi will keep track of the
number of iterations and the difference in subspace angle of every two
successive iterates sangle. To obtain this information, capture the third
output:
[Uhat,Shat,output] = lmlra(T,size_core,options);
and inspect its fields, for example by plotting the objective function value:
semilogy(0:output.Algorithm.iterations,sqrt(2*output.Algorithm.fval));
xlabel('iteration');
ylabel('frob(lmlrares(T,U))');
grid on;
Setting the Display option to true or to a number greater than zero,
prints additional information to the command window. For example:
size_core = [5 6 3];
[U,S] = lmlra_rnd([10 11 12], size_core);
T = lmlragen(U,S);
Tn = noisy(T, 20);
[Uhat, Shat, output] = lmlra(Tn, size_core, 'Display', 1);
Step 1: Initialization is mlsvd_rsi...relative error = 0.0930664.
Step 2: Algorithm is lmlra_nls... iterations = 5,
relative error = 0.0930472.
Two steps are performed by lmlra. In step 1, the mlsvd_rsi algorithm is
used to compute an initial guess, which is refined in step 2 using the
lmlra_nls algorithm.
In the case the tensor T is given as the efficient representation of a structured tensor, step 1 can also contain an expansion step:
% Create a tensor with CPD structure
T = cpd_rnd([10 11 12], 5);
T{1} = bsxfun(@times, T{1}, [1000 100 10 1 0.01]);
options = struct;
options.Algorithm = @lmlra_minf; % use minf algorithm
[Uhat, Shat, output] = lmlra(T, [4 4 4], 'Display', 1, options);
Step 1: Initialization is mlsvd_rsi:
| Step 1a: Structured tensor expanded to full tensor (prod(getsize(T) <= 1e+06)
| Step 1b: mlsvd_rsi on full tensor... relative error = 5.32044e-06.
Step 2: Algorithm is lmlra_minf... iterations = 1, relative error = 5.32044e-06.
In step 1a, the tensor is expanded such that the mlsvd_rsi algorithm can be
used as initialization. Without expansion, lmlra_aca is the default
initialization algorithm for structured tensors.
Note that structure is not yet detected automatically in the lmlra command.
Computing the error¶
The residual between a tensor \(\ten{T}\) and its computed LMLRA defined by the core tensor \(\ten{\hat{S}}\) and factor matrices \(\mat{\hat{U}}^{(n)}\) can be computed with
res = lmlrares(T,Uhat,Shat);
If the tensor is dense, then the result is equivalent to
lmlragen(Uhat,Shat)-T. The relative error between the tensor and its LMLRA
can then be computed as
relerr = frob(lmlrares(T,Uhat,Shat))/frob(T);
If the original factor matrices \(\mat{U}^{(n)}\) that generated
\(\ten{T}\) are known, the subspace angle between each of them and their
corresponding approximations \(\mat{\hat{U}}^{(n)}\) from lmlra can also
be used as a measure of the approximation error. The function lmlraerr
computes the subspace angle between the given two sets of factor matrices. In
other words,
sangle = lmlraerr(U,Uhat);
returns a vector in which the \(n\)th entry is subspace(U{n},Uhat{n}).
Choosing the size of the core tensor¶
For dense tensors, one can use the mlrankest tool to help determine the size
of the core tensor size_core. Running mlrankest(T) plots an L-curve
which represents the balance between an upper bound [17] on the relative
error of an LMLRA of T for different core tensor sizes, and the LMLRA’s
compression ratio. The following example applies mlrankest on the amino
acids dataset [16]:
url = 'http://www.models.life.ku.dk/go-engine?filename=amino.mat';
urlwrite(url,'amino.mat'); % Download amino.mat in this directory.
load amino X;
mlrankest(X);
The resulting figure is shown in Figure 38. The corner of this
L-curve is often a good estimate of the optimal trade-off between accuracy and
compression. The core tensor size size_core corresponding to the L-curve
corner is marked on the plot with a square and is also mlrankest‘s first
output. By capturing it as in size_core = mlrankest(X), the L-curve is no
longer plotted. All together, an LMLRA of the amino acids dataset can be
computed in only a few lines:
url = 'http://www.models.life.ku.dk/go-engine?filename=amino.mat';
urlwrite(url,'amino.mat'); % Download amino.mat in this directory.
load amino X;
size_core = mlrankest(X); % Optimal core tensor size at L-curve corner.
[U,S] = lmlra(X,size_core);
Additionally, the compression and relative error of other choices of
size_core can be viewed by using the figure’s Data Cursor tool.
Overview of algorithms¶
The mlsvd and lmlra methods are the principal methods for the MLSVD and
the LMLRA. Below we give an overview of the available algorithms for the
computation of the MLSVD and the LMLRA, as well as an overview of other
convenient routines.
The following algorithms can be used to compute the low multilinear rank approximation or the multilinear singular value decomposition of a dense, sparse, incomplete or efficiently represented tensor, unless otherwise specified.
lmlra(T, size_core)computes the LMLRA of a tensorTusing a multistep approach [29].lmlra_nls(T, U, S)computes the LMRLA of a tensorTusing an NLS type algorithm with as initial guessUfor the factor matrices andSfor the core tensor [29].lmlra_minf(T, U, S)computes the LMLRA of a tensorTusing nonlinear unconstrained optimization with as initial guessUfor the factor matrices andSfor the core tensor [29].lmlra_aca(T,size_core)computes the LMLRA of a tensorTusing adaptive cross approximation [30].mlsvd(T)computes the full MLSVD of a dense tensorT, including the multilinear singular values.mlsvd(T, size_core)truncates the MLSVD to the given core size andmlsvd(T, tol)truncates the MLSVD if the multilinear singular values are below a given tolerancetol[17][31].mlsvds(T,size_core)computes the truncated MLSVD of a sparse tensorT. The same options as formlsvdapply.mlsvd_rsi(T, size_core)computes the truncated MLSVD of a full or sparse tensorTusing a randomized SVD in combination with randomized subspace iteration. This algorithm is useful for larger tensors that have a low multilinear rank [32].lmlra_hooi(T, U)uses higher-order orthogonal iteration to compute the LMLRA of a dense tensorT[33].lmlra3_dgn(T, U)uses a differential-geometric Newton method to compute the LMLRA of a dense third-order tensorT[34].lmlra3_rtr(T, U)uses a Riemannian trust region method to compute the LMLRA of a dense third-order tensorT[35].
The following routines can be used for problem generation, error analysis and rank estimation.
lmlra_rnd(size_tens, size_core)generates pseudorandom factors for an LMLRA.lmlragen(U, S)generates the full tensor from given factorsUand core tensorS.lmlrares(T, U, S)computes the residuallmlragen(U,S) - T.froblmlrares(T, U)computes the Frobenius norm of the residuallmlragen(U,S) - T. This also works for structured tensorsT.lmlraerr(U, Uhat)computes the angle between the subspaces of the original tensor and the approximation. The subspaces are given as the factor matricesUof the original tensor and the factor matricesUhatof the approximation.mlrank(T,tol)computes the multilinear rank of a tensorTusing a given tolerancetol.mlrankest(T)estimates the multilinear rank of a tensorTfrom an L-curve.
Note
When using structured tensors, the expected numerical precision is only half
the machine precision. This is due to the mathematical formulation
implemented to exploit the structure. In most cases, this is not a problem as
the maximal attainable precision is already limited due to noise and model
errors. Only in the very specific case when a solution accurate up to machine
precision can be found and is required, this can be an issue. (This requires
TolFun and TolX to be eps^2 and eps, respectively.) A
solution is to use the structured tensor T to compute a solution
Ures, Sres accurate up to half the machine precision, and then refine
this solution using
lmlra_nls(ful(T), Ures, Sres, 'TolFun', eps^2, 'TolX', eps)
for a few iterations. (It can be useful to set MaxIter to 2 or
3.) This technique requires only very few expensive iterations involving
the full tensor.
Further reading¶
The algorithms outlined in this chapter can be used to compute an unconstrained MLSVD or LMLRA. In the structured data fusion (SDF) framework constraints can be imposed as well, and coupled decompositions can be defined. See Structured data fusion for more details.
The demo on “Multilinear Singular Value Decomposition and Low Multilinear Rank Approximation” gives some intuition behind the MLSVD and the LMLRA.
