final turnin
This commit is contained in:
parent
d79046d7b9
commit
3f2f1ef665
1 changed files with 9 additions and 9 deletions
|
@ -17,8 +17,8 @@ mu1 = [-1 -1];
|
||||||
mu2 = [1 1];
|
mu2 = [1 1];
|
||||||
|
|
||||||
% Equal diagnoal covariance matrix
|
% Equal diagnoal covariance matrix
|
||||||
Sigma1 = [1 0; 0 1];
|
% Sigma1 = [1 0; 0 1];
|
||||||
Sigma2 = [1 0; 0 1];
|
% Sigma2 = [1 0; 0 1];
|
||||||
|
|
||||||
% Diagnoal covariance matrix
|
% Diagnoal covariance matrix
|
||||||
% Sigma1 = [1 0; 0 0.5];
|
% Sigma1 = [1 0; 0 0.5];
|
||||||
|
@ -31,22 +31,22 @@ mu2 = [1 1];
|
||||||
x1 = -10:.1:10; x2 = -10:.1:10;
|
x1 = -10:.1:10; x2 = -10:.1:10;
|
||||||
|
|
||||||
% covariance matrix (increase the range for visualization)
|
% covariance matrix (increase the range for visualization)
|
||||||
% Sigma1 = [1 0.1; 0.1 0.5];
|
Sigma1 = [1 0.1; 0.1 0.5];
|
||||||
% Sigma2 = [0.5 0.3; 0.3 1];
|
Sigma2 = [0.5 0.3; 0.3 1];
|
||||||
% x1 = -40:.1:40; x2 = -40:.1:40;
|
x1 = -40:.1:40; x2 = -40:.1:40;
|
||||||
|
|
||||||
[X1,X2] = meshgrid(x1,x2);
|
[X1,X2] = meshgrid(x1,x2);
|
||||||
%pdf1
|
%pdf1
|
||||||
% F1 = mvnpdf([X1(:) X2(:)],mu1,Sigma1);
|
% F1 = mvnpdf([X1(:) X2(:)],mu1,Sigma1);
|
||||||
F1 = mvndis([X1(:) X2(:)], mu1, Sigma1, prior1);
|
F1 = mvndis([X1(:) X2(:)], mu1, Sigma1, prior1);
|
||||||
F1 = reshape(prior1 * F1,length(x2),length(x1));
|
F1 = reshape(F1,length(x2),length(x1));
|
||||||
subplot(1,2,1);
|
subplot(1,2,1);
|
||||||
surf(x1,x2,F1); hold on;
|
surf(x1,x2,F1); hold on;
|
||||||
|
|
||||||
%pdf2
|
%pdf2
|
||||||
% F2 = mvnpdf([X1(:) X2(:)],mu2,Sigma2);
|
% F2 = mvnpdf([X1(:) X2(:)],mu2,Sigma2);
|
||||||
F2 = mvndis([X1(:) X2(:)], mu2, Sigma2, prior2);
|
F2 = mvndis([X1(:) X2(:)], mu2, Sigma2, prior2);
|
||||||
F2 = reshape(prior2 * F2,length(x2),length(x1));
|
F2 = reshape(F2,length(x2),length(x1));
|
||||||
surf(x1,x2,F2);
|
surf(x1,x2,F2);
|
||||||
caxis([min(F2(:))-.5*range(F2(:)),max(F2(:))]);
|
caxis([min(F2(:))-.5*range(F2(:)),max(F2(:))]);
|
||||||
axis([-4 4 -4 4 0 .4])
|
axis([-4 4 -4 4 0 .4])
|
||||||
|
@ -66,13 +66,13 @@ xlabel('x1'); ylabel('x2');
|
||||||
|
|
||||||
|
|
||||||
function res = mvndis(X, mu, Sigma, prior)
|
function res = mvndis(X, mu, Sigma, prior)
|
||||||
[len, ~] = size(X);
|
[len, d] = size(X);
|
||||||
res = zeros(len, 1);
|
res = zeros(len, 1);
|
||||||
|
|
||||||
for i = 1:len
|
for i = 1:len
|
||||||
x = X(i,:);
|
x = X(i,:);
|
||||||
mdist = (x - mu) * inv(Sigma) * (x - mu).';
|
mdist = (x - mu) * inv(Sigma) * (x - mu).';
|
||||||
res(i) = -log(2*pi) - 1/2*log(det(Sigma)) - 1/2*mdist + log(prior);
|
res(i) = -d/2*log(2*pi) - 1/2*log(det(Sigma)) - 1/2*mdist + log(prior);
|
||||||
end
|
end
|
||||||
% 1 x 2
|
% 1 x 2
|
||||||
% (1 x 2) x ((2 x 2) x (2 x 1))
|
% (1 x 2) x ((2 x 2) x (2 x 1))
|
||||||
|
|
Loading…
Reference in a new issue