15

I am currently creating different signals using Matlab, mixing them by multiplying them by a mixing matrix A, and then trying to get back the original signals using FastICA.

So far, the recovered signals are really bad when compared to the original ones, which was not what I expected.

I'm trying to see whether I'm doing anything wrong. The signals I'm generating are the following:

s1 = (-x.^2 + 100*x + 500) / 3000; % quadratic
s2 = exp(-x / 10); % -ve exponential
s3 = (sin(x)+ 1) * 0.5; % sine
s4 = 0.5 + 0.1 * randn(size(x, 2), 1); % gaussian
s5 = (sawtooth(x, 0.75)+ 1) * 0.5; % sawtooth

Original Signals

One condition for ICA to be successful is that at most one signal is Gaussian, and I've observed this in my signal generation.

However, another condition is that all signals are statistically independent.

All I know is that this means that, given two signals A & B, knowing one signal does not give any information with regards to the other, i.e.: P(A|B) = P(A) where P is the probability.

Now my question is this: Are my signals statistically independent? Is there any way I can determine this? Perhaps some property that must be observed?

Another thing I've noticed is that when I calculate the eigenvalues of the covariance matrix (calculated for the matrix containing the mixed signals), the eigenspectrum seems to show that there is only one (main) principal component. What does this really mean? Shouldn't there be 5, since I have 5 (supposedly) independent signals?

For example, when using the following mixing matrix:

A =

0.2000    0.4267    0.2133    0.1067    0.0533
0.2909    0.2000    0.2909    0.1455    0.0727
0.1333    0.2667    0.2000    0.2667    0.1333
0.0727    0.1455    0.2909    0.2000    0.2909
0.0533    0.1067    0.2133    0.4267    0.2000

The eigenvalues are: 0.0000 0.0005 0.0022 0.0042 0.0345 (only 4!)

When using the identity matrix as the mixing matrix (i.e. the mixed signals are the same as the original ones), the eigenspectrum is: 0.0103 0.0199 0.0330 0.0811 0.1762. There still is one value much larger than the rest..

Thank you for your help.

I apologise if the answers to my questions are painfully obvious, but I'm really new to statistics, ICA and Matlab. Thanks again.

EDIT

I have 500 samples of each signal, in the range [0.2, 100], in steps of 0.2, i.e. x = 0:0.1:100.

Also, given the ICA Model: X = As + n (I'm not adding any noise at the moment), I am referring to the eigenspectrum of the transpose of X, i.e. eig(cov(X')).

UPDATE

As suggested (refer to comments), I tried FastICA on only 2 signals. The results were quite good (see pic below). The mixing matrix used was A = [0.75 0.25; 0.25 0.75]. However, the eigenspectrum 0.1657 0.7732 still showed only one main principal component.

My question therefore boils down to the following: What function/equation/property can I use to check whether a number of signal vectors are statistically independent?

Sine & Gaussian - FastICA

