% test robustnes against noise
clear d2 d
count=0;
 for iNoise = 0:1:50;      % loop over noise level
     count=count+1;
     noise(count)=iNoise;
     for iTrial=1:10;           % loop over trails
        d(iTrial)=0;
        d2(iTrial)=0;
        rIN=zeros(size(r_i));
        for iLetter=1:26                 % loop over letter set
            rIn(:,iLetter)=r_i(:,iLetter);
            noiseVec=ranBinVec(156,iNoise*156/100);
            rIn(noiseVec==1,iLetter)=rIn(noiseVec==1,iLetter)==0;
        end
        % test all pattern
        r_o_test=1./(1+exp(-w_o*(1./(1+exp(-w_h*rIn)))));
        d(iTrial)=sum(sum((r_o_test-r_d).^2));
        r_o_test2=floor(r_o_test+0.5);
        d2(iTrial)=sum(sum((r_o_test2-r_d).^2));
     end
     meanD(count)=mean(d2);
     stdD(count)=std(d2);
 end

 %figure;
 errorbar(noise,meanD,stdD)
 title('MLP')
 %axis([0 90 0 26]);
 xlabel('noise [%]')
 ylabel('average Hamming distance')