Issue in calculating targets from neural network model
1 view (last 30 days)
Show older comments
Srinivas Alagesan
on 31 Oct 2023
Commented: Srinivas Alagesan
on 8 Nov 2023
Hi,
I have trained a neural network model and saved it for predicting new inputs for future. To verify the targets predicted by model manually, i have taken the network weights and biases and estimated the targets accordingly. But the values obtained from this approach and directly from the model is varying. Could anyone help me with this please. I have attached the manual calculation procedure here.
inputvector = X_train(1,:)'
z_hidden = bestNetwork.IW{1}*inputvector+bestNetwork.b{1}
a_hidden = 1./(1+exp(-z_hidden)) % I have used logistic sigmoid function for input and hidden layer
z_output = bestNetwork.LW{2,1}*a_hidden+bestNetwork.b{2}
a_output = (2/(1+exp(-2*z_output)))-1 % I have used hyperbolic tangent function for hidden and output layer
d = bestNetwork(inputvector)
The value of 'a_output' and 'd' has different value. Please help me in resolving this issue.
0 Comments
Accepted Answer
Shivansh
on 8 Nov 2023
Hi Srinivas,
I understand from the description that you are manually calculating the forward pass of your neural network and comparing the output with the output of the trained model.
If the difference in the outputs is not very significant, the discrepancy of the output can be attributed to the numerical precision issues. MATLAB uses double-precision floating-point numbers, which can lead to small differences in calculations due to rounding errors.
There can also be other reasons for the discrepancy in outputs. Here are some things to check:
Activation Functions: You can verify that you are using the correct activation functions for each layer using “bestNetwork.layers{1}.transferFcn” and “bestNetwork.layers{2}.transferFcn“ functions.
Network Architecture: You can verify that your manual calculation matches the architecture of your trained network. You can check the number of layers, the number of neurons in each layer, the connections between the layers, etc.
You can refer to the following link for more information about the properties and functions for the network https://www.mathworks.com/help/deeplearning/ug/neural-network-subobject-properties.html#bss4hk6-99.
I hope this helps!
More Answers (0)
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!