% ece532 demo 1
clear all
close all

% generate iid zero mean unit variance Gaussian pairs
n=100;
x(1,:) = randn(1,n);
x(2,:) = randn(1,n);

% make scatterplot
subplot(2,2,1)
for i=1:n
    plot(x(1,i),x(2,i),'.')
    hold on
end
axis([-10,10,-10,10])
axis('square')
pause

% transform 1
y1(1,:) = x(1,:)+3;
y1(2,:) = x(2,:)-3;
subplot(2,2,2)
for i=1:n
    plot(y1(1,i),y1(2,i),'.')
    hold on
end
axis([-10,10,-10,10])
axis('square')
pause

% transform 2
subplot(2,2,3)
y2 = [1/2 0;0 2]*x;
for i=1:n
    plot(y2(1,i),y2(2,i),'.')
    hold on
end
axis([-10,10,-10,10])
axis('square')
pause

% transform 3
y3 = [1 .5;.5 1]*x;
subplot(2,2,4)
for i=1:n
    plot(y3(1,i),y3(2,i),'.')
    hold on
end
axis([-10,10,-10,10])
axis('square')
pause

% mixture example
% more complicated distributions can be generated by 
% "mixtures" of multiple Gaussians
p = rand(1,n)>.5;
z(1,:) = p.*y1(1,:)+(1-p).*y2(1,:);
z(2,:) = p.*y1(2,:)+(1-p).*y2(2,:);
figure(2)
for i=1:n
    plot(z(1,i),z(2,i),'.')
    hold on
end
axis([-10,10,-10,10])
axis('square')
pause



% classification example
x1 = [1 .5;.5 1]*x;
x1(1,:) = x1(1,:)+2;
x1(2,:) = x1(2,:)-2;
x2 = [1 .25; .25 2]*x;
figure(3)
for i=1:n
    plot(x1(1,i),x1(2,i),'.')
    hold on
    plot(x2(1,i),x2(2,i),'.r')
    hold on
end
axis([-10,10,-10,10])
axis('square')


