rosenblatt perceptron linear version ( done )
Show older comments
% I had problem with rosenblatt perceptron but i solved it :)
clc
clear all;
close all;
I = 1000; % number of class
n = 2 ;
eta = 0.5 ;
W = zeros(1,n+1) ;
k = 0 ;
X=rand(I,1);
X(:,2)=rand(I,1);
X(1:I/2,2)=X(1:I/2,2).*0.4;
X(I/2+1:I,2)=X(I/2+1:I,2).*0.4+0.6;
X=[ones(I,1),X];
Y=[ones(I/2,1)*(-1);ones(I/2,1)];
A=[1 2 3];
k=0;
while isempty(A)~=1
A=[];
for i=1:1:I
s=X(i,:)*W';
y=-1;
if s==0 || s>0
y=1;
end
if y~=Y(i)
A=[A;i];
end
end
k=k+1;
if isempty(A)
break
end
idx=randi(length(A));
W=W+eta*Y(A(idx))*X(A(idx),:);
clf
plot(X(1:I/2,2),X(1:I/2,3),'x')
hold on
plot(X(I/2+1:I,2),X(I/2+1:I,3),'o')
X1 = 0:0.05:1;
X2 = -(W(1)+W(2)*X1)/W(3) ;
hold on
plot(X1,X2,'r');
pause(0.2);
end
display(k);
Answers (0)
Categories
Find more on Pattern Recognition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!