matlab练习程序(线性分类器<感知器>)。。。待改进

clear all;
close all;
clc;
step=0.1;       %迭代步长
num=15;         %数据个数
k=100;          %迭代次数

set=[  0.4   0.05   1;
     - 0.2   0.75   1;    
       0.5   0.1    1;
     - 0.1   0.7    1;
       0.3   0.2    1;
     - 0.15  0.9    1;
       0     0.8    1;
       0.4   0.3    1;
      -0.2   0.87   1;
       0.4   0.1    1;
      -0.2   0.9    1;
      -0.2   0.4    1;
      -0.1   0.4    1;
       0.3   0.9    1;
      -0.5   0      1];

for i=1:num
    plot(set(i,1),set(i,2),'ro');
    hold on;
end

axis([-0.5 0.5 0 1]);
%axis([-0.5 1.5 -0.5 1.5]);
w(1,:)=[-3 0 1];        %初始权值
x=-0.5:0.1:0.5;
%x=-0.5:0.1:1.5;

flag=0;
for i=2:k
    tmp=[0 0 0];
    for j=1:num
        flag=w(i-1,:)*set(j,:)';
        tmp=tmp+flag*set(j,:);
    end
    
    w(i,:)=w(i-1,:)-step*tmp;
end

for i=1:k
    y=(-w(i,3)-w(i,1)*x)/w(i,2);
    plot(x,y);
    hold on;
end

 y=(-w(k,3)-w(k,1)*x)/w(k,2);
 plot(x,y,'r')

参考:

1.http://jpkc.nudt.edu.cn/mssb/donghua/zaixianshiyan/gzqsf.htm

2.http://read.pudn.com/downloads102/ebook/420359/chapter%203/3.doc

posted @ 2012-05-04 15:48  Dsp Tian  阅读(2568)  评论(0编辑  收藏  举报