Rachel
  • 311
  • 4
  • 8
  • 1
    Excellent question. I has asked about how we can know when two signals are independent here (http://dsp.stackexchange.com/questions/1242/examples-of-independent-and-uncorrelated-data-in-real-life-and-ways-to-measure) but didnt get too far with that. :-) I am also new to ICA but I might be able to shed some light. – Spacey Feb 21 '12 at 16:44
  • @Mohammad Are you still interested in a response to that question? I'll gladly put a bounty on it to attract interest. – Phonon Feb 21 '12 at 17:23
  • @Mohammad I upvoted your question. Hope you get a good answer, it's really related to mine. I've been reading the comments on it so far, and there's a lot of statistics going on that I don't understand. Have you managed to come up with a definite way to conclude whether two signals are independent or not? – Rachel Feb 22 '12 at 11:42
  • @Rachel Not yet at the moment, but I will research it some more and let you know. It is a very important concept, one that I feel is usually glazed over unfortunately. – Spacey Feb 22 '12 at 18:10
  • Thank you @Mohammad. I agree. Independent signals observe the property that E(s1, s2) = E(s1) x E(s2), but I don't know how to actually calculate it for real signals. – Rachel Feb 22 '12 at 18:22
  • @Rachel The gaussian is the only statistical (i.e. random) signal in the bunch. The others are all completely deterministic. I'm not sure how meaningfully you can even talk about concepts like "independence" with a set like this. – Jim Clay Feb 28 '12 at 01:59
  • @JimClay There seems to be some confusion (conflicting terminology) between what ICA considered 'independent' and what statisticians are saying is independent. ICA can separate a sin and another sin wave because 'they are independent'. How does this square with the definition of independence? – Spacey Feb 28 '12 at 05:18
  • @JimClay, we must talk about independence because it is one of the requirements for ICA. ICA can unmix a mixture of signals given that: there are at least as many observed signals as there are original signals, at most one is Gaussian, and ALL SIGNALS ARE STATISTICALLY INDEPENDENT. The first two conditions are easy to observe, but what about the last one?? – Rachel Feb 28 '12 at 10:46
  • @Mohammad I will echo a comment that Dilip Sarwate made in another thread. Deterministic signals are independent because knowing about one does not tell you anything about the other. You can know that you are generating independent signals by using separate "rand" calls, assuming you don't do something like seed them the same before every call. After that all you have to do is make sure that only one of them is gaussian distributed. – Jim Clay Feb 28 '12 at 14:20
  • @JimClay Yes, I understand that. But from what I read earlier, there was some chatter about 'how can you even say they are independent when they arent even random variables to begin with'. This I think is the source of the confusion. – Spacey Feb 28 '12 at 17:19
  • @Mohammad As the presumed source of the "chatter" -- which I regard as an insultingly pejorative usage -- let me remind you that what I said was "Your statement "Now two vectors are said to be statistically independent if E(X Y) = E(X) * E(Y), where E is the expectation operator." is incorrect on several counts. Unless your vectors are vectors of random variables, there is no expectation operator that you can use." In that comment, I did not say anything about independence of nonrandom quantities, only about independence of random variables. – Dilip Sarwate Mar 03 '12 at 15:11
  • @DilipSarwate ... Wow! - relax - It was not meant as an insult! By chatter I meant the general discussions going around on different Qs! Take it easy... no one is attacking you. – Spacey Mar 03 '12 at 18:38

4 Answers4

9

Signals 3 and 5 appear to be quite correlated -- they share their first harmonic. If I were given two mixtures of those, I wouldn't be able to separate those, I'd be tempted to put the common harmonic as one signal and the higher harmonics as a second signal. And I would be wrong! This might explain the missing eigenvalue.

Signals 1 and 2 do not look independent too.

A quick and dirty "sanity-check" for the independence of two series is to do a (x, y) plot of one signal against the other:

plot (sig3, sig5)

and then to do the same (x, y) plot with one signal shuffled:

indices = randperm(length(sig3))
plot(sig3(indices), sig5)

If the two plots have a dissimilar look, your signals are not independent. More generally, if the (x, y) plot of the data shows "features", disymmetries etc, it's a bad omen.

Proper tests for independence (and those are the objective functions used in the ICA optimization loop) include, for example, mutual information.

ICA is recovering the most independent signals a linear mixing of which yields your input data. It will work as a signal separation methods and recover the original signals only if those were maximally independent according to the optimization criterion used in your ICA implementation.

pichenettes
  • 19,413
  • 1
  • 50
  • 69
  • 1
    Question: If the 5 signals in her case were in fact all independent, then we would expect there to be NO principal components correct? (In other words, all eigenvalues would be sort of the same). Geometrically, we would have a guassian 'cloud' in 5 dimensions, agree? – Spacey Feb 21 '12 at 18:14
  • I had also contacted an author on ICA about the removal of two sinusoids from a mixture, and he said that it could in fact be done with ICA. This confuses me a little bit based on what you are saying with regards to signals 3 and 5 because (I agree with you) they do look correlated. – Spacey Feb 21 '12 at 18:17
  • @pichenettes I plotted those graphs as you suggested - and the plots do indeed have a dissimilar look. Unfortunately I'm still stuck as to how test for independence. I really need a way to generate signals which are statistically independent, so that I can evaluate the performance of FastICA. – Rachel Feb 22 '12 at 11:51
  • @Rachel Perhaps one fast thing you can try at the moment to make statistically independent signals is the following: Record your voice saying something. (In MATLAB, you can use 'wavrecord' command). Save that vector, $x_1[n]$ Then make a second recording of some music playing. Save that as $x_2[n]$. Now apply your mixing matrix and see if FastICA can separate them. Maybe you edit your question to show some results for us. Im curious. :-) – Spacey Feb 22 '12 at 18:33
  • @Mohammad I didn't record my own voice but I tried using FastICA on a mixture of Sinusodial and Gaussian signals. I'd THINK they are independent.. FastICA performed quite good but the eigenspectrum was still weird. I'll update my question to show the results. – Rachel Feb 25 '12 at 11:19
  • @Rachel Wow that looks great and looks encouraging! Yes, sine wave would be independent of gaussian because knowing a current value of a gaussian will tell you 0 information on that value of the sine. Try this experiment on two sinusoids next - what do you get? – Spacey Feb 25 '12 at 18:08
  • @Rachel Also as far as the eigenspecturm, plot the sine against the gaussian and see if there is a pattern. If there is some 'skewness' then I would expect one eigen value to be more than the other, as your results have shown. So, plot sine on the x axis, and gaussian on the y, and also put that up so we can see. – Spacey Feb 25 '12 at 20:33
