Dear everyone,
I am exploring the Neural Network Toolbox and would like to manually calculate output by hand. I used one of the example provided by Matlab with the following code. Unfortunately, my output is incorrect. Does anyone know why? Thanks
%%below is the sample code from Matlab
[x, y] = crab_dataset;size(x) % 6 x 200
size(y) % 2 x 200
setdemorandstream(491218382);net = patternnet(10);[net, tr_info] = train(net, x, y);testX = x(:, tr_info.testInd);testT = y(:, tr_info.testInd);testY = net(testX);testIndices = vec2ind(testY);[error_rate, conf_mat] = confusion(testT, testY);fprintf('Percentage Correct Classification : %f%%\n', 100*(1 - error_rate));fprintf('Percentage Incorrect Classification : %f%%\n', 100*error_rate);%%Manually calculate the output by hand
% nFeatures = 6
% nSamples = 200
% nHiddenNode = 10
% nClass = 2
% input layer => x (6x200)
% hidden layer => h = sigmoid(w1.x + b1)
% = (10x6)(6x200) + (10x1)
% = (10x200)
%
% output layer => yhat = w2.h + b2
% = (2x200)
w1 = net.IW{1}; % (10x6)
w2 = net.LW{2}; % (2x10)
b1 = net.b{1}; % (10x1)
b2 = net.b{2}; % (2x1)
h = sigmoid(w1*x + b1);yhat = w2*h + b2;[testY' yhat'][vec2ind(testY)' vec2ind(yhat)']
Best Answer