Neural network multiple output with different units
3 views (last 30 days)
Show older comments
Hello,
I'm trying to build a network with 4 inputs and 2 outputs. In the output are different units like µm and percent. At the end of the NN calculation I want to get the mean squared error, but how can I interpret this error when there are different units. For example a mse of 1 µm is very good and also a mse of 5 % would be great, too for another output.
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 07-Dec-2016 07:33:26
%
% This script assumes these variables are defined:
%
% OptiSlangExport_woKW - input data.
% Sa - target data.
close all
x = OptiSlangExport_woKW';
t = Sa';
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
% trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
trainFcn = 'trainbr';
% Create a Fitting Network
hiddenLayerSize = 7;
net = fitnet(hiddenLayerSize,trainFcn);
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.input.processFcns = {'removeconstantrows','mapminmax'};
net.output.processFcns = {'removeconstantrows','mapminmax'};
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 90/100;
% net.divideParam.valRatio = 35/100; % No Validation when using trainbr
net.divideParam.testRatio = 10/100;
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
% net.performFcn = 'crossentropy'; %Mean absolut Error
net.performFcn = 'mse'; % Mean Squared Error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% Recalculate Training, Validation and Test Performance
trainTargets = t .* tr.trainMask{1};
valTargets = t .* tr.valMask{1};
testTargets = t .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
% View the Network
% view(net)
% Plots
% Uncomment these lines to enable various plots.
figure, plotperform(tr)
%figure, plottrainstate(tr)
figure, ploterrhist(e)
% figure, plotregression(t,y)
% plotregression(trTarg,trOut,'Train',vTarg,vOut,'Validation',...
% tsTarg,tsOut,'Testing')
% figure, plotfit(net,x,t)
% Deployment
% Change the (false) values to (true) to enable the following code blocks.
% See the help for each generation function for more information.
if (false)
% Generate MATLAB function for neural network for application
% deployment in MATLAB scripts or with MATLAB Compiler and Builder
% tools, or simply to examine the calculations your trained neural
% network performs.
genFunction(net,'myNeuralNetworkFunction');
y = myNeuralNetworkFunction(x);
end
if (false)
% Generate a matrix-only MATLAB function for neural network code
% generation with MATLAB Coder tools.
genFunction(net,'myNeuralNetworkFunction','MatrixOnly','yes');
y = myNeuralNetworkFunction(x);
end
if (false)
% Generate a Simulink diagram for simulation or deployment with.
% Simulink Coder tools.
gensim(net);
end
1 Comment
John D'Errico
on 12 Dec 2016
Edited: John D'Errico
on 12 Dec 2016
It would have really helped if you learn to properly format your code to be readable. Paste in the code. Then select the entire block of code, and THEN click on the "{} Code" button.
You did try though to use the button, so I fixed it for you.
Accepted Answer
Greg Heath
on 13 Dec 2016
Standardize variables to zero mean and unit variance using ZSCORE.
help zsore
doc zscore
Good designs will have MSE < 1/100
For examples search NEWSGROUP and ANSWERS using
greg zscore
Hope this helps.
Thank you for formally accepting my answer
Greg
0 Comments
More Answers (0)
See Also
Categories
Find more on Modeling and Prediction with NARX and Time-Delay Networks 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!