Using advanced Tensorlab features for ICA

Tags: lagged covariance matrices, sdf, nonnegativity, symmetry, missing elements, Toeplitz structure, imposing structure

Many signals can be modeled as a mixture of independent components. In its most basic form, independent component analysis (ICA) tries to estimate the independent components from such mixtures without prior knowledge of the signals or mixing coefficients. Though many methods for ICA use higher-order statistics to solve this problem, this demo will focus on approaches using second-order statistics. More information on methods for ICA can for instance be found in [3].

For basic ICA techniques, we refer to the demo Using basic Tensorlab features for ICA. In this demo, we will consider variants of second-order statistics based ICA that illustrate more advanced Tensorlab features. A Matlab implementation of this demo is given in the demo_advancedica.m file, which can be found in the demo folder of Tensorlab or downloaded here.

Instantaneous mixtures

An instantaneous mixture \(\vec{x}(t) \in \R^{Q}\) of \(R\) independent components \(\vec{s}(t) \in \R^{R}\) can be written as

\[\vec{x}(t) = \mat{M} \cdot \vec{s}(t) + \vec{n}(t),\]

in which \(\mat{M}\) contains the mixing coefficients. Temporally i.i.d. noise is captured by the additive noise term \(\vec{n}(t)\). Here, the sources are assumed to be temporally coherent. All results below are computed for a mixture of three sources with five observed signals. Each signal has \(10^4\) samples and the signal-to-noise ratio is \(10\) dB.

In our examples, the temporally coherent sources are generated by passing \(10^4\) i.i.d. samples from a standard normal distribution through a finite impulse response filter. The filter coefficients, the entries of the mixing matrix \(M\) and the additive noise are taken from a standard normal distribution as well. The noise is scaled to obtain the desired signal-to-noise ratio. In Matlab, this is done as follows:

% Parameters
Q = 5;              % nb outputs
R = 3;              % nb sources
K = 20;             % nb slices
N = 1e4;            % nb samples
SNR = 10;           % Signal to noise ratio in dB
filterlength = 21;  % Filter length for sources

% Generate signals
s = randn(N,R);
filt = randn(filterlength,R);
for r = 1:R
    s(:,r) = conv(s(:,r),filt(:,r),'same'); % temporally coherent sources
end
M = randn(Q,R);
x = s*M.'; % create mixture
x = noisy(x,SNR); % Additive Gaussian noise

By stacking lagged covariance matrices of the observations \(E\left\lbrace\vec{x}(t)\vec{x}(t+\tau)^{\T}\right\rbrace\), the tensor \(\ten{C}^{(2)}_{\vec{x}}\) shown in Figure 77 is obtained. Because the source covariance matrices are close to diagonal, the figure actually shows the approximate canonical polyadic decomposition (CPD) of \(\ten{C}^{(2)}_{\vec{x}}\). If this CPD is unique, its computation will return an estimate of the mixing matrix \(\mat{M}\). Since the mixture is overdetermined, the mixing matrix estimate can subsequently be used to estimate the original source signals as

\[\hat{\vec{s}}(t) = \mat{M}^{\dagger} \cdot \vec{y}(t).\]

The rest of this section will show how this CPD can be computed using advanced Tensorlab features. We focus on the implementation of the different types of structure, for which we use Tensorlab’s structured data fusion framework.

SOBI

Figure 77: Tensorizing the data by stacking lagged covariance matrices.

Without first slice

If infinitely many samples are available, the noise will only influence the diagonal of the covariance matrix with shift \(\tau = 0\), which is the diagonal of the first frontal slice. We could simply set this noisy diagonal to missing, as explained in the second-order statistics and missing values section in the basic ICA demo. Here, we will gradually build up an approach that uses more advanced Tensorlab features.

Our first approach is to drop the entire first slice and compute the CPD of the remaining tensor with lags \(\tau = \left\lbrace1,\ldots,K-1\right\rbrace\) instead of \(\tau = \left\lbrace 0,\ldots,K-1\right\rbrace\). First we compute this CPD without imposing any structure:

