%This runs 1000 trials of MLE to classify a noisy bank digit as one of digits 0...9.
%100 noisy versions of each digit 0...9 are to be classified. Reslts are summarized
%as a confusion matrix, showing how often each nosiy digit is correctly classified.
clear;load bank.mat;sigma=1000;C(10,10)=0;%Note more noise than in Section 11-1.
%Each digit XX(:,:,?) is a 30X18 portion of X. (XX is a 3D array).
%XX(:,:,?) represents digit ?. (XX(:,:,10) represents 0). Noisy digit Y is 3.
XX(:,:,1)=X(:,17:34);XX(:,:,2)=X(:,50:67);XX(:,:,3)=X(:,78:95);
XX(:,:,4)=X(:,111:128);XX(:,:,5)=X(:,140:157);XX(:,:,6)=X(:,170:187);
XX(:,:,7)=X(:,202:219);XX(:,:,8)=X(:,232:249);XX(:,:,9)=X(:,262:279);
XX(:,:,10)=X(:,292:309);%Assemble confusion matrix:
for K0=1:100;%100 trials for each digit
for K1=1:10;N=sigma*randn(30,18);Y=XX(:,:,K1)+N;%Add noise to each digit.
%Compute MLE classifier for each noisy digit:
for K2=1:10;Z(K2)=2*sum(sum(XX(:,:,K2).*Y))-sum(sum(XX(:,:,K2).*XX(:,:,K2)));end;
[Q K3]=max(Z);C(K1,K3)=C(K1,K3)+1;end;end;%Use max for index, not value, of maximum.
C%Output confusion matrix C. Diagonal means most noisy digits classified correctly.



