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

A
arnaud_ensberg · Jul 20, 2021 · 2.2K views
Question
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 PhD Expert
Answered Aug 12, 2026
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']
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!