
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Inspect mistakes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

confusion = zeros(num_classes, num_classes);
for i=1:num_classes
    for j=1:num_classes
        confusion(i,j) = sum(test_predictions==i & y_test==j);
    end
end

v = confusion - diag(diag(confusion));
[~,ind] = max(v(:));
[imax, jmax] = ind2sub([num_classes num_classes], ind);

% Find the most frequently mistaken digits
fprintf('The most common error is to mistake %d for %d\n', jmax, imax);

mistakes = find(test_predictions==imax & y_test == jmax);
figure();
display_data(X_test(mistakes,:));

%nine_vs_four  = find(pred_test==9 & y_test == 4);
%display_data(X_test(nine_vs_four,:));
