%% Letter recognition with threshold perceptron 
 clear; clf;
 nIn=12*13; nOut=26;
 wOut=rand(nOut,nIn)-0.5; 
 
% training vectors 
 load pattern1;
 rIn=reshape(pattern1', nIn, 26); 
 rDes=diag(ones(1,26));

% Updating and training network 
 for training_step=1:20;
     % test all pattern
      rOut=(wOut*rIn)>0.5;
      distH=sum(sum((rDes-rOut).^2))/26;
      error(training_step)=distH;
     % training with delta rule
      wOut=wOut+0.1*(rDes-rOut)*rIn';  
 end

 plot(0:19,error)
 xlabel('Training step')
 ylabel('Average Hamming distance')
 
 