load alphachars X=alphabet; T=eye(26); nn=linspace(0.05,0.6,15); for j=1:15 X=[X alphabet+nn(j)*randn(size(alphabet))]; T=[T eye(26)]; end net=feedforwardnet(25); net.divideParam.trainRatio=0.75; net.divideParam.valRatio=0.10; net.divideParam.testRatio=0.15; %net.trainFcn='trainrp'; net=train(net,X,T); nn=[0,nn]; Misclass=zeros(16,1); for j=1:16 Out=sim(net,alphabet+nn(j)*randn(size(alphabet))); for k=1:26 [vv,ii]=max(Out(:,k)); if ii~=k Misclass(j)=Misclass(j)+1; end end Misclass(j)=Misclass(j)/26; end figure(2) plot(nn,Misclass); title('Percent error versus Noise'); %% A nice way to visualize what Matlab has produced. % % ... This is just for fun % % The result of the code below is to build a noisy test set, then see how % Matlab classifies it. For each test letter, we show the noisy letter, % the actual letter, and what letter Matlab used. The "pause" command % below halts the code until any button is pressed. figure(3) Test=alphabet+0.4*randn(size(alphabet)); Out=sim(net,Test); mm=colormap(gray); mm=mm(end:-1:1,:); for j=1:26 subplot(1,3,1) colormap(mm) imagesc(reshape(Test(:,j),5,7)'); axis equal; axis off title('Input') subplot(1,3,2) imagesc(reshape(alphabet(:,j),5,7)'); axis equal; axis off title('Actual') [vv,ii]=max(Out(:,j)); subplot(1,3,3) imagesc(reshape(alphabet(:,ii),5,7)'); axis equal; axis off title('Matlab Says'); pause end