How can I manually evaluate my data to validate my neural network?

Illustration
arnaud_ensberg - 2021-07-20T10:54:46+00:00
Question: How can I manually evaluate my data to validate my neural network?

I would like to validate the data which my neural network is generating, but when I follow the steps in the doc, I receive a different answer than what is generated by my neural network.  

Expert Answer

Profile picture of Prashant Kumar Prashant Kumar answered . 2025-11-20

To replicate the calculations of a neural network, you must:
 
1) Pre-process the inputs.
 
2) Perform the calculations using the correct weights, biases, transfer functions, and connections.
 
3) Post-process the outputs.
 
The following example replicates the output of a 2 layer feed-forward backpropogation network.
 
inputs = [0 1 2 3 4 5 6 7 8 9 10];

% inputs = inputs + .1 *rand(size(inputs));

targets = [0 1 2 3 4 3 2 1 2 3 4];

% Create a network with 1 neuron in the first layer

net=newff(inputs,targets,1,{'tansig','tansig'},'trainlm');

% Train the network

net = init(net);

net.trainParam.epochs = 100;

[net,tr,out]=train(net,inputs,targets);

%Simulate the network with the inputs

[Y,Pf,Af,E,perf] = sim(net,inputs);

%Calculate output manually:

% Pre-process the data

for iii = 1:numel(net.inputs{1}.processFcns)

      inputs = feval( net.inputs{1}.processFcns{iii}, ...

          'apply', inputs, net.inputs{1}.processSettings{iii} );

end

% Calculate the network response

a1 = tansig(net.IW{1,1}*inputs + net.b{1}); 

Yc = tansig(net.LW{2,1}*a1 + net.b{2}); 

% Post-process the data

for iii = 1:numel(net.outputs{2}.processFcns)

     Yc = feval( net.outputs{2}.processFcns{iii}, ...

          'reverse', Yc, net.outputs{2}.processSettings{iii} );

end

close all

% View results

[Y' Yc']


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!