资源简介
贝叶斯判别,模式识别作业。比较简单。可以参考一下,提供借鉴。
代码片段和文件信息
clear; clc;
N = 30
C1 =[3.50;03.5];
C2 = [3.50;03.5];
M1 = [-22];
M2 = [2-2];
w1=mvnrnd(M1C130); %产生随即数
w2 =mvnrnd(M2C230);
f1 = 0;
f2 = 0;
M1 = [00];
M2 = [00];
C1 = [00;00];
C2 = [00;00];
mm = max(abs(w1)); %控制样本特征值在[-55]之间
mm = max(mm);
w1 = w1/mm*5
mm = max(abs(w2));
mm = max(mm);
w2 = w2/mm*5
for i = 1:N
M1 = M1 + w1(i:);
M2 = M2 + w2(i:);
end
M1 = M1/N
M2 = M2/N
for i=1:N
C1 = C1 + transpose(w1(i:))*w1(i:)-transpose(M1)*M1;
C2 = C2 + transpose(w2(i:))*w2(i:)-transpose(M2)*M2;
end
C1 = C1/N
C2 = C2/N
figure(1); %以样本的第一个特征值进行分类
axis([-55-55]);
hold on
grid on
f1=0;
f2=0;
for i=1:N
t=(w1(i1)-M1(1))*(1/C1(11))*(w1(i1)-M1(1));
d1 = log(0.5)-0.5*log(C1(11))-0.5*t;
t=(w1(i1)-M2(1))*(1/C2(11))*(w1(i1)-M2(1));
d2 = log(0.5)-0.5*log(C2(11))-0.5*t;
if d1 plot(w1(i1)w1(i2)‘rx‘)
f1 = f1+1;
else
plot(w1(i1)w1(i2)‘ro‘)
end
t=(w2(i1)-M1(1))*(1/C1(11))*(w2(i1)-M1(1));
d1 = log(0.5)-0.5*log(C1(11))-0.5*t;
t=(w2(i1)-M2(1))*(1/C2(11))*(w2(i1)-M2(1));
d2 = log(0.5)-0.5*log(C2(11))-0.5*t;
if d2 plot(w2(i1)w2(i2)‘x‘)
f2 = f2+1;
else
plot(w2(i1)w2(i2)‘o‘)
end
end
p1 = f1/N*100
p2 = f2/N*100
figure(2); %以样本的第二个特征值进行分类
axis([-55-55]);
hold on
grid on
f1=0;
f2=0;
for i=1:N
t=(w1(i2)-M1(2))*(1/C1(22))*(w1(i2)-M1(2));
d1
- 上一篇:预测控制matlab工具箱
- 下一篇:阴影检测HSV
评论
共有 条评论