C2x = scov(x,1:K-1);
U = cpd(C2x,R);
cpderr(M,U{1})

which yields a relative error on \(\mat{M}\) of 2.347691e-02.

Figure 77 shows that the factor matrices in the first and second mode are both equal to \(\mat{M}\). This symmetry can be imposed in the structured data fusion framework.

First, the variables of the SDF algorithm need to be properly initialized. This can be done using the result of the unconstrained CPD, which has already been computed:

model.variables.M = U{1};
model.variables.C = U{3};

These variables can now be used to compose the factors that will appear in the decomposition:

model.factors.M = 'M';
model.factors.C = 'C';

In a next step, the tensor and the type of decomposition have to be specified. At this point, the symmetry is exploited by imposing that the factor matrices in the first two modes are both equal to M.

model.factorizations.example_cpdsym.data = C2x;
model.factorizations.example_cpdsym.cpd = {'M','M','C'};

It may be useful to verify the syntax and consistency of the model. This can be done using sdf_check, which indicates the correctness. The print option can be used to see the conversions made between variables, factors and factorizations:

sdf_check(model,'print')
sobi-1
Factor                   Size                 Comment
------------------------------------------------------------------------
M                        [5x3]
C                        [19x3]

Factorization            Type       Factors   Comments
------------------------------------------------------------------------
example_cpdsym (id = 1)  cpd        M,M,C

Finally, the model is computed using numerical optimization (we choose a nonlinear least squares method) and the relative estimation error of the result is determined:

sol = sdf_nls(model);
cpderr(M,sol.factors.M)

This approach leads to a relative error of 1.594028e-02, which is a slight improvement on the previous result. Note that, by default, the syntax and consistency of the model is always verified automatically when using the SDF algorithms such as sdf_nls and sdf_minf.

With first slice

In the previous approaches, the first tensor slice was dropped to get rid of the noisy values on its diagonal. Here, the first slice will be kept and the noise effects will be explicitly modeled. In this case, computation of a simple unconstrained CPD leads to suboptimal results:

C2x = scov(x,0:K-1);
U = cpd(C2x,R);
cpderr(M,U{1})

This yields a relative error of 2.095566e-02. Since only the diagonal of the first slice is perturbed, and actually not much, the effect on the result is limited.

Explicit modeling of the noise contributions may perhaps improve this result. Such additional modeling allows us to further illustrate Tensorlab’s SDF framework.

First, the variables need to be initialized. Prior information can be used for this purpose, if it is available. Here, the results of the unconstrained CPD are re-used. To capture the standard deviations of the noise, an extra variable noise is added, initialized with random positive values.

model.variables.M = U{1};
model.variables.C = U{3};
model.variables.noise = rand(Q,1);

Construction of the factors requires some mathematical insight into the problem. The goal is to add a diagonal matrix holding noise variances to the first frontal slice of the tensor. Mathematically, we would like to construct

\[\mat{C}_{\vec{x}}^{(2)} = \mat{M} \mat{C}_{\vec{s}}^{(2)} \mat{M}^T + \Sigma_n^2\]

as the first frontal slice of \(\ten{C}_{\vec{x}}^{(2)}\).

One can start by placing the variable noise, containing the noise standard deviations \(\sigma_{n_q}\), in a diagonal matrix:

\[\begin{split}\mat{\Sigma}_n = \begin{bmatrix} \sigma_{n_1} & 0 & 0\\ 0 & \ddots & 0\\ 0 & 0 & \sigma_{n_Q}\end{bmatrix}.\end{split}\]

To obtain a matrix with variances on the diagonal, the matrix above can be used as factor matrix in the first and second mode, leading to

\[\begin{split}\begin{bmatrix} \sigma_{n_1} & 0 & 0\\ 0 & \ddots & 0\\ 0 & 0 & \sigma_{n_Q}\end{bmatrix} \cdot \begin{bmatrix} \sigma_{n_1} & 0 & 0\\ 0 & \ddots & 0\\ 0 & 0 & \sigma_{n_Q}\end{bmatrix}^{\T} = \begin{bmatrix} \sigma^2_{n_1} & 0 & 0\\ 0 & \ddots & 0\\ 0 & 0 & \sigma^2_{n_Q}\end{bmatrix}\end{split}\]