9

I'm not an expert on ICA, but I can tell you a little bit about independence.

As some of the comments have mentioned, statistical independence between two random variables can be roughly interpreted as "the amount of information that observing one variable gives about another".

However, because we're talking about statistical independence, all of this is with respect to a distribution. In particular, if you observe two random variables $X$ and $Y$, independence of $X$ and $Y$ is equivalent to a condition on their joint distribution $p(x,y)$. In particular, $X$ and $Y$ are independent if and only if $p(x,y) = p(x)p(y)$.

This condition is basically what an earlier comment suggested that you use. Plotting a scatter plot of the two variables is a kind of visualization of the joint distribution $p(x,y)$. When two variables are independent, permuting the observations should give the same underlying joint distribution.

There are lots of ways to test for independence. In practice (say, to draw scientific conclusions), you might like a careful hypothesis test that allows you to state your assumptions and the confidence of your conclusions (like the chi-square test). I'll ignore that here, and assume you have perfect information about your distributions. Then, note that the mutual information between $X$ and $Y$ is zero exactly when $X$ and $Y$ are independent. To compute the mutual information, let your joint distribution be $p(X=i, Y=j) = p_{ij}$, and $P(X=i) = p_i$ and $P(Y=j) = p_j$ be your marginals. Then,

$I(X,Y) = \sum_i \sum_j p_{ij} \log \frac{p_{ij}}{p_i p_j}$

Here's some matlab code that will generate two independent signals from a constructed joint distribution, and two from a non-independent joint distribution, and then compute the mutual information of the joints.

The function "computeMIplugin.m" is a simple function I wrote that computes the mutual information using the summation formula above.

Ndist = 25;
xx = linspace(-pi, pi, Ndist);

P1 = abs(sin(xx)); P2 = abs(cos(xx)); 
P1 = P1/sum(P1); P2 = P2/sum(P2); % generate marginal distributions

%% Draw independent samples.
Nsamp = 1e4;
X = randsample(xx, Nsamp, 'true', P1);
Y = randsample(xx, Nsamp, 'true', P2);

Pj1 = P1'*P2;
computeMIplugin(Pj1)

% I get approx 8e-15 ... independent!

% Now Sample the joint distribution 
cnt = {}; cnt{1} = xx; cnt{2} = xx; % bin centers
Pj1_samp= hist3([X' Y'],cnt); Pj1_samp = Pj1_samp/sum(Pj1_samp(:));
computeMIplugin(Pj1_samp)
% I get approx .02; since we've estimated the distribution from
% samples, we don't know the true value of the MI. This is where
% a confidence interval would come in handy. We'd like to know 
% whether value of MI is significantly different from 0. 

