Skip to content

Instantly share code, notes, and snippets.

@ghdawn
Created November 8, 2012 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghdawn/4038397 to your computer and use it in GitHub Desktop.
Save ghdawn/4038397 to your computer and use it in GitHub Desktop.
a example of perceptron(Artifial Neural Network)
function [w,flag] = learning(flag,w,omega,target )
%UNTITLED3 Summary of this function goes here
% Detailed explanation goes here
ita=1;
result=(omega*w)>0;
result=target-result;
for i = 1 : 3
if result(i) == 0
continue
end
flag=0;
w=w+2*ita*result(i)*omega(i,:)'
end
end
omega1=[0,1;0,2;1,1];
omega2=[2,0;3,0;3,1];
plot(omega1(:,1),omega1(:,2),'r*');
hold on;
plot(omega2(:,1),omega2(:,2),'gx');
x0=[-1;-1;-1]
omega1=[x0,omega1];
omega2=[x0,omega2];
w=rand(3,1)
flag=0;
while flag==0
flag=1;
[w,flag]=learning(flag,w,omega1,ones(3,1));
[w,flag]=learning(flag,w,omega2,zeros(3,1));
end
x=0:4;
plot(x,w(1)/w(3)-x*w(2)/w(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment