Effacer les filtres
Effacer les filtres

Neural network with multiple inputs and single output - how to change processing functions?

3 vues (au cours des 30 derniers jours)
Hello everyone! I would like to create a neural network with 5 input nodes. In the following I have created a simple code with the help of the neural network toolbox. I have a question regarding this code.
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 tanh function
Here is my code:
Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 28-Mar-2016 11:42:43
%
% This script assumes these variables are defined:
%
% rinputs - input data.
% rtargetfourthroot - target data.
x = rinputs; t = rtargetfourthroot;
% 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.
% Create a Fitting Network hiddenLayerSize = 50; 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 = 60/100; net.divideParam.valRatio = 20/100; net.divideParam.testRatio = 20/100;
% 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,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) %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
Thank you
  1 commentaire
Greg Heath
Greg Heath le 28 Mar 2016
Modifié(e) : Greg Heath le 28 Mar 2016
PLEASE !!!
1. Remove assignment statements that just assign default values.
2. Justify all nondefault values that are used
3. Use {} to format
THANKS
Greg

Connectez-vous pour commenter.

Réponse acceptée

Greg Heath
Greg Heath le 28 Mar 2016
% NO SEMICOLONS !!!
clc
net = fitnet
transferFcn1 = net.layers{1}.transferFcn
transferFcn2 = net.layers{2}.transferFcn
Hope this helps.
Thank you for formally accepting my answer
Greg
  2 commentaires
pepper yuan
pepper yuan le 29 Mar 2016
Modifié(e) : pepper yuan le 29 Mar 2016
May i know how to justify the tanh as my transfer function?
>> [x,t] = house_dataset;
>> net = feedforwardnet;
>> view(net)
>> net.layers{1}.transferFcn = 'tanh'
Error using feval Undefined function 'tanh' for input arguments of type 'char'.
Error in network/subsasgn>getDefaultParam (line 2048) param = struct(feval(fcn,'defaultParam'));
Error in network/subsasgn>setLayerTransferFcn (line 1224) net.layers{i}.transferParam = getDefaultParam(transferFcn);
Error in network/subsasgn>network_subsasgn (line 208) if isempty(err), [net,err] = setLayerTransferFcn(net,i,transferFcn); end
These are the example code that I'm trying to use tanh as my transfer function. How can i make the tanh function as the transfer function in hidden layer? Thank you

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by