MATLAB Answers

Artificial Neural Networks Hidden Layers

61 views (last 30 days)
Tiago Dias
Tiago Dias on 25 Jul 2019
Edited: Tiago Dias on 25 Jul 2019
Below is my code to build a neural netword.
Question 1
n defines the number of nodes in the hidden layer. How can i define more nodes to the output hidden layer? or the fact it is 1 because i have only 1 output variable?
Question 2
Is it possible to set, for example, 2 hidden layers, of 15 neuros and 5 neuros respectively?
%% ANN --------------------------------------------------------------------
% Define X
X = predictors;
% Define Y
% Define a neural network (variable called 'net' which is a 3 layer
% perceptron with n nodes in the hidden layer
n = 25;
net = feedforwardnet(n);
% Train network
[net, TR] = train(net, X', Y');
% Prediction
Y_model = zeros(length(Y),1);
for i = 1:length(Y)
% Simulate Neural Network
Y_model(i) = net([X(i,:)]');
% Input of net, must be a column vector
Thanks for your time


Sign in to comment.

Accepted Answer

Greg Heath
Greg Heath on 25 Jul 2019
Number of input and output nodes is determined by the data.
Number of hidden layers and nodes is determined by the program author.
Hope this helps
Thank you for formally accepting my answer,

  1 Comment

Tiago Dias
Tiago Dias on 25 Jul 2019
Thanks for your comment, still got some doubts.
I set 25 nodes for the hidden layer, for the box with the "layer" title.
The value 1 for the box that is surroing "b" , "W" labeled as output, i didn't set for value 1, can change this value (red arrow)?
Or that value is 1 cause the Output green square has 1 as well?

Sign in to comment.

More Answers (0)