To integrate this diagonal perturbation in the decomposition, the factors in the first two modes can be concatenated, i.e., instead of the factor matrix \(\mat{M}\), the matrix \([\mat{M}, \mat{\Sigma}_n]\) is used. However, the perturbation must only appear in the first frontal slice. This can be achieved by appending a matrix with ones in the first row and zeros elsewhere to the factor matrix in the third mode, yielding

\[\begin{split}\begin{bmatrix} c_{11} & c_{12} & \cdots & c_{1R} & 1 & 1 & \cdots & 1\\ c_{21} & c_{22} & \cdots & c_{2R} & 0 & 0 & \cdots & 0\\ \vdots & \vdots & & \vdots & \vdots & \vdots & & \vdots\\ c_{K1} & c_{K2} & \cdots & c_{KR} & 0 & 0 & \cdots & 0 \end{bmatrix}\end{split}\]

as factor matrix in the third mode.

The Matlab implementation of the explanation above is quite straightforward. To construct a diagonal factor (sub)matrix from the variable noise, the struct_diag-function can be used:

diagmat = @(z,task)struct_diag(z,task);
model.factors.M = {'M',{'noise',diagmat}};
model.factors.C = {'C',[ones(1,Q); zeros(K-1,Q)]};

Note that concatenating in SDF is similar as in standard Matlab notation: a comma represents horizontal concatenation and a semicolon represents vertical concatenation. The rest of the procedure is the same as above: the data and the decomposition are specified, and the model is fitted using a nonlinear least squares method.

model.factorizations.example_cpdnoisemodel.data = C2x;
model.factorizations.example_cpdnoisemodel.cpd = {'M','M','C'};
sol = sdf_nls(model,'MaxIter',500);
cpderr(M,sol.factors.M)

At the cost of a more complicated model, a more accurate estimate with a relative error of 1.044207e-02 is obtained in this case.

An alternative approach is to denote possibly unreliable values as missing. As mentioned earlier, the i.i.d. noise only affects the diagonal of the first frontal slice of the tensor \(\ten{C}^{(2)}_{\vec{x}}\) for long enough data sets. It thus suffices to denote these elements on the first diagonal as missing:

C2xmiss = C2x;
for q = 1:Q
    C2xmiss(q,q,1) = NaN;
end

Constrained CPDs of incomplete tensors can be computed in the same way as those of full tensors. For instance, symmetry can be imposed as follows:

model.variables.M = U{1};
model.variables.C = U{3};
model.factors.M = {'M'};
model.factors.C = {'C'};
model.factorizations.example_cpdmissing.data = C2xmiss;
model.factorizations.example_cpdmissing.cpd = {'M','M','C'};
sol = sdf_minf(model,'MaxIter',500);
cpderr(M,sol.factors.M)

This results in a relative estimation error of 2.021610e-02.

With prewhitening

In the original SOBI-method, the covariance of the observed signals without shift is used to prewhiten the data [5].

[E,D] = eig(cov(x));
z = (E*abs(D)^(-1/2)*E.'*(x.')).';

After this transformation, the tensor with covariance slices has orthogonal factor matrices in the first and second mode. In the SDF-framework, this orthogonality can be imposed as well. First, the variables are initialized:

model.variables.M = randn(R*(Q - (R-1)/2),1);
model.variables.C = randn(K,R);

Columnwise orthonormal matrices of size \(Q \times R\) are fully determined by \(R(Q - (R-1)/2)\) variables, hence the size of the initialization vector. In a next step, the variables are mapped to a columnwise orthonormal factor matrix, using the struct_orth function:

ortho = @(z,task)struct_orth(z,task,[Q R]);
model.factors.M = {'M',ortho};
model.factors.C = {'C'};

Next, the data and factorization are specified and the model is computed:

