In my project, I generate random samples from N1, N2 ,N3 and i plot them and x is a 2 dimensional guassian distribution N(meani,sigmai). but I want also to plot the bayes decision regions for equal and different initial prob. can anyboby help me plz?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
clear all
close all
%N1
mean1=[0 0];
sigma1=[1 0; 0 1];
%N2
mean2=[1 1];
sigma2=[1 0;0 4];
%N3
mean3=[2 2];
sigma3=[1 -1;-1 4];
x1 = -4:.2:4;
x2 = -4:.2:4;
[X1,X2] = meshgrid(x1,x2);
y1=mvnpdf([X1(:) X2(:)],mean1,sigma1);
y1 = reshape(y1,length(x2),length(x1));
surf(x1,x2,y1);
caxis([min(y1(:))-.5*range(y1(:)),max(y1(:))]);
axis([-4 4 -4 4 0 .2])
xlabel('x1'); ylabel('x2'); zlabel('Probability Density');
figure(1)
hold on
y2=mvnpdf([X1(:) X2(:)],mean2,sigma2);
y2 = reshape(y2,length(x2),length(x1));
surf(x1,x2,y2);
caxis([min(y2(:))-.5*range(y2(:)),max(y2(:))]);
axis([-4 4 -4 4 0 .2])
xlabel('x1'); ylabel('x2'); zlabel('Probability Density');
hold on
y3=mvnpdf([X1(:) X2(:)],mean3,sigma3);
y3 = reshape(y3,length(x2),length(x1));
surf(x1,x2,y3);
caxis([min(y3(:))-.5*range(y3(:)),max(y3(:))]);
axis([-4 4 -4 4 0 .2])
xlabel('x1'); ylabel('x2'); zlabel('Probability Density');
s1=mvnrnd(mean1,sigma1,30);
i=zeros(1,30);
figure(2)
plot(s1,i,'v')
hold on
s2=mvnrnd(mean2,sigma2,30);
i=zeros(1,30);
plot(s2,i,'r*')
hold on
s3=mvnrnd(mean3,sigma3,30);
i=zeros(1,30);
plot(s3,i,'+')
figure(3)
c1=contour(x1,x2,y1);
hold on
c2=contour(x1,x2,y2);
hold on
c3=contour(x1,x2,y3);
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Descriptive Statistics and Visualization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!