//// Testing generalization perfroamnce of trained perceptron exec perceptronTrain.sce; function r=randomFlipMatrix(n); // returns matrix with components 1 at n random positions of each column r=zeros(156,26); for i=1:26 x=grand(1,'prm',(1:156)'); r(x(1:n),i)=1; end endfunction letterMatrix=rIn; for nflip = 1:80; distH=[]; for trial=1:10; rIn=abs(letterMatrix-randomFlipMatrix(nflip)); rOut=(wOut*rIn)>0.5; distH=[distH,sum(sum((rDes-rOut).^2))/26]; end meanDistH(nflip)=mean(distH); stdDistH(nflip)=st_deviation(distH); end figure; plot((1:80)',meanDistH); errbar((1:80)',meanDistH,stdDistH,stdDistH) xlabel('Number of flipped bits') ylabel('Average Hamming distance')