文档详情

感知器算法练习.docx

发布:2016-11-26约字共3页下载文档
文本预览下载声明
感知器算法练习产生两个具有200个二维的数据集,均值分别为(5,1), (-5,1), 方差均为I. 设计使用感知器算法的线性分类器, 使用2个不同的初始化向量,步长参数设为1.解:初始化向量为W1=[1 1 1]’时function Perceptron2%UNTITLED Summary of this function goes here% Detailed explanation goes hereX1=normrnd(5,1,[1 200]);Y1=normrnd(1,1,[1 200]);X2=normrnd(-5,1,[1 200]);Y2=normrnd(1,1,[1 200]);O=ones(1,200);X=[X1 -X2;Y1 -Y2;O -O];W1=[1 1 1];t=0;s=1;while s0 s=0; for i=1:400 if W1*X(:,i)=0; W1=W1+X(:,i); s=s+1; else W1=W1+0; s=s+0; end end t=t+1;end fprintf(μü′ú′?êy?a\n,t)fprintf(?a?òá??a\nW=)disp(W1)end Perceptron2迭代次数为解向量为W= 4.3106 -1.4254 0 X1=normrnd(5,1,[1 200]);Y1=normrnd(1,1,[1 200]);X2=normrnd(-5,1,[1 200]);Y2=normrnd(1,1,[1 200]); x=X1;y=Y1; plot(x,y,*) hold onx=X2;y=Y2; plot(x,y,o) hold on ezplot(4.3106*x-1.4254*y)初始化向量为W1=[0 0 0]’时 Perceptron2迭代次数为解向量为W= 5.9840 2.17541.0000
显示全部
相似文档