model.factorizations.example_cpdprewhit.data = C2x;
model.factorizations.example_cpdprewhit.cpd = {'M','M','C'};
sol = sdf_nls(model,'MaxIter',500);

Taking into account the prewhitening, it is found that the relative estimation error is 3.009932e-02.

Mest = E*abs(D)^(1/2)*E.'*sol.factors.M;
cpderr(M,Mest)

Nonstationary sources

We now consider an instantaneous mixture of nonstationary independent source signals

\[\vec{x}(t) = \mat{M} \cdot \vec{s}(t),\]

in which \(\vec{x}(t)\) are the observed mixtures, \(\mat{M}\) contains the mixing coefficients, and \(\vec{s}(t)\) represent the nonstationary independent sources. For simplicity, we assume that there is no additive noise. Here, we do not assume that the sources are temporally coherent, but that they are nonstationary.

To identify mixtures of such nonstationary source signals, the nonstationarity can be exploited in a similar way as the temporal coherence in the example before. To do this, a tensor-based version of the method presented in [6] will be used.

First, the observed signals are divided into segments, assuming that the source statistics can approximately be considered constant over each segment. For the \(k\) th segment, computing the covariance yields

\[\mat{C}_{\vec{x}_k} = \mat{M} \cdot \mat{C}_{\vec{s}_k} \cdot \mat{M}^{\T}.\]

The matrices \(\mat{C}_{\vec{s}_k}\) are diagonal due to the independence of the inputs. By stacking the observed covariance matrices, a third-order tensor is obtained.

% Segment signals and compute covariances
Xs = segmentize(x,'segsize',N/K);
C2x = dcov(Xs,'dims',[1 3],'perm',true);

The factor matrices of the CPD in the first and second mode are again both equal to \(\mat{M}\). The factor matrix in the third mode contains the source variances. Since these are always positive, it makes sense to impose nonnegativity on this factor matrix. In Tensorlab, nonnegativity can be imposed on a variable using the struct_nonneg structure:

model.variables.M = randn(Q,R);
model.variables.C = rand(K,R);
model.factors.M = 'M';
model.factors.C = {'C',@struct_nonneg};
model.factorizations.example_cpdnonneg.data = C2x;
model.factorizations.example_cpdnonneg.cpd = {'M','M','C'};
sol = sdf_nls(model,'MaxIter',500,'TolFun',1e-8);
cpderr(M,sol.factors.M)

This procedure leads to an estimation error of 1.186503e-01 for a mixture of three sources with five observed signals and with signals of length \(10^4\) samples and a signal-to-noise ratio of \(10\) dB.

Convolutive mixtures

A convolutive mixture of \(R\) sources \(s_r(t)\) in \(M\) measurements \(x_m(t)\) can be written as

\[x_m(t) = \sum_{r = 1}^{R} \sum_{l = 0}^{L} h_{mr}(l) s_r(t-l) \qquad \text{for } m = 1,\ldots,M,\]

in which \(h_{mr}(l)\) represents the convolutive mixing filter from input \(r\) to output \(m\) and \(L\) is the maximum filter delay (which implies that the filter length is \(L+1\)). We assume for simplicity that there is no additive noise. To write this relation as a matrix product, first construct

\[\begin{split}\vec{s}(n) &= \left[s_1(n), \ldots, s_1(n-(L+L')+1),\ldots,s_R(n-(L+L')+1)\right]^{\T}\\ \vec{x}(n) &= \left[x_1(n), \ldots, x_1(n-L'+1),\ldots,x_M(n),\ldots,x_M(n-L'+1)\right]^{\T},\end{split}\]

