Borrar filtros
Borrar filtros

Predict output values from trained neural network

6 visualizaciones (últimos 30 días)
Camila Gill
Camila Gill el 13 de Abr. de 2020
Editada: Ameer Hamza el 14 de Abr. de 2020
Data set attached.
I have a trained neural network:
% Fit a feedforward neural network to a set of FDM processing data.
% Analysis of errors, computationally and visually.
%
% Input: fdm_trainingdata.m file
% Table with columns for:
% layer thickness [mm], deposition speed [mm/s], elastic modulus [MPa],
% tensile strength [MPa]
% Separate arrays that define the 5 layer thicknesses and 5 deposition
% speeds
%
% Output:
% surface plots of neural network fit of elastic modulus and strength
% errors between predictions of modulus and measured values
% quadratic polynomial regression fits of modulus and strength
clear
% Read file; variables are 'trainingdata,' 'missing,' 'layerthick,'
% 'speed' and 'inputmat'
run('fdm_trainingdata.m');
inputs = trainingdata(:,1:2)';
targets = trainingdata(:,3:4)';
%nvar = length(layerthick);
% Create a Fitting Network
hiddenLayerSize = [15 15];
net = fitnet(hiddenLayerSize);
% Set up Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 1;
net.divideParam.valRatio = 0;
net.divideParam.testRatio = 0;
% Train the Network
[net,tr] = train(net,inputs,targets);
% Test the Network
outputs = net(inputs);
errors = gsubtract(outputs,targets);
performance = perform(net,targets,outputs)
% View the Network
view(net)
I need generate the modulus and strength prediction plots using matrices that are at least 25x26 in size.
How do I generate predictions using the trained network? I need to generate input vectors of (25x25 =) 625 elements so that I can plot the results using surf command.

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 14 de Abr. de 2020
Editada: Ameer Hamza el 14 de Abr. de 2020
Since your NN have two inputs so suppose you have two input matrices of size 25x25. Copy the following code and add it to the end of your current code.
[X,Y] = meshgrid(linspace(0,1,25), linspace(20,60,25)); % input needs to be meshgrid to be used with surf
out = net([X(:)'; Y(:)']);
out1 = reshape(out(1,:), 25, 25);
out2 = reshape(out(2,:), 25, 25);
figure();
surf(X,Y,out1);
figure();
surf(X,Y,out2);
Since there are two outputs, it will generates two surf plots.
out1:
out2:

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by