Hello everyone! I would like to create a neural network with 6 input nodes. In the following I have created a simple code with the help of the neural network toolbox. I have a few questions regarding this code.
1. As I understood after reading several forum entries I have to create a matrix out of the 6 input vectors first, right?
2. How can I change the processing function in the hidden layer nodes? In the default settings the sigmoid function is used… I would like to change it to the tangid function…
3. How can I plot the results of the neural network. I would like to plot the original target data as well as the test data that are forecasted by the neural network in one diagram to show how well they compare… since I have multiple inputs this function of the neural network toolbox doesn't work…
% This is my code:
a=[1 2 3 4 5 6 7 8 9 10]'; b=[3 4 5 6 7 8 9 10 11 1]'; c=[1 4 2 5 3 6 4 8 9 10]'; d=[2 4 5 6 7 9 8 10 1 11]'; e=[1 6 3 5 4 7 8 9 10 11]'; f=[10 9 8 7 1 2 3 4 5 6 ]';
o=[50 51 52 54 58 60 65 66 69 70]';
% Create input matrix and output vector inputs=[a b c d e f]'; targets=o';
% Create a Fitting Network hiddenLayerSize = 4; net = fitnet(hiddenLayerSize);
% Choose Input and Output Pre/Post-Processing Functions % For a list of all processing functions type: help nnprocess net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'}; net.outputs{2}.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 = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100;
% For help on training function 'trainlm' type: help trainlm % For a list of all training functions type: help nntrain net.trainFcn = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function % For a list of all performance functions type: help nnperformance 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,inputs,targets);
% Test the Network outputs = net(inputs); errors = gsubtract(targets,outputs); performance = perform(net,targets,outputs)
% Recalculate Training, Validation and Test Performance trainTargets = targets .* tr.trainMask{1}; valTargets = targets .* tr.valMask{1}; testTargets = targets .* tr.testMask{1}; trainPerformance = perform(net,trainTargets,outputs) valPerformance = perform(net,valTargets,outputs) testPerformance = perform(net,testTargets,outputs)
% View the Network view(net)
figure, plotfit(net,inputs,targets)
Thank you so much!!
Best Answer