function [w,y]=perlearn(inp,tar,wini,alfa) % % This function implements the perception learning rule % % Input arguments: % % inp - input matrix (m patterns, n inputs) % tar - target vector % wini - initial value of the weight vector (bias is the (n+1)th weight % alfa - learning rate % % Output arguments: % % w - weight vector history % y - output vector % [m,n]=size(inp); w=wini; for i=1:m y(i)=w(i,:)*[inp(i,:) 1]'; if y(i)>=0 y(i)=1; else y(i)=0; end w(i+1,:)=w(i,:)+alfa*(tar(i)-y(i))*[inp(i,:) 1]; end