solve q1
This commit is contained in:
parent
063966d730
commit
563015a0fb
1 changed files with 6 additions and 2 deletions
|
@ -2,6 +2,10 @@
|
||||||
% Rui Kuang
|
% Rui Kuang
|
||||||
% Demonstration of Classification by 2-D Gaussians
|
% Demonstration of Classification by 2-D Gaussians
|
||||||
|
|
||||||
|
clf;
|
||||||
|
prior1 = 0.3;
|
||||||
|
prior2 = 0.7;
|
||||||
|
|
||||||
mu1 = [-1 -1];
|
mu1 = [-1 -1];
|
||||||
mu2 = [1 1];
|
mu2 = [1 1];
|
||||||
|
|
||||||
|
@ -27,13 +31,13 @@ mu2 = [1 1];
|
||||||
[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 = reshape(F1,length(x2),length(x1));
|
F1 = reshape(prior1 * 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 = reshape(F2,length(x2),length(x1));
|
F2 = reshape(prior2 * 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])
|
||||||
|
|
Loading…
Reference in a new issue