.. _demo-mlsvd: Multilinear singular value decomposition and low multilinear rank approximation =============================================================================== **Tags:** ``mlsvd``, ``lmlra`` The multilinear singular value decomposition is, as the term indicates, a multilinear generalization of the matrix singular value decomposition. In this demo, we provide some insight in this decomposition and the low multilinear rank approximation. A Matlab implementation of this demo is given in the ``demo_mlsvd.m`` file, which can be found in the demo folder of Tensorlab or downloaded `here `_. For matrices, the singular value decomposition :math:`\mat{M} = \mat{U}\mat{\Sigma}\transpose{\mat{V}}` is well known. Using tensor-matrix products, this decomposition can be written as .. math:: \begin{aligned} \mat{M} = \mat{\Sigma}\tmprod_1\mat{U}\tmprod_2\mat{V}.\end{aligned} The matrix :math:`\mat{\Sigma}` is a diagonal matrix, and the matrices :math:`\mat{U}` and :math:`\mat{V}` are orthogonal matrices. A generalization of this SVD is the multilinear singular value decomposition (MLSVD). In the literature, one can also find the names higher-order SVD (HOSVD) and Tucker decomposition. The term Tucker decomposition has evolved over the years and is now often used in a more general sense. The MLSVD of a third-order tensor can be written as .. math:: \begin{aligned} \ten{T} = \ten{S}\tmprod_1\mat{U}^{(1)} \tmprod_2\mat{U}^{(2)} \tmprod_3\mat{U}^{(3)}. \label{eq:mlsvd}\end{aligned} Like in the matrix case where :math:`\mat{U}` and :math:`\mat{V}` are orthonormal bases for the column and row space, respectively, the MLSVD computes :math:`N` orthonormal bases :math:`\mat{U}^{(n)}`, :math:`n=1,\ldots,N` for the :math:`N` different subspaces of mode-\ :math:`n` vectors. As is illustrated in :num:`Figure #mlsvd1`, these orthonormal bases have exactly the same interpretation in as the matrix case. Essentially, the MLSVD considers a given tensor as :math:`N` sets of mode-\ :math:`n` vectors, and computes the matrix SVD of these sets. The multilinear rank of the tensor :math:`\ten{T}` corresponds to the :math:`N-\text{tuplet}` consisting of the dimensions of the different subspaces. .. _mlsvd1: .. figure:: img/mlsvd.* :alt: MLSVD :align: center :width: 95% Illustration of the multilinear singular value decomposition of a multilinear rank-:math:`(R_1,R_2,R_3)` tensor and the different spaces. The noiseless case ------------------ First we study the properties of the MLSVD for the exact case. Random factor matrices and a random core tensor are used to construct a multilinear rank-\ :math:`(2, 2, 3)` tensor :math:`\ten{T}`. Next the MLSVD is computed using ``mlsvd``. .. code-block:: tensorlab S = randn(2,2,3); U = {rand(4,2), rand(5,2), rand(6,3)}; T = lmlragen(U,S); [Ue,Se,sve] = mlsvd(T) We can check the properties of the MLSVD: - The first two, two and three columns of respectively ``Ue{1}``, ``Ue{2}``, and ``Ue{3}`` are a basis for the column, row and fiber subspaces of :math:`\ten{T}`, respectively. (``subspace`` computes the angle between subspaces: a zero angle indicates that the spaces are identical.) .. code-block:: tensorlab subspace(Ue{1}(:,1:2),U{1}) subspace(Ue{2}(:,1:2),U{2}) subspace(Ue{3}(:,1:3),U{3}) .. code-block:: none :caption: mlsvd-kladfq 4.3356e-16 4.9257e-16 6.2976e-16 - The remaining two, three and three columns of ``Ue{1}``, ``Ue{2}``, and ``Ue{3}`` are orthogonal bases for the complements of the column, row and fiber subspaces of :math:`\ten{T}`. These subspaces are orthogonal to the column, row, and fiber subspaces, respectively: .. code-block:: tensorlab U{1}'*Ue{1}(:, 3:end) U{2}'*Ue{2}(:, 3:end) U{3}'*Ue{3}(:, 4:end) .. code-block:: none :caption: nlsvdadlfj ans = 1.0e-15 * 0.2220 0.0555 0.0694 0.4580 ans = 1.0e-15 * -0.0139 0.0230 0.0173 0.1110 0.0607 0.1110 ans = 1.0e-15 * -0.1110 0.2637 0 -0.0971 0.2463 0.0902 0.0555 -0.2220 -0.1527 - Similar to the matrix SVD, the multilinear singular values ``sve`` indicate the importance of a basis vector in a particular mode. In contrast to the SVD, the core tensor :math:`\ten{S}` is not diagonal. The multilinear singular values are defined as the Frobenius norms of the slices of order :math:`N-1` for the different modes, i.e. the norm of the subtensor created by fixing one index: .. code-block:: tensorlab nrm = zeros(size(Se,1),1); for i = 1:size(Se,1) nrm(i) = frob(Se(i,:,:)); end [sve{1} nrm] % mode-1 singular values .. code-block:: none :caption: lkasdls ans = 2.0722 2.0722 1.1272 1.1272 0.0000 0.0000 0.0000 0.0000 The multilinear rank of a tensor can be determined by looking at the multilinear singular values. As shown in :num:`Figure #noiseless-sv`, the multilinear singular values :math:`\sigma_{r}^{(n)}` become zero for :math:`r > R_n`, in which :math:`R_n` is the mode-\ :math:`n` rank. .. code-block:: tensorlab for n = 1:3 subplot(1,3,n); semilogy(sve{n},'.-'); xlim([1 length(sve{n})]) end .. _noiseless-sv: .. figure:: img/noiseless-sv.* :alt: Multilinear singular values in the noiseless case. :align: center :width: 95% Multilinear singular values in the noiseless case. - Finally, the all-orthogonality of the core tensor is investigated. This property means that all slices of order :math:`N-1` are mutually orthogonal to each other. We test this for the second mode by computing the inner product between the slices. To do this efficiently, we unfold the tensor in the second mode. .. code-block:: tensorlab M = tens2mat(Se, 2); M*M' .. code-block:: none :caption: lkasdsad 4.7448 0 0.0000 -0.0000 -0.0000 0 0.8197 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 -0.0000 0.0000 0.0000 0.0000 0.0000 We indeed see that all the off-diagonal entries are zero. Note that the diagonal contains the squared multilinear singular values for the second mode. .. code-block:: tensorlab [sve{2} sve{2}.^2] .. code-block:: none :caption: lkasfadsfadsfasfdls 2.1782 4.7448 0.9054 0.8197 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 Noisy case ---------- The equality in Equation holds only for the exact case. When noise is added, the multilinear rank-\ :math:`(2, 2, 3)` decomposition only approximates the tensor. Here, the influence of the noise is investigated. In this example, noise is added such that the signal-to-noise ratio is 30dB. .. code-block:: tensorlab Tn = noisy(T, 30); Again, a MLSVD can be computed from this noisy tensor. The multilinear singular values are plotted in :num:`Figure #noisy-sv`. Estimating the multilinear rank is now a more difficult task. .. code-block:: tensorlab [Uen,Sen,sven] = mlsvd(Tn); for n = 1:3 subplot(1,3,n); semilogy(sven{n},'.-'); xlim([1 length(sve{n})]) end .. _noisy-sv: .. figure:: img/noisy-sv.* :alt: Multilinear singular values in the noisy case. :align: center :width: 95% Multilinear singular values in the noisy case. From the construction, we know that the multilinear rank is :math:`(2, 2, 3)`. We can only keep the respective vectors and part of the core tensor: .. code-block:: tensorlab Uentrunc{1} = Uen{1}(:,1:2); Uentrunc{2} = Uen{2}(:,1:2); Uentrunc{3} = Uen{3}(:,1:3); Sentrunc = Sen(1:2, 1:2, 1:3); The approximation error will not be zero now. The relative error is: .. code-block:: tensorlab format long frob(lmlragen(Uentrunc,Sentrunc)-Tn)/frob(Tn) .. code-block:: none :caption: lmlra-1 0.049896088936784 In contrast to the matrix case, this approximation may not be optimal in terms of relative Frobenius norm error, however. The ``lmlra`` method attempts to find the tensor of multilinear rank :math:`(2, 2, 3)` that best approximates :math:`\ten{T}` in a least squares sense. .. code-block:: tensorlab [Uopt, Sopt] = lmlra(Tn, [2 2 3]); We again compute the error: .. code-block:: tensorlab frob(lmlragen(Uopt,Sopt)-Tn)/frob(Tn) .. code-block:: none :caption: lmlra-2 0.049884982735855 The error has indeed improved. (For other tensors the difference may be more substantial.) The computational cost has increased, however. This cost can be somewhat reduced by taking the MLSVD solution as initialization: .. code-block:: tensorlab [Uopt, Sopt] = lmlra(Tn, Uentrunc, Sentrunc); The relative approximation error can also be improved by keeping more multilinear singular values, and hence by taking larger subspaces. .. code-block:: tensorlab Uentrunc2{1} = Uen{1}(:,1:3); Uentrunc2{2} = Uen{2}(:,1:3); Uentrunc2{3} = Uen{3}(:,1:3); Sentrunc2 = Sen(1:3, 1:3, 1:3); frob(lmlragen(Uentrunc2,Sentrunc2)-Tn)/frob(Tn) .. code-block:: none :caption: lmlra-3 0.042189469973458 While the error indeed decreases and the MLSVD is computationally cheaper than ``lmlra``, taking larger subspaces may not be desirable in particular applications, e.g., in multidimensional harmonic retrieval.