필터 지우기
필터 지우기

How to manually obtain the output values of a ANN

조회 수: 6 (최근 30일)
Raul Onrubia
Raul Onrubia 2024년 2월 26일
편집: Avadhoot 2024년 3월 13일
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.

채택된 답변

Avadhoot
Avadhoot 2024년 3월 13일
편집: Avadhoot 2024년 3월 13일
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개)

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by