% This program uses the weights obtained from the training process with %TestMultiClass.m to classify slightly corrupted images. clear all close all %TestMultiClass; % call TestMultiClass.m to retrieve weights W1 and W2. TestMultiClass_sol; % call TestMultiClass.m to retrieve weights W1 and W2. clc % The input set consists of five 5x5 pixel squares. %0: white pixel; 1: black pixel. X = zeros(5, 5, 5); X(:, :, 1) = [0 1 1 1 1; 0 0 0 0 1; 0 0 0 1 1; 0 0 1 0 1; 0 0 1 0 0]; %corrupted 7. X(:, :, 2) = [0 0 0 1 0; 0 0 1 0 0; 0 1 1 0 0; 1 0 0 1 0; 0 0 0 1 0]; %corrupted 4. X(:, :, 3) = [0 1 1 1 0; 0 0 0 1 0; 0 1 1 1 0; 1 1 0 0 0; 0 1 1 1 0]; %corrupted 2. X(:, :, 4) = [1 1 1 1 0; 1 0 0 0 0; 1 0 0 0 1; 1 0 0 0 1; 0 1 1 1 1]; %corrupted 6. X(:, :, 5) = [0 1 1 1 1; 0 1 0 0 0; 0 1 1 1 0; 0 0 0 1 0; 1 1 1 1 0]; %corrupted 5. % Inference: classes = 7; N = size(X,3); y = zeros(N,classes); %5 because of the one-hot encoding method. for k = 1:N x = reshape(X(:, :, k), 25, 1); v1 = W1*x; y1 = Sigmoid(v1); v = W2*y1; y(k,:) = Softmax(v); end disp('Results:'); disp(' [network_output]:'); disp(y) %% Showing images: for i = 1:N compareImages(X(:,:,i), y(i,:)); end