with \(L'\) chosen so that \(M L' \geq R (L + L')\). The mixture can now be written as \(\vec{x}(n) = \mat{H} \cdot \vec{s}(n)\), in which \(\mat{H}\) is a Toeplitz-block matrix given by

\[\begin{split}\mat{H} = \begin{bmatrix} \mat{H}_{11} & \cdots & \mat{H}_{1R}\\ \vdots & \ddots & \vdots\\ \mat{H}_{M1} & \cdots & \mat{H}_{MR} \end{bmatrix} \in \R^{ML' \times R(L+L')}\end{split}\]

with blocks

\[\begin{split}\mat{H}_{ij} = \begin{bmatrix} h_{ij}(0) & \cdots & h_{ij}(L) & \cdots & 0 \\ & \ddots & \ddots & \ddots & \\ 0 & \cdots & h_{ij}(0) & \cdots & h_{ij}(L) \end{bmatrix} \in \R^{L' \times (L+L')}.\end{split}\]

Note that the choice of \(L'\) implies that \(\mat{H}\) will always have at least as many rows as columns.

Now, a similar approach as in the instantaneous case can be used. By stacking lagged covariance matrices of the outputs \(E\left\lbrace\vec{x}(t)\vec{x}(t+\tau)^{\T}\right\rbrace\), the tensor shown in Figure 78 is obtained. This tensor can be decomposed using a block term decomposition in multilinear rank-\((L+L',L+L',\cdot)\) terms. In Figure 78, the matrix \(\mat{H}_k\) represents the \(k\) th block column of \(\mat{H}\) and the core tensors are formed by the block diagonals of the covariances of \(\vec{s}(n)\). This decomposition can be computed using the SDF-framework of Tensorlab.

SOBI

Figure 78: Stacking the lagged covariance matrices for convolutive mixtures leads to a block-term decomposition in rank-\((L+L',L+L',\cdot)\) terms.

First, the filter coefficients for each submatrix of \(\mat{H}\) and the core tensors have to be initialized. For a mixture of two sources having three outputs, this is done by:

model.variables.H11 = randn(L+1,1);
model.variables.H21 = randn(L+1,1);
model.variables.H31 = randn(L+1,1);
model.variables.H12 = randn(L+1,1);
model.variables.H22 = randn(L+1,1);
model.variables.H32 = randn(L+1,1);
model.variables.Core1 = randn(L+Lacc,L+Lacc,K);
model.variables.Core2 = randn(L+Lacc,L+Lacc,K);

Note that the parameter \(L'\) is represented by Lacc. Next, the Toeplitz structure of the submatrices \(\mat{H}_{ij}\) is implemented. As explained in the documentation of struct_toeplitz, it is possible to pass along known diagonals under or above the sought ones. Here, the fact that the first and last \(L'-1\) diagonals of \(\mat{H}_{ij}\) are zero, is taken into account in:

toepl = @(z,task)struct_toeplitz(z,task,[Lacc L+Lacc], ...
zeros(Lacc-1,1),zeros(Lacc-1,1));

This code will provide a structure that pads the variable z with \(L'-1\) zeros at both ends and then uses these elements for the diagonals of a Toeplitz matrix. The rest of the code is similar to the previous examples: the structure is imposed when creating the factors, the data and decomposition are specified, and the model is computed:

model.factors.H1 = {{'H11',toepl};{'H21',toepl};{'H31',toepl}};
model.factors.H2 = {{'H12',toepl};{'H22',toepl};{'H32',toepl}};
model.factors.Core1 = {'Core1'};
model.factors.Core2 = {'Core2'};
model.factors.C = eye(K);
model.factorizations.example_btdconv.data = T;
model.factorizations.example_btdconv.btd = {{'H1','H1','C','Core1'},
                                            {'H2','H2','C','Core2'}};
options = struct;
options.Display = 50;
options.MaxIter = 500;
options.TolFun = 1e-8;
options.TolX = 1e-8;
sol = sdf_minf(model,options);

Pest = [sol.variables.H11, sol.variables.H12; sol.variables.H21,...
    sol.variables.H22; sol.variables.H31, sol.variables.H32];

cpderr(P,Pest)

Because there is no factor matrix in the third mode, an identity matrix is used in that mode. The matrices Pest and P are constructed to easily compare the computed solution to the real one. The obtained accuracy is 1.033602e-02 when the signals have \(10^4\) samples and the signal-to-noise ratio is \(20\) dB in a mixture of two sources having three outputs and \(L = 1, L' = 2\).