% mean square difference between true and sampled?
% (this is small for these parameter settings... 
% depends on the sample size and # bins in the distribution).
mean( (Pj1_samp(:) - Pj1(:)).^2)

%% Draw samples that aren't independent. 

tx = linspace(0,30,Nsamp);
X = pi*sin(tx);
Y = pi*cos(tx);

% estimate the joint distribution
cnt = {}; cnt{1} = xx; cnt{2} = xx; % bin centers
Pj2= hist3([X' Y'],cnt); Pj2 = Pj2/sum(Pj2(:));
computeMIplugin(Pj2)

% I get 1.9281  - not independent!

%% make figure
figure(1); 
colormap gray
subplot(221)
imagesc(xx,xx,Pj1_samp)
title('sampled joint distribution 1')
subplot(222)
imagesc(xx,xx,Pj2)
title('sampled joint distribution 2')
subplot(223)
imagesc(xx,xx,Pj1)
title('true joint distribution 1')

Again, this assumes you have a good estimate of the joint distribution (along with other blithe assumptions), but it should be useful as a rule of thumb.

yep
  • 297
  • 1
  • 2
  • Thats a good answer sydeulissie thanks, Ill have to look into it a little deeper. – Spacey Mar 03 '12 at 19:18
  • First of all, thank you for the lengthy answer, it was very informative. I just have a couple of questions. You mentioned using a chi-squared test. I've looked into it and looks really interesting, but how can I use it on signals? Can't it only be applied to categorical data? – Rachel Mar 05 '12 at 12:33
  • Also, you are using Pj1 = P1'*P2 to calculate the joint distribution, correct? But, technically, I believe this cannot be done. Maybe you're doing it 'cause you're assuming that the original signals are independent, and the result thus holds? But how can you then calculate the mutual information - since it's result depends on the joint distribution..? It may be that I have misunderstood something, but I'd like a clarification, please. – Rachel Mar 05 '12 at 12:37
  • I'll be happy to - though it'll be a bit before I get the time :). – yep Mar 08 '12 at 20:56
  • Thank you @sydeulissie. I would like an answer which does not assume that I have knowledge of the joint distribution, please. – Rachel Mar 10 '12 at 12:04
  • @Rachel - You're right that I'm computing the joint using P1'P2 because* I've constructed the two signals to be independent. When two variables are independent, the joint distribution is just the product of their marginals. I've modified the code slightly to compute the empirical joint in the independent case; with enough samples, they will be arbitrarily close. – yep Mar 11 '12 at 03:02
  • Thanks @sydeulissie, that makes much more sense. Would you mind posting the code for the computeMIplugin function, please? I've written my own but I must have some huge bug 'cause I'm getting weird answers like negative and complex numbers. Not only should MI by real, but it should also always be positive! Thank you. – Rachel Mar 11 '12 at 21:58
  • @sydeulissie You can have a look at what I did over here. – Rachel Mar 11 '12 at 22:35
  • @sydeulissie No need to post any code for calculating the MI - I've managed. Thanks anyway. – Rachel Mar 22 '12 at 13:55
4

As mentioned above, both signals 3 and 5 appear to be quite correlated and have a similar period.

We can think of two signals being correlated if we can shift one of the sources left or right and increase or decrease its amplitude so that it fits on top of the other source. Note we are not changing the frequency of the source, we are just performing a phase and amplitude shift.

In the above case, we can shift source 3 so that its peaks coincide with source 5. This is the sort of thing that will mess source extraction when using ICA due to the independence assumption.

Note: A nice illustration of the above concept is to think of two sinusoidal waves. These are both completely deterministic. If they both have the same frequency (even with different phase) then they are perfectly correlated and ICA will not be able to separate them. If instead they have different frequencies (that are not integer multiples of one another), then they are independent and can be seperated.

Below is some Matlab code for you to see this for yourself

%Sine waves of equal frequency
X = 1:1000;
Y(1,:) = sin(2*pi*X*10/1000);
Y(2,:) = sin(1+2*pi*X*10/1000);

figure
subplot(3,2,1)
plot(Y(1,:))
title('Initial Source 1')
subplot(3,2,2)
plot(Y(2,:))
title('Initial Source 2')
A = [1, 2; 4, -1];
Y = A*Y;
subplot(3,2,3)
plot(Y(1,:))
title('Signal 1')
subplot(3,2,4)
plot(Y(2,:))
title('Signal 2')

Z = fastica(Y);

subplot(3,2,5)
plot(Z(1,:))
title('Source 1')
subplot(3,2,6)
plot(Z(2,:))
title('Source 2')

%Sine waves of different frequency
X = 1:1000;
Y(1,:) = sin(2*pi*X*10/1000);
Y(2,:) = sin(1+2*pi*X*8/1000);

figure
subplot(3,2,1)
plot(Y(1,:))
title('Initial Source 1')
subplot(3,2,2)
plot(Y(2,:))
title('Initial Source 2')
A = [1, 2; 4, -1];
Y = A*Y;
subplot(3,2,3)
plot(Y(1,:))
title('Signal 1')
subplot(3,2,4)
plot(Y(2,:))
title('Signal 2')

Z = fastica(Y);

subplot(3,2,5)
plot(Z(1,:))
title('Source 1')
subplot(3,2,6)
plot(Z(2,:))
title('Source 2')

Note that for the waves of the same frequency, ICA just returns the input signals, but for different frequencies it returns the original sources.

rwolst
  • 351
  • 3
  • 5
2

Rachel,

From my research I have so far been able to find something called 'Chi-Squared Test For Independence', but I am not sure how it works at the moment, but it might be worth a look.

Spacey
  • 9,817
  • 8
  • 43
  • 79
  • I've found these two tutorials explaining how to perform the chi-squared test: http://www.ling.upenn.edu/~clight/chisquared.htm & http://math.hws.edu/javamath/ryan/ChiSquare.html. However, the test can only be performed on categorical data. I don't know whether this can be applied to our signal observations.. – Rachel Feb 28 '12 at 10:37