How to feed with 2 or more inputs a Neural Network in Matlab

10,493

You have to distinguish between the following parameters:

  1. The dimension of the input vector to the neural network. In your example, the first layer has one input vector of dimension 4. This parameter is called R in Matlab's documentation.
  2. The number of different inputs to the network, which is how many sets of vectors are input to the network. From the Neural Network Toolbox doc's:

    net.numInputs This property defines the number of inputs a network receives. It can be set to 0 or a positive integer. Clarification: The number of network inputs and the size of a network input are not the same thing. The number of inputs defines how many sets of vectors the network receives as input. The size of each input (i.e., the number of elements in each input vector) is determined by the input size (net.inputs{i}.size). Most networks have only one input, whose size is determined by the problem.

  3. The number of samples of the input which is given to the network. In your example, you have 3 samples of 4-dimensional vectors.

With this in mind, if you meant to feed the network with 3 samples, then your code is ok. If, on the other hand, you really need 3 different sets of inputs, you can manually change the numInputs parameter in your network, or you can create a custom network:

net = network(numInputs,numLayers,biasConnect,inputConnect, layerConnect,outputConnect);

with the number of inputs numInputs as you need, but them you need to customize it yourself. You can read more about it here: http://www.mathworks.com/help/toolbox/nnet/network.html#667825

Share:
10,493
Giuseppe
Author by

Giuseppe

Updated on June 04, 2022

Comments

  • Giuseppe
    Giuseppe almost 2 years

    I want to feed a Neural Network with more than one input (using the Matlab tool Box).

    If I declare the input vector like P = [1 2 3 4; 1 2 3 4; 1 2 3 4;1 2 3 4], the target as T = [1 2 3 4] and then the network as net = newff(P,T,1);, when I look at the network parameters it says numInputs: 1, while in my mind the number of inputs should be 3 (one for each row).

    My question is: how to feed the network with 3 separated inputs?

    Thanks in advance, Regards G.B.