%% Letter recognition with threshold perceptron
 clear; clf;
 nIn=12*13; nOut=26; % number of input and output channels
 wOut=rand(nOut,nIn)-0.5; %random initial weight matrix

 % training vectors
 load pattern1;
 rIn=reshape(pattern1', nIn, 26); % matrix of input pattern
 rDes=diag(ones(1,26)); % matrix of desired outputs

 % Updating and training network
 for training_step=1:20;
     % test all pattern
       rOut=(wOut*rIn)>0; % threshold activation function
       dist=sum(sum(abs(rDes-rOut)))/26;
       error(training_step)=dist;
     % training with delta rule
       wOut=wOut+0.1*(rDes-rOut)*rIn';
 end

 plot(0:19,error)
 xlabel('Training step')
 ylabel('Average number of wrong bits') 