Commit efa90b68 authored by Saad Jbabdi's avatar Saad Jbabdi
Browse files

Updates to the prac

parent e3e53e07
......@@ -113,9 +113,9 @@ for i = 1:10
w = randn(d,1); w = w/norm(w)*5;
subplot(1,2,1)
plot(x_w(1,:),x_w(2,:),'o'); hold on
axis equal
grid on
axis equal; grid on
quiver(0,0,w(1),w(2),'linewidth',2,'color','r'); hold off
title(sprintf('%d/10 random projection',i))
subplot(1,2,2)
histogram(w'*x_w)
pause
......@@ -151,11 +151,9 @@ grid on
G0 = @(x)(x.^2); % quadratic (do not use this!)
G1 = @(x)(1-exp(-x.^2)); % Gaussian --> integral(x*exp(-x^2/2)
G2 = @(x)(log(cosh(x))); % --> integral(tanh)
G3 = @(x)(x.^3); % kurtosis
G3 = @(x)(x.^3); % skewness
G4 = @(x)(x.^4); % tailedness
G5 = @(x)(sqrt(G1(x)));
% put your own non-linearity in here!
G = G3;
% Let's plot these functions
Gall = {G0, G1, G2, G3, G4};
......@@ -178,7 +176,10 @@ end
angles = linspace(0,2*pi,1000); % angles to calculate cost function along
I = zeros(size(angles)); % Interestingness
E = zeros(size(angles)); % Extent (variance)
G = G4; % select contrast function
% put your own non-linearity in here!
G = G4;
for i = 1:length(angles)
% get vector w along angle
[w_x, w_y] = pol2cart(angles(i),1);
......@@ -227,19 +228,40 @@ addpath ./utils/FastICA_25
% check the help to see how to change things like the contrast function g
% note that we are using x (fastica does pre-whitening internally)
[S, A, W] = fastica(x,'approach', 'symm','g','skew');
% S = source signals, A = mixing matrix, W = unmixing matrix
[S, A, W] = fastica(x_c,'approach', 'symm','g','skew');
% I am not sure why I need to do the below
W = A';
mixedS = A*S; % mixture of source signals
% plot the results
figure
subplot(1,3,1)
plot(S(1,:),S(2,:),'o'); hold on
quiver(0,0,A(1,1),A(2,1),'linewidth',3,'color','k')
quiver(0,0,-A(1,1),-A(2,1),'linewidth',3,'color','k')
quiver(0,0,A(1,2),A(2,2),'linewidth',3,'color','c')
quiver(0,0,-A(1,2),-A(2,2),'linewidth',3,'color','c')
xlim([-5,5]); ylim([-6,6])
title('Estimated Source')
subplot(1,3,2)
plot(mixedS(1,:),mixedS(2,:),'o'); hold on
quiver(0,0,A(1,1),A(2,1),'linewidth',3,'color','k')
quiver(0,0,-A(1,1),-A(2,1),'linewidth',3,'color','k')
quiver(0,0,A(1,2),A(2,2),'linewidth',3,'color','c')
quiver(0,0,-A(1,2),-A(2,2),'linewidth',3,'color','c')
xlim([-4,4]); ylim([-5,5])
title('Mixed Source')
subplot(1,3,3)
plot(x_c(1,:),x_c(2,:),'o'); hold on
quiver(0,0,W(1,1),W(1,2),'linewidth',3,'color','k')
quiver(0,0,-W(1,1),-W(1,2),'linewidth',3,'color','k')
quiver(0,0,W(2,1),W(2,2),'linewidth',3,'color','c')
quiver(0,0,-W(2,1),-W(2,2),'linewidth',3,'color','c')
axis equal
quiver(0,0,A(1,1),A(2,1),'linewidth',3,'color','k')
quiver(0,0,-A(1,1),-A(2,1),'linewidth',3,'color','k')
quiver(0,0,A(1,2),A(2,2),'linewidth',3,'color','c')
quiver(0,0,-A(1,2),-A(2,2),'linewidth',3,'color','c')
xlim([-4,4]); ylim([-5,5])
title('Original centered data')
%% Quick implementation of the FastICA algorithm
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment