0
votes

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:

  • The input layer has 122 features/inputs,
  • 1 hidden layer with 25 hidden units,
  • 1 output layer (binary classification),
  • Input layer and Hidden layer have bias units (Please see the image below for a general idea)

enter image description here

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:

enter image description here

From my understanding my code has the following problems:

  • There is no bias inputs in the input layer
  • it's not a fully connected network (it's like one neuron is connected to only on hidden neuron)

So please, I have put my cards on the table, how can I do it?

1

1 Answers

0
votes

I strongly suppose you are confusing the number of inputs/layers with their size:

  • your network has ONE input, whose size is 122;
  • your network has TWO layers:
    • 1st layer: hidden layer with 25 nodes (W is a 25 by 122 weight matrix);
    • 2nd layer: output layer with 1 node (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:

enter image description here

Try also help network, to have a look on how to set input data range, transfer functions and more.