.. _demo-ica: Using basic Tensorlab features for ICA ============================================== **Tags:** ``lagged covariance matrices``, ``fourth-order cumulant``, ``missing elements`` .. This demo deals with the separation of linear mixtures of source signals, known as blind signal separation (BSS). The general solution to this problem is not unique and various approaches have been proposed, ranging from applying independence assumptions to non-negativity and sparsity constraints [1]. This demo illustrates the use of basic tensor tools in the context of independent component analysis (ICA). We consider an ICA variant that uses lagged covariance matrices and a variant that relies on a fourth-order cumulant. The demo also illustrates the decomposition of incomplete tensors. In this demo, we do not exploit structure such as symmetry, or orthogonality after prewhitening. The demo :ref:`demo-sobi` goes a step further and illustrates the use of the structured data fusion framework to impose constraints. More information on methods for ICA can for instance be found in :cite:`comon2010handbook`. A Matlab implementation of this demo is given in the ``demo_basicica.m`` file, which can be found in the demo folder of Tensorlab or downloaded `here `_. Instantaneous mixtures ----------------------- An instantaneous mixture :math:`\vec{x}(t) \in \R^{Q}` of :math:`R` independent components :math:`\vec{s}(t) \in \R^{R}` can be written as .. math:: \vec{x}(t) = \mat{M} \cdot \vec{s}(t) + \vec{n}(t), in which :math:`\mat{M}` contains the mixing coefficients and temporally i.i.d. noise is captured by the additive noise term :math:`\vec{n}(t)`. We consider two auxiliary signals that are identically uniformly distributed over :math:`[-1,1]`. Eeach signal has :math:`10^4` samples. The two actual source signals are generated by passing these auxiliary signals through finite impulse response filters with coefficients :math:`[-1,1,1]` and :math:`[1,1,1]`, respectively: .. code-block:: tensorlab N = 10000; R = 2; Saux = rand(N,R)*2-1; S(:,1) = filter([-1 1 1],1,Saux(:,1)); S(:,2) = filter([1 1 1],1,Saux(:,2)); :num:`Figure #icahists` shows the source histograms. The samples are confined to the interval :math:`[-3,3]`. The mixing matrix is taken equal to .. math:: \mat{M} = \begin{bmatrix} 1/\sqrt{2} & 2/\sqrt{5}\\ -1/\sqrt{2} & 1/\sqrt{5}\end{bmatrix}. Independent identically distributed Gaussian noise is added with a signal-to-noise-ratio of 10 dB: .. code-block:: tensorlab M = [1/sqrt(2) 2/sqrt(5); -1/sqrt(2) 1/sqrt(5)]; X = S*M.'; SNR = 10; Xnoisy = noisy(X,SNR); .. _icahists: .. figure:: img/ica-hists.* :align: center :width: 80% Histogram of the source samples. Second-order statistics ------------------------------------ Consider a tensor :math:`\ten{C}^{(2)}_x` of which the slices are lagged covariance matrices. This tensor can be generated with the ``scov`` command: .. code-block:: tensorlab lags = [0 1 2]; C2x = scov(Xnoisy,lags); Each observed lagged covariance matrix equals the corresponding lagged covariance matrix of the source signals, multiplied by the mixing matrix in the first and second mode. As the lagged covariance matrices of the source signals are approximately diagonal, the tensor is approximately low-rank, as illustrated in :num:`Figure #icafig1`. .. _icafig1: .. figure:: img/sobi-ica-basic.* :align: center :width: 60% Tensorizing the data by stacking lagged covariance matrices. The mixing matrix can be recovered by decomposing :math:`\ten{C}^{(2)}_x` in a minimal number of rank-1 terms. We use the basic ``cpd`` command without exploiting the symmetry; hence, two estimates of the mixing matrix are obtained: .. code-block:: tensorlab Uest = cpd(C2x,R); Mest_mode1 = Uest{1}; Mest_mode2 = Uest{2}; Since the mixing matrix is square non-singular, the source signals can subsequently be estimated as .. math:: \hat{\vec{s}}(t) = \mat{M}^{-1} \cdot \vec{y}(t). The ``cpderr`` command can be used to compute the relative error on the estimates of the mixing matrix, and to fix the indeterminacies for visualization purposes: .. code-block:: tensorlab [err_scov_mode1,P1,D1,Mestscaled] = cpderr(M,Mest_mode1) [err_scov_mode2,P2,D2] = cpderr(M,Mest_mode2) Srec = Xnoisy*pinv(Mestscaled.'); The joint distributions of the signals are visualized in :num:`Figure #ica12plot`. The joint distribution of the source signals is confined to the square :math:`[-3,3]\times [-3,3]`, and the components vary independently along the horizontal and vertical axis according to their distribution function (cf. :num:`Figure #icahists`). The edges of the figure in the middle illustrate that the observed signals cannot take values independent of one another. As a matter of fact, the observed joint distribution is equal to the joint distribution of the source signals, linearly transformed by the mixing matrix :math:`\mat{M}`. The axes correspond to the columns of the identity matrix (left), the mixing matrix :math:`\mat{M}` (middle), and the matrix :math:`\tilde{\mat{M}}^{-1}\cdot\mat{M}` (right), with :math:`\tilde{\mat{M}}` the estimate of :math:`\mat{M}`. The figure on the right shows that the estimated source signals are close to independent. .. _ica12plot: .. figure:: img/ica-overview-signals.* :align: center :width: 90% Visualization of the joint distributions of the source signals (left), the observed signals (middle) and the estimated source signals (right). The axes correspond to the columns of the identity matrix (left), the mixing matrix :math:`\mat{M}` (middle), and the matrix :math:`\tilde{\mat{M}}^{-1}\cdot\mat{M}` (right), with :math:`\tilde{\mat{M}}` the estimate of :math:`\mat{M}`. Fourth-order statistics ------------------------------------ Consider the fourth-order cumulant :math:`\ten{C}^{(4)}_x` of the observed signals, which can be computed using the ``cum4`` command: .. code-block:: tensorlab C4x = cum4(Xnoisy); The fourth-order cumulant of the sources is approximately diagonal because of the mutual statistical independence; hence, the tensor :math:`\ten{C}^{(4)}_x` can be decomposed in rank-1 terms as follows: .. math:: \ten{C}^{(4)}_x \approx \ten{C}^{(4)}_s \cdot_1 \mat{M} \cdot_2 \mat{M} \cdot_3 \mat{M} \cdot_4 \mat{M} = \cp{\ten{C}^{(4)}_s;\mat{M},\mat{M},\mat{M},\mat{M}}, with :math:`\ten{C}^{(4)}_s = \text{diag}_4(c_{s_1}^{(4)},c_{s_2}^{(4)},\ldots,c_{s_R}^{(4)})`. All four factor matrices are equal to the mixing matrix. We only use the first factor matrix as an estimate: .. code-block:: tensorlab Uest = cpd(C4x,R); Mest_mode1 = Uest{1}; [err_cum,P,D] = cpderr(M,Mest_mode1) .. A relative error of 0.0570 on the mixing matrix is obtained. .. _demo-ica-missingvalues: Second-order statistics and missing values ------------------------------------------ If infinitely many samples are available, the i.i.d. Gaussian noise only affects the values on the diagonal of the covariance matrix for lag zero. These entries can be omitted from the tensor :math:`\ten{C}^{(2)}_x` as follows: .. code-block:: tensorlab C2xi = C2x; for i = 1:size(C2x,1) C2xi(i,i,1) = NaN; end The ``cpd`` command can be used to decompose the incomplete tensor ``C2xi``: .. code-block:: tensorlab Uest = cpd(C2xi,R); Mest_mode1 = Uest{1}; [err_scovi,P,D] = cpderr(M,Mest_mode1) The demo :ref:`demo-sobi` elaborates on noise modeling using advanced Tensorlab features. .. This can be advantage in the case of equal number of source signals and observed signals, i.e., when the variance of the noise cannot be estimated beforehand. .. Furthermore, if only a single observed signal is (heavily) perturbed by noise, only its corresponding variance on the diagonal of the unshifted covariance matrix should be omitted. .. A relative error of 0.0086 is obtained after decomposing :math:`\ten{C}^{(4)}_x` with ``cpd``, which is lower than when all second-order statistics are used. .. Note that a likewise procedure can be performed for the fourth-order ICA method by omitting the diagonal entries from the fourth-order cumulant.