function [W1, W2] = MultiClass(W1, W2, X, D) % The function MultiClass.m implements the learning rule of multiclass %classification using the SGD method and cross entropy cost function (see %Chapter 3 for more information about cross entropy function). %It takes the input arguments of the weights and training data and returns %the trained weights. alpha = 0.9; N = size(X,3); %number of samples for k = 1:N x = reshape(X(:, :, k), 25, 1); %reorganizes the k-th sample into a 25x1 vector d = D(k, :)'; %desired output v1 = W1*x; y1 = Sigmoid(v1); v = W2*y1; y = Softmax(v); e = d - y; delta = e; e1 = W2'*delta; delta1 = y1.*(1-y1).*e1; dW1 = alpha*delta1*x'; W1 = W1 + dW1; dW2 = alpha*delta*y1'; W2 = W2 + dW2; end end