clc,clear all,close all
%=========================== w1,w2是两类的训练集,每个样本是二维纵向量
w1 = [0.1 6.8 -3.5 2.0 4.1 3.1 -0.8 0.9 5.0 3.9;1.1 7.1 -4.1 2.7 2.8 5.0 -1.3 1.2 6.4 4.0];
w2 = [7.1 -1.4 4.5 6.3 4.2 1.4 2.5 8.4 4.1 2.4;4.2 -4.3 0.0 1.6 1.9 -3.2 -6.1 3.7 -2.2 1.0];
%===============adjust函数是感知器,adjust(A,B,C):A是第一类训练集,B是第二类训练集,C是最大循环次数
W = adjust(w1,w2,5000);
figure
scatter(w1(1,:),w1(2,:),'r');
hold on
scatter(w2(1,:),w2(2,:),'g');
hold on
x = -4:10;
y = (-W(3) - W(1)*x)/W(2);
plot(x,y,'b');%训练集样本分布情况
title('训练集样本分布')
%随机生成一组二维纵向量集合,区间为[min,max];
n = 100; %生成个数,可修改
min = -10; %区间下限,可修改
max = 10; %区间上限,可修改
Un = rand(2,n)*(max - min) + min;
Un = [Un;ones(1,n)];
sort_1 = [];
sort_2 = [];
for i = 1:n
if W'*Un(:,i) > 0
sort_1 = [sort_1 Un(:,i)];
else
sort_2 = [sort_2 Un(:,i)];
end
end
figure
scatter(sort_1(1,:),sort_1(2,:),'r');%第一类
hold on
scatter(sort_2(1,:),sort_2(2,:),'g');%第二类
hold on
x = min:max;
y = (-W(3) - W(1)*x)/W(2);
plot(x,y,'b');
title('检测集合样本分布');
- 1
- 2
- 3
- 4
- 5
前往页