This commit is contained in:
Michael Zhang 2023-10-08 00:38:10 -05:00
parent 063966d730
commit 563015a0fb

View file

@ -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])