Issue in calculating targets from neural network model

1 次查看(过去 30 天)
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.

采纳的回答

Shivansh
Shivansh 2023-11-8
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!
  1 个评论
Srinivas Alagesan
Srinivas Alagesan 2023-11-8
Hi Shivansh,
Thanks for your response. I have figured it out the reason behind the difference. It's due to normalization settings which I overlooked in the manual calculation.
Anyways, Once thank you so much for your response.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by