I spent the past 3 hours trying to create a feed-forward neural network in matlab with no success. It's really confusing for me now.
I am trying to create the following neural network:
But from my analysis of the network
function, I can't understand how I am going to specify 25 hidden units or neurons in my single hidden layer, and how I can make all of the input layer neurons connected to these hidden unit.
net = network(numInputs,numLayers,biasConnect,inputConnect,layerConnect,outputConnect);
For example if I want to create a neural network with 5 inputs and 5 hidden units in the hidden layer (including the bias units) and make it fully connected. I am using this code:
net = network(5,1,1,[1 1 1 1 1],0,1);
which output this:
From my understanding my code has the following problems:
So please, I have put my cards on the table, how can I do it?
I strongly suppose you are confusing the number of inputs/layers with their size:
W
is a 25 by 122 weight matrix);W
is a 1 by 25 weight matrix).The following code does what you are trying to do:
% 1, 2: ONE input, TWO layers (one hidden layer and one output layer)
% [1; 1]: both 1st and 2nd layer have a bias node
% [1; 0]: the input is a source for the 1st layer
% [0 0; 1 0]: the 1st layer is a source for the 2nd layer
% [0 1]: the 2nd layer is a source for your output
net = network(1, 2, [1; 1], [1; 0], [0 0; 1 0], [0 1]);
net.inputs{1}.size = 122; % input size
net.layers{1}.size = 25; % hidden layer size
net.layers{2}.size = 1; % output layer size
net.view;
Which results in:
Try also help network
, to have a look on how to set input data range, transfer functions and more.