How to manually obtain the output values of a ANN
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Raul Onrubia
el 26 de Feb. de 2024
I am using ANN to compute the coefficients for a linear regresion. To do so, I use a fitnet neural network (net) with no hidden layers:
I want to reconstruct the output value as function of the input ones. I tried using:
output = net.IW{1}*(x) + net.b{1})*;
but the values I obtain are in a different order of magnitude (~10^4) than the expected ones (~200). If I do
figure, hist(net(x)-y,-20:0.5:20);
I can see that the error is quite low.
I attach a file with the neural network (net), with some input values (x) and the expected output (y).
How can I manually reconstruct the output without doing net(input)?
Thank you very much.
0 comentarios
Respuesta aceptada
Avadhoot
el 13 de Mzo. de 2024
Editada: Avadhoot
el 13 de Mzo. de 2024
I see that you are getting different results when you try to compute the ANN layer manually. I looked at the data and the model you provided. You have calculated the main step correctly but you have missed the input preprocessing and output post processing steps. That is why you are getting different results. You can see the preprocessing functions applied in the model by using the following command:
net.inputs{1}.processFcns
Similarly post-processing functions can be seen using the below command:
net.outputs{1}.processFcns
You will see that in both the cases the "mapminmax" function is used. So to get accurate results you need to use the function in your calculations as well.
Before calculating the output you can process the input using the below code:
inputSettings = net.inputs{1}.processSettings{1};
ymin = inputSettings.ymin; % Minimum of inputs before normalization
ymax = inputSettings.ymax; % Maximum of inputs before normalization
xmin = inputSettings.xmin;
xmax = inputSettings.xmax;
originalInputs = (x - xmin) .* ((ymax-ymin)./(xmax-xmin)) + ymin
After this execute your earlier code as follows:
output = net.IW{1}*(x) + net.b{1}
After this to perform the post processing, you can refer to the below code:
outputSettings = net.outputs{1}.processSettings{1};
ymin = outputSettings.ymin; % Minimum of outputs before normalization
ymax = outputSettings.ymax; % Maximum of outputs before normalization
xmin = outputSettings.xmin; % Typically -1
xmax = outputSettings.xmax; % Typically 1
originalOutputs = (output - ymin) .* ((xmax-xmin)./(ymax-ymin)) + xmin
Now you can compare the manually calculated output to the "y" matrix and find that the values are almost equal.
You can check the construction of the ANN in the Simulink model I have attached. I have constructed it using your ANN.
For more information on "mapminmax" function refer the below documentation:
I hope this helps.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!