how to find output of hidden layers in neural networks?

3 views (last 30 days)
I am trying to find out the output of neural network in the following code :-
clear;
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by NFTOOL
%
% This script assumes these variables are defined:
%
% houseInputs - input data.
% houseTargets - target data.
% load bodyfat_dataset
%inputs = bodyfatInputs;
%targets = bodyfatTargets;
%[inputs, targets] = bodyfat_dataset;
inputs = [0,1,0,1;0,0,1,1];
targets = [0 0 0 1;0 1 0 1];
% Create a Fitting Network
hiddenLayerSize = [10];
net = fitnet(hiddenLayerSize);
% Set up Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 100/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% mynet = feedforwardnet % Just a toy example, without any training
weights = net.LW;
biases = net.b;
%netname = net.layers{2}.size;
% Train the Network
[net,tr] = train(net,inputs,targets);
net1 = network;
%net1.numLayers =1;
net1.numInputs = 2;
%net1.numOutputs = 10;
net1.numLayers = 2;
% net1.IW=net.IW;
%net1.layerWeights{1,1} = net.layerWeights{1,1};
view(net1);
% Test the Network
outputs = net(inputs);
errors = gsubtract(outputs,targets);
performance = perform(net,targets,outputs)
% View the Network
view(net)
weights = net.LW
biases = net.b
IW = (net.IW{1,1});
b1 = net.b{1,1};
mult = IW * [-1;-1];
h = tansig( mult + b1 );
b2 = net.b{2,1};
IW1 = weights{2,1};
mult1 = IW1 * h;
h1 = purelin( mult1 + b2 )
h1 here is coming out to be completely different from the actual output :( please help!

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!