clear
d = 2; %2 dimension
N = 50; %50 random samples
mu1=[3, 4];
mu2=[9, 14];
mu3=[15, 10];
cov1 =[9,0;0,9];
cov2 =[9,0;0,9];
cov3 =[9,0;0,9];
z = randn(N, d); % N x d,
meanz = mean(z)'; % d x 1
covz = cov(z); % 1 x d
meanz2 = [meanz meanz]; % d x d
mu11 = mu1'; mu22 = mu2'; mu33 = mu3';
mu1 = [mu11 mu11]; % d x d
mu2 = [mu22 mu22]; % d x d
mu3 = [mu33 mu33]; % d x d
[row, col] = size(z');
[row1, col1] = size(meanz2);
while col1 ~= col
meanz2 = [meanz2 meanz];
mu1 = [mu1 mu11];
mu2 = [mu2 mu22];
mu3 = [mu3 mu33];
col1 = col1 + 1;
end
[zvects, zeigs] = eig(covz); % eigenvectors = d x d , eigenvalues = d x d, (lambdas=diagonals)
[x1vects, x1eig] = eig(cov1);
[x2vects, x2eig] = eig(cov2);
[x3vects, x3eig] = eig(cov3);
yp = (zvects * zeigs ^ (-.5))'*z'- meanz2; % A Whitening Transform for zero means correction
x1 = (((x1vects * x1eig^(-.5))')^-1) * yp + mu1; % d x N, the inverse Whitening to center the dist. to means
x2 = (((x2vects * x2eig^(-.5))')^-1) * yp + mu2; % d x N, the inverse Whitening to center the dist. to means
x3 = (((x3vects * x3eig^(-.5))')^-1) * yp + mu3; % d x N, the inverse Whitening to center the dist. to means
x1p = x1'; x2p = x2'; x3p = x3';
figure(1)
hold on
plot(x1(1,:),x1(2,:),'.r')
plot(x2(1,:),x2(2,:),'.g')
plot(x3(1,:),x3(2,:),'.b')
title('Project 1 Gaussian Samples'),
xlabel('X'),ylabel('Y');
range = 25;
axis([-5,range,-5,range]);
syms X1 X2
X=[X1,X2];
range = 25;
axis([-5,range,-5,range]);
y1= 0.5 * (X' - mu11)' * cov1^-1 * (X' - mu11) - log(det(cov1))+log(.2);
y2= 0.5 * (X' - mu22)' * cov2^-1 * (X' - mu22) - log(det(cov2))+log(.3);
y3= 0.5 * (X' - mu33)' * cov3^-1 * (X' - mu33) - log(det(cov3))+log(.5);
ezplot(y1-y2,[0,10, 1,18])
ezplot(y2-y3,[10,20, 5,18])
ezplot(y1-y3,[10,22, -1,10])
title('Project 2 Boundary Plots for Sigma is Diff & Diff Prob - Kiriti'),